1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __CFIFLASH_INTERNAL_H__ 16 #define __CFIFLASH_INTERNAL_H__ 17 18 #include "cfiflash.h" 19 20 #define HDF_LOG_TAG cfi_flash_driver 21 22 #define CFIFLASH_ONE_BANK_BITS 25 23 24 #define CFIFLASH_SEC_SIZE 512 25 #define CFIFLASH_SEC_SIZE_BITS 9 26 #define CFIFLASH_SECTORS (CFIFLASH_CAPACITY / CFIFLASH_SEC_SIZE) 27 28 #define CFIFLASH_PAGE_SIZE (2048 * 2) /* fit QEMU of 2 banks */ 29 #define CFIFLASH_PAGE_WORDS (CFIFLASH_PAGE_SIZE / sizeof(uint32_t)) 30 #define CFIFLASH_PAGE_WORDS_MASK (CFIFLASH_PAGE_WORDS - 1) 31 32 #define CFIFLASH_QUERY_CMD 0x98 33 #define CFIFLASH_QUERY_BASE 0x55 34 #define CFIFLASH_QUERY_QRY 0x10 35 #define CFIFLASH_QUERY_VENDOR 0x13 36 #define CFIFLASH_QUERY_SIZE 0x27 37 #define CFIFLASH_QUERY_PAGE_BITS 0x2A 38 #define CFIFLASH_QUERY_ERASE_REGION 0x2C 39 #define CFIFLASH_QUERY_BLOCKS 0x2D 40 #define CFIFLASH_QUERY_BLOCK_SIZE 0x2F 41 #define CFIFLASH_EXPECT_VENDOR 1 /* Intel command set */ 42 #define CFIFLASH_EXPECT_PAGE_BITS 11 43 #define CFIFLASH_EXPECT_BLOCKS 255 /* plus 1: # of blocks */ 44 #define CFIFLASH_EXPECT_BLOCK_SIZE 512 /* times 256: block size */ 45 #define CFIFLASH_EXPECT_ERASE_REGION 1 46 47 #define CFIFLASH_CMD_ERASE 0x20 48 #define CFIFLASH_CMD_CLEAR_STATUS 0x50 49 #define CFIFLASH_CMD_READ_STATUS 0x70 50 #define CFIFLASH_CMD_CONFIRM 0xD0 51 #define CFIFLASH_CMD_BUFWRITE 0xE8 52 #define CFIFLASH_CMD_RESET 0xFF 53 54 #define CFIFLASH_STATUS_READY_MASK 0x80 55 56 int CfiFlashInit(uint8_t *p); 57 int CfiBlkOpen(struct Vnode *vnode); 58 int CfiBlkClose(struct Vnode *vnode); 59 ssize_t CfiBlkRead(struct Vnode *vnode, unsigned char *buffer, 60 unsigned long long start_sector, unsigned int nsectors); 61 ssize_t CfiBlkWrite(struct Vnode *vnode, const unsigned char *buffer, 62 unsigned long long start_sector, unsigned int nsectors); 63 int CfiBlkGeometry(struct Vnode *vnode, struct geometry *geometry); 64 65 int CfiMtdErase(struct MtdDev *mtd, UINT64 start, UINT64 bytes, UINT64 *failAddr); 66 int CfiMtdRead(struct MtdDev *mtd, UINT64 start, UINT64 bytes, const char *buf); 67 int CfiMtdWrite(struct MtdDev *mtd, UINT64 start, UINT64 bytes, const char *buf); 68 69 #endif 70