X9M 芯片烧录及启动问题分析

一、概述

刚好最近客户做好的板子遇到了无法烧录的问题,现以此问题作为例子来对 X9M 芯片烧录及启动的问题进行分析。

板子使用的主控是 X9M 芯片,DDR 使用的是 LPDDR4 MT53X,Flash 用的是 GD25X,我们首先对核心板上的供电、时钟及复位进行测试,确保硬件上的功能正常后,再将启动模式切换到了下图所示的 USB Boot。

 

二、烧录问题分析

使用原厂提供的烧录工具 SDFactory 进行烧录,出现如下报错:

 

连接串口可以查看到如下错误信息: 

get hwid timeout, will use the dummy one?

version:

arch: ARM

platform: KUNLUN

target: REFERENCE_X9

project: DEFAULT

buildid: X9_PTG3_8_RC5:K71FQ_LOCAL

] change ddr state to 6

DDR init //打印目录 lk/lk_customize/application/system/spl/spl.c

DDR Sequence Version: 0x00010005

dwc_ddrphy_fw_monitor_loop: Opps: DDR Training Failed.

Opps, DDR initialization failed

get_vid_pid vid:0x3273 pid:0x1

get_serialno serial:121b36353853300f

linksts change

U0

linksts change

U5

linksts change

U3

get dev evt usb reset on ep:0, in: 0

conndone

linksts change

U0

usb online

fastboot: processing commands


从以上错误信息可以看到主要是 DDR initialization failed,由于更换了 DDR 及 Flash,相关的烧录引导配置及启动配置都需要做更改,方法如下:

① 修改 lunch_config 目录下的软件配置文件 X9M_RefA03_Isolation_Serdes_8G_3200, lk 和 baremetal 的编译选项可以修改内存大小和内存运行频率,将 DDR_SIZE 改为 4G,DDR_FW 和 DDR_TYPE 改为 lpddr4:

{

"name":"-emmc",

"platform":"X9MREF",

"soc":"X9M",

"board":"RefA03",

"swconf":"Isolation",

"description":"X9M With FreeRTOS Cluster,Enable FastAVM, Serdes Display with 8G DDR based on X9 Ref A03 Board",

"verified_boot":"false",

"build-repo":[

{

"name":"lk",

"branch":"master",

"need-sync":1,

"projects":[

{

"project-name":"spl_x9m_ref_serdes",

"make-config":"DDR_FREQ=3200 DDR_SIZE=4G",

"need-build":1

},

{

"project-name":"ssystem_x9m_ref_serdes",

"make-config":"",

"need-build":1

},

{

"project-name":"dloader_x9m_ref_serdes",

"make-config":"",

"need-build":1

},

{

"project-name":"preloader_x9m_ref_serdes",

"make-config":"",

"need-build":1

},

{

"project-name":"bootloader_x9m_ref_serdes",

"make-config":"DDR_SIZE=4G",

"need-build":1

}

]

},

{

"name":"freertos",

"branch":"master",

"branch2":"lk_freertos",

"need-sync":1,

"projects":[

{

"project-name":"safety-x9m-ref-serdes",

"make-config":" ENABLE_BOOT_ANIMATION=true ENABLE_FASTAVM=true ",

"need-build":1

},

{

"project-name":"ospi_handover-x9m-ms",

"make-config":"",

"need-build":1

}

]

},

{

"name":"android",

"branch":"semidrive_x9_develope",

"need-sync":1,

"projects":[

{

"project-name":"android",

"make-config":"",

"lunch-name":"x9m_ref-userdebug",

"dts":"x9_mid_ref_native_ivi_serdes_avm",

"need-build":1

}

]

},

{

"name":"atf",

"branch":"master",

"need-sync":1,

"projects":[

{

"project-name":"atf",

"make-config":"ATF_BOARD=X9_REF CHIPVERSION=x9_mid PROJECT=serdes",

"need-build":1

}

]

},

{

"name":"baremetal",

"branch":"master",

"need-sync":1,

"projects":[

{

"project-name":"dil",

"make-config":"BOARD=x9_mid_ref CFG=t_loader DDR_FW=lpddr4 DDR_TYPE=lpddr4 DDR_SIZE=4GB DDR_FREQ=3200",

"need-build":1

},

{

"project-name":"dil2",

"make-config":"BOARD=x9_mid_ref CFG=t_loader DIL2=1",

"need-build":1

}

]

}



],

"gen-pac":{

"need-gen":1,

"system_config":"generate/x9_mid/projects/serdes/system_config.bin",

"dts":"x9_mid_ref_native_ivi_serdes_avm",

"safety-res":"BootAnimation cluster controlpanel fastavm audio"

}

}


