blob: db66b22a68e95cf6296e8186ed0d7639d9114d30 [file] [log] [blame]
/* Copyright Statement:
*
* This software/firmware and related documentation ("MediaTek Software") are
* protected under relevant copyright laws. The information contained herein is
* confidential and proprietary to MediaTek Inc. and/or its licensors. Without
* the prior written permission of MediaTek inc. and/or its licensors, any
* reproduction, modification, use or disclosure of MediaTek Software, and
* information contained herein, in whole or in part, shall be strictly
* prohibited.
*
* MediaTek Inc. (C) 2018. All rights reserved.
*
* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
* ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
* RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
* INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
* TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
* RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
* OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
* SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
* RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
* ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
* RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
* MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
* CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* The following software/firmware and/or related documentation ("MediaTek
* Software") have been modified by MediaTek Inc. All revisions are subject to
* any receiver's applicable license agreements with MediaTek Inc.
*/
#ifndef MIDDLEWARE_BOOTLOADER_INCLUDE_BDEV_H
#define MIDDLEWARE_BOOTLOADER_INCLUDE_BDEV_H
#include <mt_list.h>
#include <platform_config.h>
#include <stdint.h>
#include <unistd.h>
extern uint32_t bdev_work_buf;
extern uint32_t bdev_work_buf_size;
#define BDEV_FLAGS_NONE (0U << 0U)
#define BDEV_FLAG_CACHE_ALIGNED_READS (1U << 0U)
#define BDEV_FLAG_CACHE_ALIGNED_WRITES (1U << 1U)
#define BDEV_FLAG_ADDR_CHECK (1U << 2U)
#define BDEV_FLAG_BUF_ALIGNED_READS (1U << 3U)
/* normal boot device */
struct bdev {
struct list_node node;
uint8_t name[MAX_DEVICE_NAME_LEN];
off_t total_size;
uint32_t block_size; /* which means page size */
uint32_t block_shift;
uint32_t block_count;
uint8_t label[MAX_PART_NAME_LEN];
uint8_t erase_byte;
uint32_t erase_size; /* flash erase basic unit */
uint32_t flags;
uint32_t gpt_flag; /* this flag if for writing nand gpt */
uint32_t buf_align;
void *private_data;
/* function pointers */
ssize_t (*read)(struct bdev *dev, uint8_t *buf,
off_t offset, size_t len);
ssize_t (*read_block)(struct bdev *dev, uint8_t *buf,
uint32_t blknr, uint32_t count);
ssize_t (*write)(struct bdev *dev, uint8_t *buf,
off_t offset, size_t len);
ssize_t (*write_block)(struct bdev *dev, uint8_t *buf,
uint32_t blknr, uint32_t count);
ssize_t (*erase)(struct bdev *dev, off_t offset, size_t len);
void (*close)(struct bdev *dev);
};
void bdev_init(uint32_t work_buf, uint32_t work_buf_size);
int32_t bdev_register_device(struct bdev *dev);
int32_t bdev_unregister_device(struct bdev *dev);
/* I/O operation */
struct bdev *bdev_open(const uint8_t *name);
struct bdev *bdev_open_by_label(const uint8_t *label);
ssize_t bdev_read(struct bdev *dev, uint8_t *buf,
off_t offset, size_t len);
ssize_t bdev_read_block(struct bdev *dev, uint8_t *buf,
uint32_t block, uint32_t count);
ssize_t bdev_write(struct bdev *dev, uint8_t *buf,
off_t offset, size_t len);
ssize_t bdev_write_block(struct bdev *dev, uint8_t *buf,
uint32_t block, uint32_t count);
ssize_t bdev_erase(struct bdev *dev, off_t offset, size_t len);
int32_t bdev_close(struct bdev *dev);
#endif /* MIDDLEWARE_BOOTLOADER_INCLUDE_BDEV_H */