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 #include "diskio.h" 20 21 #define CFIFLASH_ONE_BANK_BITS 24 22 23 #define CFIFLASH_SEC_SIZE 512 24 #define CFIFLASH_SEC_SIZE_BITS 9 25 #define CFIFLASH_SECTORS (CFIFLASH_CAPACITY / CFIFLASH_SEC_SIZE) 26 27 #define CFIFLASH_PAGE_SIZE (2048 * 2) /* fit QEMU of 2 banks */ 28 #define CFIFLASH_PAGE_WORDS (CFIFLASH_PAGE_SIZE / sizeof(uint32_t)) 29 #define CFIFLASH_PAGE_WORDS_MASK (CFIFLASH_PAGE_WORDS - 1) 30 31 #define CFIFLASH_QUERY_CMD 0x98 32 #define CFIFLASH_QUERY_BASE 0x55 33 #define CFIFLASH_QUERY_QRY 0x10 34 #define CFIFLASH_QUERY_VENDOR 0x13 35 #define CFIFLASH_QUERY_SIZE 0x27 36 #define CFIFLASH_QUERY_PAGE_BITS 0x2A 37 #define CFIFLASH_QUERY_ERASE_REGION 0x2C 38 #define CFIFLASH_QUERY_BLOCKS 0x2D 39 #define CFIFLASH_QUERY_BLOCK_SIZE 0x2F 40 #define CFIFLASH_EXPECT_VENDOR 1 /* Intel command set */ 41 #define CFIFLASH_EXPECT_PAGE_BITS 11 42 #define CFIFLASH_EXPECT_BLOCKS 127 /* plus 1: # of blocks, arm_virt is 255, riscv32 is 127 */ 43 #define CFIFLASH_EXPECT_BLOCK_SIZE 512 /* times 128: block size */ 44 #define CFIFLASH_EXPECT_ERASE_REGION 1 45 46 #define CFIFLASH_CMD_ERASE 0x20 47 #define CFIFLASH_CMD_CLEAR_STATUS 0x50 48 #define CFIFLASH_CMD_READ_STATUS 0x70 49 #define CFIFLASH_CMD_CONFIRM 0xD0 50 #define CFIFLASH_CMD_BUFWRITE 0xE8 51 #define CFIFLASH_CMD_RESET 0xFF 52 53 #define CFIFLASH_STATUS_READY_MASK 0x80 54 55 DSTATUS DiskInit(BYTE); 56 DSTATUS DiskStatus(BYTE); 57 DSTATUS DisckRead(BYTE, BYTE *, DWORD, UINT); 58 DSTATUS DiskWrite(BYTE, const BYTE *, DWORD, UINT); 59 DSTATUS DiskIoctl(BYTE, BYTE, void *); 60 61 #endif 62