② 新增一个内存训练脚本,需要在 LK 和 BareMetal_Suite 里同时添加。LK 中内存训练脚本是下载模式下使用,BareMetal_Suite 中内存训练脚本是启动时使用。改动如下:

1)lk/lk_customize/project/dloader_x9m_ref_serdes.mk

diff --git a/project/dloader_x9m_ref_serdes.mk b/project/dloader_x9m_ref_serdes.mk

index 71b5b63..b9da0c7 100755

--- a/project/dloader_x9m_ref_serdes.mk

+++ b/project/dloader_x9m_ref_serdes.mk

@@ -28,7 +28,8 @@ SUPPORT_CLKGEN_SDDRV := true

SUPPORT_FUSE_CTRL := true



#for mt35x nor flash, rom needs to reset ospi before reading it

-NORFLASH_DEVICE_TYPE := mt35x

+#NORFLASH_DEVICE_TYPE := mt35x

+NORFLASH_DEVICE_TYPE := gd25x

TOGGLE_OSPI_RESET_ENABLE := true



include $(LOCAL_DIR)/../project/common/dloader.mk

 

2)lk/lk_customize/project/spl_x9m_ref_serdes.mk

diff --git a/project/spl_x9m_ref_serdes.mk b/project/spl_x9m_ref_serdes.mk

index 246db2c..a3c644a 100644

--- a/project/spl_x9m_ref_serdes.mk

+++ b/project/spl_x9m_ref_serdes.mk

@@ -30,5 +30,6 @@ NEED_CHANGE_VOLTAGE := true

SUPPORT_FUSE_CTRL :=true

DDR_FREQ := 3200



+LPDDR4 :=true



include $(LOCAL_DIR)/../project/common/spl.mk

 

3)lk/lk_customize/target/reference_x9/secure/ddr_init.c

diff --git a/reference_x9/secure/ddr_init.c b/reference_x9/secure/ddr_init.c

index cb07516..d11980e 100644

--- a/reference_x9/secure/ddr_init.c

+++ b/reference_x9/secure/ddr_init.c


@@ -49,6 +49,7 @@ const uint32_t ddr_init_seq_sz_max = sizeof(ddr_init_seq);

#endif

uint32_t ddr_init(void)

{



#if defined(SAF_CORE)

setup_scr(scr_safETY__RW__ddr_ss_pwrokin_aon,0x1);

#else

@@ -56,6 +57,7 @@ uint32_t ddr_init(void)

#endif



#if CFG_PARSE_RUN_DDR_INIT_SEQ



if (0 != run_ddr_init_seq(&ddr_init_seq[0])) {

return -1;

}

@@ -91,6 +93,10 @@ uint32_t ddr_init(void)

#include "ddr_init_script/lpddr4/ddr_init_lpddr4_8GB_3200.c"

#elif DDR_3G_4266

#include "ddr_init_script/lpddr4/ddr_init_lpddr4_3GB_4266.c"

+#elif DDR_4G_4266

+#include "ddr_init_script/lpddr4/ddr_init_lpddr4_4GB_4266.c"

+#elif DDR_4G_3200

+#include "ddr_init_script/lpddr4/ddr_init_lpddr4_4GB_3200.c"

#elif DDR_3G_3200

#include "ddr_init_script/lpddr4/ddr_init_lpddr4_3GB_3200.c"

#else

 

4)在 lk/lk_customize/target/reference_x9/secure/ddr_init_script/lpddr4 和在  BareMetal_Suite/board/x9_mid_ref/ddr_init_script/lpddr4 目录下都添加内存训练脚本文件:

ddr_init_lpddr4_3200.c & ddr_init_lpddr4_4266.c

 

完成以上修改后,重新编译 lk 和 baremetal 即可,将编译生成的 FDA.img、OPSIDA.img、DLOADER.img 替换掉

 

重新执行烧录,可以看到烧录成功

 

三、启动问题分析

镜像烧录完成后,切换启动模式为 OSPI 启动(0000),连接好串口后,接通电源。此时发现串口没有任何输出,供电也都正常,查看 GD25X 芯片手册后发现,GD25X 是 QSPI 只支持到四线模式,我们还需要根据使用的 FLASH 芯片修改 FLASH 的启动配置表。



