diff --git a/model/storage/include/common/storage.h b/model/storage/include/common/storage.h deleted file mode 100644 index d85a4a25955227ad1df346fd14d287ca95a979fd..0000000000000000000000000000000000000000 --- a/model/storage/include/common/storage.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef STORAGE_H -#define STORAGE_H - -#include "hdf_base.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -#define STORAGE_MAX_BYTES ((size_t)(-1)) - -enum StorageType { - MEDIA_MMC = 0, - MEDIA_MTD = 1, - MEDIA_ERR = 2, -}; - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* STORAGE_H */ diff --git a/model/storage/include/common/storage_block.h b/model/storage/include/common/storage_block.h deleted file mode 100644 index 726c84d13ad98b64b93fc635b8d3c187b3f57f5e..0000000000000000000000000000000000000000 --- a/model/storage/include/common/storage_block.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef STORAGE_BLOCK_H -#define STORAGE_BLOCK_H - -#include "storage.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -#define STORAGE_SEC_SIZE 512 -#define STORAGE_SEC_SHIFT 9 -#define STORAGE_MAX_SEC_NR (STORAGE_MAX_BYTES >> STORAGE_SEC_SHIFT) - -#define STORAGE_SEC_PARAM_INVALID(s, n) \ - (s >= STORAGE_MAX_SEC_NR || \ - n >= STORAGE_MAX_SEC_NR || \ - (STORAGE_MAX_SEC_NR - n) <= s) - -#define BLOCK_NAME_LEN 32 - -struct StorageBlock { - char name[BLOCK_NAME_LEN]; /* name of the block device */ - int32_t index; - enum StorageType type; /* indicate which type of media is used */ - bool removeable; - void *media; /* media device of the block */ - size_t capacity; /* sized by sector */ - size_t secSize; /* sized by bytes */ - uint32_t errCnt; /* err count on io transfer */ - struct StorageBlockMethod *ops; /* storage oparations provided by specific media */ - void *bops; /* block operations of specific os */ -}; - -struct StorageBlockMethod { - ssize_t (*read)(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr); - ssize_t (*write)(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr); - ssize_t (*erase)(struct StorageBlock *sb, size_t secStart, size_t secNr); - size_t (*getCapacity)(struct StorageBlock *sb); - bool (*isPresent)(struct StorageBlock *sb); - uint32_t (*getAuSize)(struct StorageBlock *sb); -}; - -ssize_t StorageBlockRead(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr); -ssize_t StorageBlockWrite(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr); -ssize_t StorageBlockErase(struct StorageBlock *sb, size_t secStart, size_t secNr); -size_t StorageBlockGetCapacity(struct StorageBlock *sb); -bool StorageBlockIsPresent(struct StorageBlock *sb); -int32_t StorageBlockGetAuSize(struct StorageBlock *sb, uint32_t *auSize); - -int32_t StorageBlockAdd(struct StorageBlock *sb); -void StorageBlockDel(struct StorageBlock *sb); - -/* these two functions gona implemented by specific os */ -int32_t StorageBlockOsInit(struct StorageBlock *sb); -void StorageBlockOsUninit(struct StorageBlock *sb); - -ssize_t StorageBlockMmcErase(uint32_t blockId, size_t secStart, size_t secNr); -struct StorageBlock *StorageBlockFromNumber(uint32_t number); - - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* STORAGE_BLOCK_H */ diff --git a/model/storage/include/mmc/mmc_block.h b/model/storage/include/mmc/mmc_block.h new file mode 100644 index 0000000000000000000000000000000000000000..a1c91c16f79887b510900df38ee81624a9d599ee --- /dev/null +++ b/model/storage/include/mmc/mmc_block.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef MMC_BLOCK_H +#define MMC_BLOCK_H + +#include "mmc_corex.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +/** + * @Defines the default mmc sector size + * + */ +#define MMC_SEC_SIZE 512 + +/** + * @Defines the default mmc sector size shift + * + */ +#define MMC_SEC_SHIFT 9 + +/** + * @Defines the help macro for getting sector number + * + */ +#define MMC_MAX_SEC_NR (MMC_MAX_BYTES >> MMC_SEC_SHIFT) + +#define MMC_SEC_PARAM_INVALID(s, n) \ + (s >= MMC_MAX_SEC_NR || \ + n >= MMC_MAX_SEC_NR || \ + (MMC_MAX_SEC_NR - n) <= s) + +/** + * @Defines the max length of mmc block device name + * + */ +#define MMC_BLOCK_NAME_LEN 32 + +/** + * @Defines the structure used to identify a general block device. + * + */ +struct MmcBlock { + char name[MMC_BLOCK_NAME_LEN]; /* name of the block device */ + int32_t index; + bool removeable; + size_t capacity; /* sized by sector */ + size_t secSize; /* sized by bytes */ + uint32_t errCnt; /* err count on io transfer */ + void *bops; /* block operations of specific os */ + void *osData; /* os specific data */ + struct MmcDevice *mmc; +}; + +/** + * @brief Block device init for the mmc device. + * + * This function behaves differently in different OS + * + * @param mmcDevice Indicates the pointer to the mmc device. + * + * @return Returns 0 if init successfully; returns a negative value otherwise. + */ +int32_t MmcBlockInit(struct MmcDevice *mmcDevice); + +/** + * @brief Block device uninit for the mmc device. + * + * This function behaves differently in different OS + * + * @param mmcDevice Indicates the pointer to the mmc device. + * + */ +void MmcBlockUninit(struct MmcDevice *mmcDevice); + +/** + * @brief Block device init for the mmc device in specific os. + * + * These function gona be implemented by specific os + * + * @param mmcDevice Indicates the pointer to the mmc device. + * + * @return Returns 0 if init successfully; returns a negative value otherwise. + */ +int32_t MmcBlockOsInit(struct MmcDevice *mmcDevice); + +/** + * @brief Block device uninit for the mmc device in specific os. + * + * These function gona be implemented by specific os + * + * @param mmcDevice Indicates the pointer to the mmc device. + * + */ +void MmcBlockOsUninit(struct MmcDevice *mmcDevice); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* MMC_BLOCK_H */ diff --git a/model/storage/include/mtd/mtd_block.h b/model/storage/include/mtd/mtd_block.h index c1dc005ac9aff0d48ab0fa1c85f0e986725896ed..9d82c4db0b32a22a7f600b1a72d87f34e8bcf423 100644 --- a/model/storage/include/mtd/mtd_block.h +++ b/model/storage/include/mtd/mtd_block.h @@ -17,12 +17,47 @@ extern "C" { #endif #endif /* __cplusplus */ -int32_t MtdBlockInit(struct MtdDevice *mtd); -void MtdBlockUninit(struct MtdDevice *mtd); +/** + * @brief Block device init for the mtd device. + * + * This function behaves differently in different OS + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns 0 if init successfully; returns a negative value otherwise. + */ +int32_t MtdBlockInit(struct MtdDevice *mtdDevice); + +/** + * @brief Block device uninit for the mtd device. + * + * This function behaves differently in different OS + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + */ +void MtdBlockUninit(struct MtdDevice *mtdDevice); -/* these too functions gona implemented by specific os */ -extern int32_t MtdBlockOsInit(struct MtdDevice *mtd); -extern void MtdBlockOsUninit(struct MtdDevice *mtd); +/** + * @brief Block device init for the mtd device in specific os. + * + * These function gona be implemented by specific os + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns 0 if init successfully; returns a negative value otherwise. + */ +int32_t MtdBlockOsInit(struct MtdDevice *mtd); + +/** + * @brief Block device uninit for the mtd device in specific os. + * + * These function gona be implemented by specific os + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + */ +void MtdBlockOsUninit(struct MtdDevice *mtd); #ifdef __cplusplus #if __cplusplus diff --git a/model/storage/include/mtd/mtd_char.h b/model/storage/include/mtd/mtd_char.h index 3d32a273680778869c23b50151435844a0a492c8..80b8ff4ff6d2535ee2ac59ac6924d8557dcc2b70 100644 --- a/model/storage/include/mtd/mtd_char.h +++ b/model/storage/include/mtd/mtd_char.h @@ -19,12 +19,47 @@ extern "C" { #define CHAR_NAME_LEN 32 +/** + * @brief Char device init for the mtd device. + * + * This function behaves differently in different OS + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns 0 if init successfully; returns a negative value otherwise. + */ int32_t MtdCharInit(struct MtdDevice *mtdDevice); + +/** + * @brief Char device uninit for the mtd device. + * + * This function behaves differently in different OS + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + */ void MtdCharUninit(struct MtdDevice *mtdDevice); -/* these too functions gona implemented by specific os */ -extern int32_t MtdCharOsInit(struct MtdDevice *mtdDevice); -extern void MtdCharOsUninit(struct MtdDevice *mtdDevice); +/** + * @brief Char device init for the mtd device in specific OS. + * + * These function gona be implemented by specific os + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns 0 if init successfully; returns a negative value otherwise. + */ +int32_t MtdCharOsInit(struct MtdDevice *mtdDevice); + +/** + * @brief Char device uninit for the mtd device in specific OS. + * + * These function gona be implemented by specific os + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + */ +void MtdCharOsUninit(struct MtdDevice *mtdDevice); #ifdef __cplusplus #if __cplusplus diff --git a/model/storage/include/mtd/mtd_core.h b/model/storage/include/mtd/mtd_core.h index 4b1f311903fbec7402e618b24f55a48b4bfc5009..0e449b70f2e1c57835158e2f933d967c00d508d2 100644 --- a/model/storage/include/mtd/mtd_core.h +++ b/model/storage/include/mtd/mtd_core.h @@ -13,15 +13,20 @@ #include "hdf_base.h" #include "osal_mutex.h" -#include "platform_device.h" +#include "platform_core.h" #define MTD_FLASH_ID_LEN_MAX 8 +#define MTD_DEVICE_NUM_MAX 3 // #define MTD_DEBUG /* open this macro for debug */ struct MtdDevice; struct MtdDeviceMethod; +/** + * @brief Enumerates the types of mtd devices. + * + */ enum MtdDevType { MTD_TYPE_NOR, MTD_TYPE_NAND, @@ -30,32 +35,68 @@ enum MtdDevType { MTD_TYPE_MAX, }; +/** + * @brief Enumerates the types of mtd message. + * + */ enum MtdMsgType { MTD_MSG_TYPE_WRITE, MTD_MSG_TYPE_READ, MTD_MSG_TYPE_ERASE, }; +/** + * @Defines the mtd request message used during request. + * + * This struct describes a custom access request typed by MtdMsgType + * + */ struct MtdMsg { + /** Type of the mtd message */ enum MtdMsgType type; + /** Start address of the mtd device to access */ off_t addr; + /** Indicates the failed address if request failed */ off_t faddr; + /** Pointer to the buffer for storing request data */ uint8_t *buf; + /** Length of the data */ size_t len; + /** Indicates whether request with oob data */ bool withOob; + /** Indicates whether skip on bad block */ bool skipBad; }; +/** + * @Defines the mtd page struct used during page transfer. + * + * This struct describes a page transfer request typed by MtdMsgType + * + */ struct MtdPage { + /** Page transfer type */ enum MtdMsgType type; + /** Start address of the mtd device to transfer from */ off_t addr; + /** Indicates the failed address if transfer failed */ off_t failAddr; + /** Pointer to the data buffer */ uint8_t *dataBuf; + /** Length of the data */ size_t dataLen; + /** Pointer to the oob data buffer */ uint8_t *oobBuf; + /** Length of the oob data */ size_t oobLen; }; +/** + * @Defines the callback method set of a mtd device. + * + * The methods defined in this struct expected to be implemented by drivers + * + */ struct MtdDeviceMethod { int32_t (*read)(struct MtdDevice *mtdDevice, off_t from, size_t len, uint8_t *buf); int32_t (*write)(struct MtdDevice *mtdDevice, off_t to, size_t len, const uint8_t *buf); @@ -68,58 +109,244 @@ struct MtdDeviceMethod { void (*unlock)(struct MtdDevice *mtdDevice); }; +/** + * @Defines the structure used to identify a physical mtd chip. + * + */ struct MtdDevice { + /** The parent device */ struct PlatformDevice device; + /** Number of the mtd device */ int16_t index; + /** Name of the mtd device */ const char *name; + /** Chip name of the mtd device */ const char *chipName; + /** Type of the mtd device */ enum MtdDevType type; union { + /** Vendor id of the mtd device */ uint8_t id[MTD_FLASH_ID_LEN_MAX]; struct { uint8_t mfrId; // id[0]: Manufacture ID uint8_t devId; // id[0]: Device ID }; }; + /** Length of the vendor id */ uint16_t idLen; - size_t capacity; // by bytes - size_t eraseSize; // by bytes - size_t writeSize; // by bytes - size_t readSize; // by bytes - size_t oobSize; // for nand only + /** Length of the vendor id */ + size_t capacity; + /** Erase size of the mtd device */ + size_t eraseSize; + /** Write size of the mtd device */ + size_t writeSize; + /** Read size of the mtd device */ + size_t readSize; + /** Oob size of the mtd device */ + size_t oobSize; + /** Write size shift bits of the mtd device */ unsigned int writeSizeShift; + /** Mutex lock for accessing protection */ struct OsalMutex lock; + /** The callback method set to access the device */ struct MtdDeviceMethod *ops; + /** Os specific data */ void *osData; + /** Flash memory controller specific data */ void *cntlr; + /** Private data of the mtd device */ void *priv; }; +/** + * @brief Get the manager of mtd + * + * @return Returns the pointer to the manager if success; + * returns NULL otherwise. + */ +struct PlatformManager *MtdManagerGet(void); + +/** + * @brief Add a mtd device. + * + * do not call in irq context cause it may sleep + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns 0 if add successfully; returns a negative value otherwise. + */ int32_t MtdDeviceAdd(struct MtdDevice *mtdDevice); + +/** + * @brief Delete a mtd device. + * + * do not call in irq context cause it may sleep + * + * @param mtdDevice Indicates the pointer to the mtd device. + */ void MtdDeviceDel(struct MtdDevice *mtdDevice); +/** + * @brief Increase reference count for a mtd device. + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns the pointer to the mtd device on success; returns NULL otherwise. + */ +static inline struct MtdDevice *MtdDeviceGet(struct MtdDevice *mtdDevice) +{ + if (mtdDevice != NULL && PlatformDeviceGet(&mtdDevice->device) != NULL) { + return mtdDevice; + } + return NULL; +} + +/** + * @brief Increase reference count for a mtd device by number. + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns the pointer to the mtd device on success; returns NULL otherwise. + */ +static inline struct MtdDevice *MtdDeviceGetByNum(int16_t num) +{ + struct PlatformDevice *device = PlatformManagerGetDeviceByMagic(MtdManagerGet(), num); + + if (device != NULL) { + return CONTAINER_OF(device, struct MtdDevice, device); + } + return NULL; +} + +/** + * @brief Decrease reference count for a mtd device. + * + * @param mtdDevice Indicates the pointer to the mtd device. + */ +static inline void MtdDevicePut(struct MtdDevice *mtdDevice) +{ + if (mtdDevice != NULL) { + PlatformDevicePut(&mtdDevice->device); + } +} + +/** + * @brief Lock the mtd device exclusivly. + * + * do not call in irq context cause it may sleep + * + * @param mtdDevice Indicates the pointer to the mtd device. + * + * @return Returns 0 on success; returns a negative value otherwise. + */ int32_t MtdDeviceLock(struct MtdDevice *mtdDevice); + +/** + * @brief Unlock the mtd device. + * + * do not call in irq context cause it may sleep + * + * @param mtdDevice Indicates the pointer to the mtd device. + */ void MtdDeviceUnlock(struct MtdDevice *mtdDevice); +/** + * @brief Reads data of a specified size from a mtd device. + * + * do not call in irq context cause it may sleep + * + * @param mtdDevice Indicates the pointer to the mtd device. + * @param from Indicates the start address to read from. + * @param len Indicates the size of the data to read. + * @param buf Indicates the pointer to the buffer for receiving the data. + * + * @return Returns the size of the data read on success; returns a negative value otherwise. + */ ssize_t MtdDeviceRead(struct MtdDevice *mtdDevice, off_t from, size_t len, uint8_t *buf); + +/** + * @brief Writes data of a specified size to a mtd device. + * + * do not call in irq context cause it may sleep + * + * @param mtdDevice Indicates the pointer to the mtd device. + * @param to Indicates the start address to write to. + * @param len Indicates the size of the data to write. + * @param buf Indicates the pointer to the buffer which provide the data. + * + * @return Returns the size of the data written on success; returns a negative value otherwise. + */ ssize_t MtdDeviceWrite(struct MtdDevice *mtdDevice, off_t to, size_t len, const uint8_t *buf); -ssize_t MtdDeviceErase(struct MtdDevice *mtdDevice, off_t from, size_t len, off_t *failAddr); +/** + * @brief Erases data of a specified size to a mtd device. + * + * do not call in irq context cause it may sleep + * + * @param mtdDevice Indicates the pointer to the mtd device. + * @param from Indicates the start address to erase from. + * @param len Indicates the size of the data to erase. + * @param faddr Indicates the pointer for receiving the address when erasing failed. + * + * @return Returns the size of the data erased on success; returns a negative value otherwise. + */ +ssize_t MtdDeviceErase(struct MtdDevice *mtdDevice, off_t from, size_t len, off_t *faddr); + +/** + * @brief Reads data of a specified size from a mtd device including oob data. + * + * It is similar to MtdDeviceRead but read oob data together. + * + * @param mtdDevice Indicates the pointer to the mtd device. + * @param from Indicates the start address to read from. + * @param len Indicates the size of the data, including oob, to read. + * @param buf Indicates the pointer to the buffer for receiving the data, including oob data. + * + * @return Returns the size of the data read on success; returns a negative value otherwise. + */ ssize_t MtdDeviceReadWithOob(struct MtdDevice *mtdDevice, off_t from, size_t len, uint8_t *buf); + +/** + * @brief Writes data of a specified size to a mtd device including oob data. + * + * It is similar to MtdDeviceWrite but write oob data together. + * + * @param mtdDevice Indicates the pointer to the mtd device. + * @param to Indicates the start address to write to. + * @param len Indicates the size of the data, including oob, to . + * @param buf Indicates the pointer to the buffer which provide the data including oob. + * + * @return Returns the size of the data read on success; returns a negative value otherwise. + */ ssize_t MtdDeviceWriteWithOob(struct MtdDevice *mtdDevice, off_t to, size_t len, const uint8_t *buf); + +/** + * @brief Judge whether the block where the specified address is located is a bad block + * + * @param mtdDevice Indicates the pointer to the mtd device. + * @param addr Indicates the address to judge, which is not neccessary to align by block size. + * + * @return Returns true is the specified address falls into a bad block; returns false otherwise. + */ bool MtdDeviceIsBadBlock(struct MtdDevice *mtdDevice, off_t addr); + +/** + * @brief Mark the block where the specified address is located as a bad block + * + * @param mtdDevice Indicates the pointer to the mtd device. + * @param addr Indicates the address to mark, which is not neccessary to align by block size. + * + * @return Returns 0 on success; returns a negative value otherwise. + */ int32_t MtdDeviceMarkBadBlock(struct MtdDevice *mtdDevice, off_t addr); -static inline bool MtdDeviceIsPageAligned(struct MtdDevice *mtdDevice, off_t addr) -{ - return ((addr & (mtdDevice->writeSize - 1)) == 0); -} -static inline size_t MtdDeviceAddrToPage(struct MtdDevice *mtdDevice, off_t addr) -{ - return (size_t)(addr >> mtdDevice->writeSizeShift); -} +/***************************** Other Utils *******************************************/ +/** + * @brief A debugging macro which an dump all the attributes of a mtd device + * + */ #define MTD_DEVICE_DUMP(mtd) \ do { \ uint16_t i; \ @@ -134,9 +361,28 @@ static inline size_t MtdDeviceAddrToPage(struct MtdDevice *mtdDevice, off_t addr HDF_LOGI("%s: oobSize: %zu", __func__, mtd->oobSize); \ } while (0) +/** + * @brief Judge whether the specified address is aligned by page size + * + */ +static inline bool MtdDeviceIsPageAligned(struct MtdDevice *mtdDevice, off_t addr) +{ + return ((addr & (mtdDevice->writeSize - 1)) == 0); +} -/***************************** Other Utils *******************************************/ +/** + * @brief Transfer the specified address to page number + * + */ +static inline size_t MtdDeviceAddrToPage(struct MtdDevice *mtdDevice, off_t addr) +{ + return (size_t)(addr >> mtdDevice->writeSizeShift); +} +/** + * @brief Flush the cache for dma transfer + * + */ static inline void MtdDmaCacheClean(void *addr, size_t size) { uintptr_t start = (uintptr_t)addr & ~(CACHE_ALIGNED_SIZE - 1); @@ -147,6 +393,10 @@ static inline void MtdDmaCacheClean(void *addr, size_t size) return; } +/** + * @brief Invalid the cache for dma transfer + * + */ static inline void MtdDmaCacheInv(void *addr, size_t size) { uintptr_t start = (uintptr_t)addr & ~(CACHE_ALIGNED_SIZE - 1); @@ -157,6 +407,11 @@ static inline void MtdDmaCacheInv(void *addr, size_t size) return; } +/** + * @brief Find the first bit set in word + * + * @return Returns the position of first bit set; returns 0 if all zero. + */ int MtdFfs(int x); #endif /* MTD_CORE_H */ diff --git a/model/storage/include/mtd/mtd_nand.h b/model/storage/include/mtd/mtd_nand.h index 055f7c88b1451435163f02ceeb62ebd39d9cddba..01101da644ef3a3a63508d93a4e928b37a4782bf 100644 --- a/model/storage/include/mtd/mtd_nand.h +++ b/model/storage/include/mtd/mtd_nand.h @@ -18,6 +18,10 @@ extern "C" { #endif #endif /* __cplusplus */ +/** + * @brief Enumerates the page size type of a nand flash memory. + * + */ enum MtdNandPageSize { MTD_NAND_PAGE_SIZE_512 = 512, MTD_NAND_PAGE_SIZE_2K = 2048, @@ -26,6 +30,10 @@ enum MtdNandPageSize { MTD_NAND_PAGE_SIZE_16K = 16384, }; +/** + * @brief Enumerates the ECC type of a nand flash memory. + * + */ enum MtdNandEccTYpe { MTD_NAND_ECC_0BIT = 0, MTD_NAND_ECC_8BIT_1K = 1, @@ -36,6 +44,10 @@ enum MtdNandEccTYpe { MTD_NAND_ECC_64BIT_1K = 6, }; +/** + * @brief Defines the bad block area size of a nand flash memory. + * + */ #define MTD_NAND_BB_SIZE 2 #ifdef __cplusplus diff --git a/model/storage/include/mtd/mtd_spi_common.h b/model/storage/include/mtd/mtd_spi_common.h index cf46b3a5795229bc6d899e9abc713a6065ecf4b7..a55e1f099c65447babbc531b874f4d99f31ae144 100644 --- a/model/storage/include/mtd/mtd_spi_common.h +++ b/model/storage/include/mtd/mtd_spi_common.h @@ -19,14 +19,39 @@ extern "C" { struct SpiFlash; +/** + * @Defines the spi configuration of a specific operation + * + */ struct MtdSpiConfig { + /** spi interface type */ uint8_t ifType; + /** the operation command */ uint8_t cmd; + /** dummy cycles */ uint8_t dummy; + /** not used now */ uint32_t size; + /** system clock used */ uint32_t clock; }; +/** + * @brief Enumerates the type of spi interface. + * + */ +enum SpiIfType { + MTD_SPI_IF_STD = 0, + MTD_SPI_IF_DUAL = 1, + MTD_SPI_IF_DIO = 2, + MTD_SPI_IF_QUAD = 3, + MTD_SPI_IF_QIO = 4, +}; + +/** + * @Defines the spi oepration set of a mtd device. + * + */ struct MtdSpiOps { int32_t (*waitReady)(struct SpiFlash *spi); int32_t (*writeEnable)(struct SpiFlash *spi); @@ -34,38 +59,91 @@ struct MtdSpiOps { int32_t (*entry4Addr)(struct SpiFlash *spi, int enable); }; +/** + * @Defines the info structure which contains vendor id and spi operations + * + */ struct SpiOpsInfo { uint8_t id[MTD_FLASH_ID_LEN_MAX]; uint8_t idLen; struct MtdSpiOps spiOps; }; -enum SpiIfType { - MTD_SPI_IF_STD = 0, - MTD_SPI_IF_DUAL = 1, - MTD_SPI_IF_DIO = 2, - MTD_SPI_IF_QUAD = 3, - MTD_SPI_IF_QIO = 4, -}; - +/** + * @Defines the structure used to identify a physical spi flash. + * + */ struct SpiFlash { + /** The parent device */ struct MtdDevice mtd; + /** chip select number */ uint8_t cs; - uint8_t qeEnable; - uint8_t qeSupport; + /** address cycle */ uint32_t addrCycle; + /** spi configuration of erase */ struct MtdSpiConfig eraseCfg; + /** spi configuration of write */ struct MtdSpiConfig writeCfg; + /** spi configuration of read */ struct MtdSpiConfig readCfg; + /** spi operation set of the device */ struct MtdSpiOps spiOps; }; +/** + * @brief Wait for a spi flash to be ready. + * + * @param spi Indicates the pointer to the spi flash. + * + * @return Returns 0 on success; returns a negative value otherwise. + */ int32_t SpiFlashWaitReady(struct SpiFlash *spi); + +/** + * @brief Enable write operation to a spi falsh. + * + * @param spi Indicates the pointer to the spi flash. + * + * @return Returns 0 on success; returns a negative value otherwise. + */ int32_t SpiFlashWriteEnable(struct SpiFlash *spi); + +/** + * @brief Enable QUAD I/O mode of a spi falsh if it supports. + * + * @param spi Indicates the pointer to the spi flash. + * + * @return Returns 0 on success; returns a negative value otherwise. + */ int32_t SpiFlashQeEnable(struct SpiFlash *spi); + +/** + * @brief Enable 4 byte address mode of a spi falsh if it supports. + * + * @param spi Indicates the pointer to the spi flash. + * + * @return Returns 0 on success; returns a negative value otherwise. + */ int32_t SpiFlashEntry4Addr(struct SpiFlash *spi, int enable); +/** + * @brief Add a spi flash device. + * + * do not call in irq context cause it may sleep + * + * @param spi Indicates the pointer to the spi flash device. + * + * @return Returns 0 if add successfully; returns a negative value otherwise. + */ int32_t SpiFlashAdd(struct SpiFlash *spi); + +/** + * @brief Delete a spi flash device. + * + * do not call in irq context cause it may sleep + * + * @param spi Indicates the pointer to the spi flash device. + */ void SpiFlashDel(struct SpiFlash *spi); /****************************Spi Common Command Set **************************************/ @@ -117,7 +195,6 @@ void SpiFlashDel(struct SpiFlash *spi); #ifdef __cplusplus #if __cplusplus - } #endif #endif /* __cplusplus */ diff --git a/model/storage/include/mtd/mtd_spi_nand.h b/model/storage/include/mtd/mtd_spi_nand.h index 76b3e7ecb8ea366ed7bd76935e764d1f8d030c41..eb8a3dce0505243cbf73411a04719d47a2aa971a 100644 --- a/model/storage/include/mtd/mtd_spi_nand.h +++ b/model/storage/include/mtd/mtd_spi_nand.h @@ -41,6 +41,10 @@ extern "C" { #define MTD_SPI_NAND_ERASE_FAIL 0x04 #define MTD_SPI_NAND_PROG_FAIL 0x08 +/** + * @Defines the structure used to describe a spi nand flash. + * + */ struct SpinandInfo { const char *name; uint8_t id[MTD_FLASH_ID_LEN_MAX]; diff --git a/model/storage/include/mtd/mtd_spi_nor.h b/model/storage/include/mtd/mtd_spi_nor.h index fd1e210eb313cdac659fef6c2e6593a781614276..cab675bb1da1914845de13da23931a132f022f62 100644 --- a/model/storage/include/mtd/mtd_spi_nor.h +++ b/model/storage/include/mtd/mtd_spi_nor.h @@ -23,6 +23,10 @@ extern "C" { #define MTD_SPI_ADDR_3BYTE 3 #define MTD_SPI_ADDR_4BYTE 4 +/** + * @Defines the structure used to describe a spi nor flash. + * + */ struct SpinorInfo { const char *name; uint8_t id[MTD_FLASH_ID_LEN_MAX]; diff --git a/model/storage/src/common/storage_block.c b/model/storage/src/common/storage_block.c deleted file mode 100644 index 54733351e5e9899bc54e35d91473f2f9c5847f05..0000000000000000000000000000000000000000 --- a/model/storage/src/common/storage_block.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ -#include "hdf_base.h" -#include "hdf_log.h" -#include "platform_core.h" -#include "storage_block.h" - -#define HDF_LOG_TAG storage_block_c - -#define MAX_BLOCK_COUNT 3 - -static struct StorageBlock *g_blocks[MAX_BLOCK_COUNT]; - -ssize_t StorageBlockErase(struct StorageBlock *sb, size_t secStart, size_t secNr) -{ - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (sb->ops == NULL || sb->ops->erase == NULL) { - return HDF_ERR_NOT_SUPPORT; - } - return sb->ops->erase(sb, secStart, secNr); -} - -ssize_t StorageBlockWrite(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr) -{ - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (sb->ops == NULL || sb->ops->write == NULL) { - return HDF_ERR_NOT_SUPPORT; - } - return sb->ops->write(sb, buf, secStart, secNr); -} - -ssize_t StorageBlockRead(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr) -{ - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (sb->ops == NULL || sb->ops->read == NULL) { - return HDF_ERR_NOT_SUPPORT; - } - return sb->ops->read(sb, buf, secStart, secNr); -} - -int32_t StorageBlockGetAuSize(struct StorageBlock *sb, uint32_t *auSize) -{ - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (sb->ops == NULL || sb->ops->getAuSize == NULL) { - return HDF_ERR_NOT_SUPPORT; - } - *auSize = sb->ops->getAuSize(sb); - return HDF_SUCCESS; -} - -size_t StorageBlockGetCapacity(struct StorageBlock *sb) -{ - return (sb == NULL) ? 0 : sb->capacity; -} - -bool StorageBlockIsPresent(struct StorageBlock *sb) -{ - return (sb != NULL && sb->ops != NULL && - sb->ops->isPresent != NULL && sb->ops->isPresent(sb)); -} - -int32_t StorageBlockAdd(struct StorageBlock *sb) -{ - int i; - int32_t ret; - - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - - for (i = 0; i < MAX_BLOCK_COUNT; i++) { - if (g_blocks[i] == NULL) { - g_blocks[i] = sb; - sb->index = i; - break; - } - } - if (i >= MAX_BLOCK_COUNT) { - return HDF_PLT_ERR_DEV_FULL; - } - - if (sb->secSize == 0) { - sb->secSize = STORAGE_SEC_SIZE; - } - - ret = StorageBlockOsInit(sb); - if (ret != HDF_SUCCESS) { - g_blocks[i] = NULL; - return ret; - } - - return HDF_SUCCESS; -} - -void StorageBlockDel(struct StorageBlock *sb) -{ - int i; - - if (sb == NULL) { - return; - } - - for (i = 0; i < MAX_BLOCK_COUNT; i++) { - if (g_blocks[i] == sb) { - g_blocks[i] = NULL; - } - } - - StorageBlockOsUninit(sb); -} - -struct StorageBlock *StorageBlockFromNumber(uint32_t number) -{ - if (number >= MAX_BLOCK_COUNT) { - HDF_LOGE("StorageBlockFromNumber: invalid number:%d", number); - return NULL; - } - return g_blocks[number]; -} diff --git a/model/storage/src/mmc/mmc_block.c b/model/storage/src/mmc/mmc_block.c new file mode 100644 index 0000000000000000000000000000000000000000..86ba1c7424dbc66969e4904790765bd52ff40db6 --- /dev/null +++ b/model/storage/src/mmc/mmc_block.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "securec.h" + +#include "hdf_base.h" +#include "hdf_log.h" +#include "mmc_block.h" +#include "platform_core.h" + +#define HDF_LOG_TAG mmc_block_c + +int32_t MmcBlockInit(struct MmcDevice *mmcDevice) +{ + int32_t ret; + size_t nameSize; + struct MmcBlock *mb = NULL; + + if (mmcDevice == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + if (PlatformDeviceGet(&mmcDevice->device) == NULL) { + return HDF_PLT_ERR_DEV_GET; + } + + mb = (struct MmcBlock *)OsalMemCalloc(sizeof(*mb)); + if (mb == NULL) { + PlatformDevicePut(&mmcDevice->device); + return HDF_ERR_MALLOC_FAIL; + } + + mmcDevice->mb = mb; + mb->mmc = mmcDevice; + mb->secSize = mmcDevice->secSize; + mb->capacity = mmcDevice->capacity; + mb->removeable = (mmcDevice->state.bits.removeable == 0) ? false : true; + nameSize = sizeof(mb->name); + ret = snprintf_s(mb->name, nameSize, nameSize - 1, "/dev/mmcblk%0d", mmcDevice->cntlr->index); + if (ret <= 0) { + OsalMemFree(mb); + PlatformDevicePut(&mmcDevice->device); + HDF_LOGE("%s: format block dev name failed, ret = %d", __func__, ret); + return HDF_PLT_ERR_OS_API; + } + + ret = MmcBlockOsInit(mmcDevice); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: mmc block os init failed, ret = %d", __func__, ret); + OsalMemFree(mb); + PlatformDevicePut(&mmcDevice->device); + return ret; + } + return HDF_SUCCESS; +} + +void MmcBlockUninit(struct MmcDevice *mmcDevice) +{ + if (mmcDevice != NULL) { + MmcBlockOsUninit(mmcDevice); + OsalMemFree(mmcDevice->mb); + mmcDevice->mb = NULL; + PlatformDevicePut(&mmcDevice->device); + } +} diff --git a/model/storage/src/mtd/mtd_block.c b/model/storage/src/mtd/mtd_block.c index fb3c39f305c3b782bf7d6cb1689ee551516a6d51..069172b2c196116f63184b5f8f82c71d439afa09 100644 --- a/model/storage/src/mtd/mtd_block.c +++ b/model/storage/src/mtd/mtd_block.c @@ -6,6 +6,7 @@ * See the LICENSE file in the root of this repository for complete details. */ +#include "hdf_log.h" #include "mtd_core.h" __attribute__((weak)) int32_t MtdBlockOsInit(struct MtdDevice *mtdDevice) @@ -21,10 +22,31 @@ __attribute__ ((weak)) void MtdBlockOsUninit(struct MtdDevice *mtdDevice) int32_t MtdBlockInit(struct MtdDevice *mtdDevice) { - return MtdBlockOsInit(mtdDevice); + int32_t ret; + + if (mtdDevice == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + if (MtdDeviceGet(mtdDevice) == NULL) { + HDF_LOGE("%s: get mtd device failed", __func__); + return HDF_PLT_ERR_DEV_GET; + } + + ret = MtdBlockOsInit(mtdDevice); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: os init failed, ret = %d", __func__, ret); + MtdDevicePut(mtdDevice); + return ret; + } + + return HDF_SUCCESS; } void MtdBlockUninit(struct MtdDevice *mtdDevice) { - MtdBlockOsUninit(mtdDevice); + if (mtdDevice != NULL) { + MtdBlockOsUninit(mtdDevice); + MtdDevicePut(mtdDevice); + } } diff --git a/model/storage/src/mtd/mtd_core.c b/model/storage/src/mtd/mtd_core.c index 051e55efb0aa35dde9d64b87374fa3aba8cc98a4..5093da2ced372b9ae38268f10732aab4b5ff0be1 100644 --- a/model/storage/src/mtd/mtd_core.c +++ b/model/storage/src/mtd/mtd_core.c @@ -16,7 +16,7 @@ static int32_t MtdDeviceCheckParms(struct MtdDevice *mtdDevice) { - if (mtdDevice->index < 0) { + if (mtdDevice->index < 0 || mtdDevice->index >= MTD_DEVICE_NUM_MAX) { HDF_LOGE("%s: invalid index: %d", __func__, mtdDevice->index); return HDF_ERR_INVALID_OBJECT; } @@ -96,6 +96,16 @@ static void MtdDeviceUnlockDefault(struct MtdDevice *mtdDevice) return; } +struct PlatformManager *MtdManagerGet(void) +{ + static struct PlatformManager *g_mtdManager = NULL; + + if (g_mtdManager == NULL) { + g_mtdManager = PlatformManagerCreate("STORAGE_MTD"); + } + return g_mtdManager; +} + int32_t MtdDeviceAdd(struct MtdDevice *mtdDevice) { int32_t ret; @@ -124,15 +134,25 @@ int32_t MtdDeviceAdd(struct MtdDevice *mtdDevice) mtdDevice->ops->unlock = MtdDeviceUnlockDefault; } + mtdDevice->device.manager = MtdManagerGet(); + mtdDevice->device.magic = mtdDevice->index; + ret = PlatformDeviceAdd(&mtdDevice->device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: mtd device add fail", __func__); + return ret; + } + MtdDeviceDump(mtdDevice); ret = MtdCharInit(mtdDevice); if (ret != HDF_SUCCESS) { + PlatformDeviceDel(&mtdDevice->device); return ret; } ret = MtdBlockInit(mtdDevice); if (ret != HDF_SUCCESS) { + PlatformDeviceDel(&mtdDevice->device); return ret; } @@ -144,6 +164,7 @@ void MtdDeviceDel(struct MtdDevice *mtdDevice) if (mtdDevice != NULL) { MtdCharUninit(mtdDevice); MtdBlockUninit(mtdDevice); + PlatformDeviceDel(&mtdDevice->device); (void)OsalMutexDestroy(&mtdDevice->lock); } } diff --git a/model/storage/src/mtd/mtd_spi_common.c b/model/storage/src/mtd/mtd_spi_common.c index 7561507e388790518153ee56346a60de888a68b5..cf2176e564e76e173264c2b716d4d57194dbfa6c 100644 --- a/model/storage/src/mtd/mtd_spi_common.c +++ b/model/storage/src/mtd/mtd_spi_common.c @@ -20,8 +20,7 @@ static void SpiFlashDumpDefualt(struct MtdDevice *mtdDevice) MTD_DEVICE_DUMP(mtdDevice); spi = CONTAINER_OF(mtdDevice, struct SpiFlash, mtd); - HDF_LOGD("%s: cs = %u, qe = %u, addrCycle = %u", __func__, - spi->cs, spi->qeEnable, spi->addrCycle); + HDF_LOGD("%s: cs = %u, addrCycle = %u", __func__, spi->cs, spi->addrCycle); cfg = &spi->readCfg; HDF_LOGD("%s: readCfg -> ifType:%u, cmd:0x%x, dummy:%u, size:%u, clock:%u", diff --git a/support/platform/include/mmc/mmc_block.h b/support/platform/include/mmc/mmc_block.h deleted file mode 100644 index bec2bb785c3e1b8a73fb816c99ca64dd5193e679..0000000000000000000000000000000000000000 --- a/support/platform/include/mmc/mmc_block.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef MMC_BLOCK_H -#define MMC_BLOCK_H - -#include "mmc_corex.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -int32_t MmcBlockAdd(struct MmcDevice *mmc); -void MmcBlockDel(struct MmcDevice *mmc); - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* MMC_BLOCK_H */ diff --git a/support/platform/include/mmc/mmc_corex.h b/support/platform/include/mmc/mmc_corex.h index f3c2afdaf9b541f6dc16fd57e0b1883d7e6f5790..fbf927522d2a7c1db53d8801e38e7defb331aa88 100644 --- a/support/platform/include/mmc/mmc_corex.h +++ b/support/platform/include/mmc/mmc_corex.h @@ -224,7 +224,7 @@ struct MmcDevice { size_t secSize; // by bytes size_t capacity; // by sectors size_t eraseSize; // by sectors - struct StorageBlock *sb; + struct MmcBlock *mb; void *priv; }; diff --git a/support/platform/src/mmc/mmc_block.c b/support/platform/src/mmc/mmc_block.c deleted file mode 100644 index 2917a2842919be037a7a171690a26b2b66c1d719..0000000000000000000000000000000000000000 --- a/support/platform/src/mmc/mmc_block.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "storage_block.h" -#include "hdf_base.h" -#include "hdf_log.h" -#include "mmc_corex.h" -#include "mmc_sd.h" -#include "osal_mem.h" -#include "securec.h" - -static ssize_t MmcBlockRead(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t nSec) -{ - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (sb->type == MEDIA_MMC) { - return MmcDeviceRead((struct MmcDevice *)sb->media, buf, secStart, nSec); - } - return HDF_ERR_NOT_SUPPORT; -} - -static ssize_t MmcBlockWrite(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t nSec) -{ - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (sb->type == MEDIA_MMC) { - return MmcDeviceWrite((struct MmcDevice *)sb->media, (uint8_t *)buf, secStart, nSec); - } - return HDF_ERR_NOT_SUPPORT; -} - -static ssize_t MmcBlockErase(struct StorageBlock *sb, size_t secStart, size_t nSec) -{ - if (sb == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - if (sb->type == MEDIA_MMC) { - return MmcDeviceErase((struct MmcDevice *)sb->media, secStart, nSec); - } - return HDF_ERR_NOT_SUPPORT; -} - -static uint32_t MmcBlockGetAuSize(struct StorageBlock *sb) -{ - struct MmcDevice *mmc = NULL; - struct SdDevice *sd = NULL; - - if (sb == NULL || sb->media == NULL) { - HDF_LOGE("MmcBlockGetAuSize: invalid sb or media!"); - return 0; - } - - if (sb->type != MEDIA_MMC) { - HDF_LOGE("MmcBlockGetAuSize: media is not mmc!"); - return 0; - } - - mmc = (struct MmcDevice *)sb->media; - if (mmc->type != MMC_DEV_SD) { - HDF_LOGE("MmcBlockGetAuSize: media is not sd!"); - return 0; - } - sd = (struct SdDevice *)mmc; - - return sd->reg.ssr.auSize; -} - -static bool MmcBlockIsPresent(struct StorageBlock *sb) -{ - return (sb != NULL && sb->type == MEDIA_MMC && - MmcDeviceIsPresent((struct MmcDevice *)sb->media)); -} - -static struct StorageBlockMethod g_mmcBlockOps = { - .read = MmcBlockRead, - .write = MmcBlockWrite, - .erase = MmcBlockErase, - .getAuSize = MmcBlockGetAuSize, - .isPresent = MmcBlockIsPresent, -}; - -static int32_t MmcBlockInit(struct StorageBlock *sb, struct MmcDevice *mmc) -{ - int32_t ret; - size_t nameSize; - - if (PlatformDeviceGet(&mmc->device) == NULL) { - return HDF_PLT_ERR_DEV_GET; - } - mmc->sb = sb; - sb->type = MEDIA_MMC; - sb->media = mmc; - sb->secSize = mmc->secSize; - sb->capacity = mmc->capacity; - sb->removeable = (mmc->state.bits.removeable == 0) ? false : true; - sb->ops = &g_mmcBlockOps; - nameSize = sizeof(sb->name); - ret = snprintf_s(sb->name, nameSize, nameSize - 1, "/dev/mmcblk%0d", mmc->cntlr->index); - if (ret <= 0) { - PlatformDevicePut(&mmc->device); - } - - return HDF_SUCCESS; -} - -static void MmcBlockUninit(struct StorageBlock *sb) -{ - struct MmcDevice *mmc = (struct MmcDevice *)sb->media; - - mmc->sb = NULL; - PlatformDevicePut(&mmc->device); -} - -int32_t MmcBlockAdd(struct MmcDevice *mmc) -{ - int32_t ret; - struct StorageBlock *sb = NULL; - - if (mmc == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - - sb = (struct StorageBlock *)OsalMemCalloc(sizeof(*sb)); - if (sb == NULL) { - return HDF_ERR_MALLOC_FAIL; - } - - ret = MmcBlockInit(sb, mmc); - if (ret != HDF_SUCCESS) { - OsalMemFree(sb); - return ret; - } - - ret = StorageBlockAdd(sb); - if (ret != HDF_SUCCESS) { - MmcBlockUninit(sb); - OsalMemFree(sb); - return ret; - } - - return HDF_SUCCESS; -} - -void MmcBlockDel(struct MmcDevice *mmc) -{ - struct StorageBlock *sb = NULL; - - if (mmc == NULL) { - return; - } - sb = mmc->sb; - if (sb == NULL) { - return; - } - - StorageBlockDel(sb); - MmcBlockUninit(sb); - OsalMemFree(sb); -} diff --git a/support/platform/src/mmc/mmc_core.c b/support/platform/src/mmc/mmc_core.c index 6d2670b1ae9f4f8d171de83141be8718afb98999..68493eb6c83c5d9857a191e129eab33c16353f96 100644 --- a/support/platform/src/mmc/mmc_core.c +++ b/support/platform/src/mmc/mmc_core.c @@ -1005,7 +1005,7 @@ int32_t MmcDeviceAdd(struct MmcDevice *mmc) } if (mmc->type == MMC_DEV_EMMC || mmc->type == MMC_DEV_SD || mmc->type == MMC_DEV_COMBO) { - ret = MmcBlockAdd(mmc); + ret = MmcBlockInit(mmc); if (ret != HDF_SUCCESS) { MmcCntlrPut(mmc->cntlr); PlatformDeviceDel(&mmc->device); @@ -1021,7 +1021,7 @@ void MmcDeviceRemove(struct MmcDevice *mmc) return; } if (mmc->type == MMC_DEV_EMMC || mmc->type == MMC_DEV_SD || mmc->type == MMC_DEV_COMBO) { - MmcBlockDel(mmc); + MmcBlockUninit(mmc); } PlatformDeviceDel(&mmc->device); MmcCntlrPut(mmc->cntlr);