本文主要介绍如何在 G9 上适配兆易创新型号为 GB25F128F 的 FLASH。
二、步骤
参考《9系列_EMMC_OSPI客制化指南_Rev1.0.pdf》
1、在路径 /buildsystem/rtos/lk_boot/exdev/norflash/spi_nor.c 中的 spi_nor_ids 结构体中添加如下成员。
{ .name = "gd25f", .flash_id = {0xc8, 0x43}, .read_proto = PROTO(SPINOR_OP_READ_1_1_4, SNOR_PROTO_1_1_4), .write_proto = PROTO(SPINOR_OP_PP_1_1_4, SNOR_PROTO_1_1_4), .erase_list = SNOR_0X20_4KB | SNOR_0X52_32KB | SNOR_0XD8_64KB, .read_dummy = 8, .status_dummy = 0, .page_size = 256, // .set_4byte_addr_mode = spi_nor_general_set_4byte_addr_mode, .quad_enable = giga_quad_enable, .enter_quad = giga_enter_quad, //.default_init = giga_default_init }, |
2、修改路径 /buildsystem/rtos/freertos_safetyos/res/g9x_octal_ouput_fast_read.json 代码
{ "tag":"0x53465301", "init_act_t": [ { "header": "(((1) << 6) | ((0) << 3) | ((0) << 0))", "command": 6, "addr": "0x0", "data0": 0, "data1": 0 } ],
"xfer_attr_t":{ "cmd": "0x0B", "cinst_type": 0, "caddr_type": 0, "cdata_type": 0, "caddr_size": 3, "cmode": 0, "cdummy_size": 8, "cflag": 0, "rsvd":[0,0,0,0,0,0,0,0] },
"ip_settings_t": { "flags":"0x01 << 3", "rx_delay":0, "tx_delay":0, "csda":0, "csdada":0, "cseot":0, "cssot":0, "min_rx_win":10, "rx_training_step":0, "ctrl_misc":"0x04", "rsvd":[0,0,0,0,0] }, "freq":3, "training_pattern":["0x5a","0xa5","0xf0","0x0f","0x0f","0xf0","0xa5","0x5a"] } |
修改以上两个步骤后,重新编译 make freertos,make lk,重新打包 make genpac,烧录出现以下错误:
gpt_partition_round 450 first_lba:114600 last_lba:131015
gpt_partition_round partition size error: first lba:114600 last_lba:32711!
ERROR:check_partition_table 554 patch nor flash ptb error! ret:3
经过追踪代码,可以知道是分区表大小和 flash 实际大小不匹配;
--- a/ab/ospi/normal_boot/ospi_g9.bpt +++ b/ab/ospi/normal_boot/ospi_g9.bpt @@ -1,6 +1,6 @@ { "settings": { - "disk_size": "65528 KiB", + "disk_size": "32760 KiB", "disk_alignment": "4096", "partitions_offset_begin": "0" }, @@ -113,7 +113,7 @@ { "ab": true, "label": "res", - "size": "24 MiB", + "size": "8 MiB", "guid": "auto", "type_guid": "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7" }, |
修改上面步骤后,重新编译打包,出现以下错误:
Fail to initialize spi nor flash
init storage fail!
cann't init partition device!
fail to load partition data!
追踪代码后发现,在启动阶段没有配置新的 FLASH ,需要配置。
4、配置新的 FLASH:在路径 /buildsystem/BareMetal_Suite/driver/spi_nor/spi_nor.c 的 spi_nor_ids 添加以下代码:
{ .name = "gd25f", .flash_id = {0xc8, 0x43}, .read_proto = PROTO(SPINOR_OP_READ_1_1_4, SNOR_PROTO_1_1_4), .write_proto = PROTO(SPINOR_OP_PP_1_1_4, SNOR_PROTO_1_1_4), .erase_proto = PROTO(SPINOR_OP_BE_4K, SNOR_PROTO_1_1_4), .read_dummy = 8, .status_dummy = 0, .page_size = 256, .sector_size = SPINOR_SECTOR_4K_SIZE, .set_4byte_addr_mode = spi_nor_general_set_4byte_addr_mode, .quad_enable = giga_quad_enable, // .enter_quad = giga_enter_quad, //.default_init = giga_default_init }, |
重新编译 make baremetal,重新打包 make genpac。
5、以上步骤完成后,成功烧录和启动,以下是启动 log,出现 an INVALID inactive slot slot! 主要是分区表没有设置 b 分区,可以正常使用。
octal dtr en: 0,dummy = 0, inst type = 0, proto = 0000
id0: 0xc8, id1: 0x43id2: 0x18flash size: 01000000
ospi phy training pass!
an INVALID inactive slot slot!
DDR Data Rate: 2133
run pfm irg mode
run PFM via irg mode
start pfm daemon service
三、参考文档
1、《9系列_EMMC_OSPI客制化指南_Rev1.0.pdf》
2、《SemiDrive_Memory支持列表_V01.00.pdf》
四、总结
以上步骤实现了在 G9 上适配新的 FLASH,如果想要适配其他的 FLASH,可以可以参考上述步骤。
接下来将会更新更多关于 SemiDrive G9 系列的文章,感兴趣的可以在评论区评论或者关注。
评论