这里的配置表是指的 sfs,sfs 是根据 meta-semidrive/script 下的 mt35_octal_ouput_fast_read.json 编出来的,路径如下:buildsystem-x9-ptg3.8/yocto/meta-semidrive/scripts/x9m_ref_serdes/mt35_octal_ouput_fast_read.json 。可以看到有如下的属性配置

"xfer_attr_t":{

"cmd": "0x0B",

"cinst_type": 3,

"caddr_type": 3,

"cdata_type": 3,

"caddr_size": 4,

"cmode": 0,

"cdummy_size": 16,

"cflag": "(0x01 << 2)|(0x01 << 1)",

"rsvd":[0,0,0,0,0,0,0,0]

},

 

我们需要参考 buildsystem-x9-ptg3.8/yocto/meta-semidrive/scripts/bf200/gd25_lb256e_low 进行修改,对应需要改为如下内容:

"xfer_attr_t": {

"cmd": "0x6c",

"cinst_type": 0,

"caddr_type": 0,

"cdata_type": 2,

"caddr_size": 4,

"cmode": 0,

"cdummy_size": 8,

"cflag": 0,

"rsvd": [0, 0, 0, 0, 0, 0, 0, 0]

},

 

这里面所对应的命令及参数解释如下:

"xfer_attr_t_comments": {

"des": "Read XFER Configuration",

"size": "16 bytes",

"cmd": {

"des": "The command code for read",

"size": "1byte"

},

"cinst_type": {

"des": "IO type of CMD",

"size": "1byte, below is valid data",

"0": "Single IO",

"1": "Dual IO",

"2": "Quad IO",

"3": "Octal IO"

},

"caddr_type": {

"des": "IO type of Adress",

"size": "1byte, below is valid data",

"0": "Single IO",

"1": "Dual IO",

"2": "Quad IO",

"3": "Octal IO"

},

"cdata_type": {

"des": "IO type of Data",

"size": "1byte, below is valid data",

"0": "Single IO",

"1": "Dual IO",

"2": "Quad IO",

"3": "Octal IO"

},

"caddr_size": {

"des": "Address sizea",

"size": "1byte, below is valid data",

"3": "3bytes addressing",

"4": "4bytes addressing"

},

"cmode": {

"des": "Mode, The Mode value to be sent, Valid only if MODE_VALID set in Flag",

"size": "1byte"

},

"cdummy_size": {

"des": "Dummy size, The number of the dummy cycles",

"size": "1byte"

},

"cflag": {

"des": "Flag",

"size": "1byte, below is valid defined",

"Bit0": "DDR, indicating this read xfer is in DDR mode",

"Bit1": "DQS, indicating this read xfer shall use DQS",

"Bit2": "DTR, indicating this read xfer is in DTR(Double Data Rate) protocol",

"Bit3": "DUAL_OPCODE_INV",

"Bit4": "Data Flip",

"Bit5": "MODE_VALID",

"Bit6": "ECC_EN,For safety ROM only,If set, Rom code setup ECC_FAIL pad and enbale ECC_FAIL IRQ",

"Bit7": "CRC_EN,For safety ROM only,If set, Rom code enables CRC feature of OSPI controller and also enable RX_CRC_MASK_IRQ"

},

"rsvd": {

"des": "Reserved",

"size": "8bytes, Shall be 0"

}

},

 

如下图为 GD25X 芯片手册介绍的相关 Command,Code 的值就对应着代码中 "cmd" 的值,Command-Address-Data 就分别对应着 "cinst_type"、"caddr_type"、"cdata_type",Dummy Clock Cycles 即为 "cdummy_size",Address Bytes 即为 "caddr_size"

 

 

这里配置了 cmd = 0x6c,即为 4-Byte Quad Output Fast Read,说明如下,

 

完成 FLASH 配置文件的修改后,执行如下命令,在当前目录下生成 sfs 配置文件:

python ./gen_sfs_binary.py --json ./x9m_ref_serdes/mt35_octal_ouput_fast_read.json --out ./sfs.img

 

将生成的 sfs 配置表通过烧录软件单独烧录进板子后,可以看到启动 log 正常输出。

 


以上步骤便解决了 X9M 芯片烧录及启动失败的问题。 

四、参考文献

《gd25lb512me-datasheet_v1.1》

《SD_X9_SDK_User_Manual》

《SemiDrive_9Series_Boot》

★博文内容均由个人提供,与平台无关,如有违法或侵权,请与网站管理员联系。

★文明上网,请理性发言。内容一周内被举报5次,发文人进小黑屋喔~

评论