DDR在DTS中配置mem=256Mb导致mem报错解决DDR大小识别错误
一、问题描述
通过DTS文件配置DDR大小,发现在DTS中配置DDR为256Mb编译出来的固件,在DDR为128Mb的硬件中固件启动之后会造成mem报错,导致系统重启。
二、解决方法
通过查看linux kernel中arch/mips/ralink/of.c文件的plat_mem_setup()函数,发现如果DTS文件中没有配置DDR大小,系统则会自动识别DDR大小
void __init plat_mem_setup(void) { void *dtb = NULL; set_io_port_base(KSEG1); /* * Load the builtin devicetree. This causes the chosen node to be * parsed resulting in our memory appearing. fw_passed_dtb is used * by CONFIG_MIPS_APPENDED_RAW_DTB as well. */ if (fw_passed_dtb) dtb = (void *)fw_passed_dtb; else if (__dtb_start != __dtb_end) dtb = (void *)__dtb_start; __dt_setup_arch(dtb); strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE); of_scan_flat_dt(early_init_dt_find_memory, NULL); if (memory_dtb) of_scan_flat_dt(early_init_dt_scan_memory, NULL); else if (soc_info.mem_detect) soc_info.mem_detect(); else if (soc_info.mem_size) add_memory_region(soc_info.mem_base, soc_info.mem_size * SZ_1M, BOOT_MEM_RAM); else detect_memory_region(soc_info.mem_base, soc_info.mem_size_min * SZ_1M, soc_info.mem_size_max * SZ_1M); }
所以在DTS中将mem的配置节点删除,重新编译固件,固件就可以实现DDR自适应
@@ -13,11 +13,6 @@ led-upgrade = &led_run; }; - memory@0 { - device_type = "memory"; - reg = <0x0 0x8000000>; - }; - chosen { bootargs = "console=ttyS0,115200"; };
三、使用uboot bootargs传参
OpenWRT1907默认关闭了uboot传参,并给kernel cmdline设了一个固定值,make kernel_menuconfig选上MIPS_CMDLINE_FROM_BOOTLOADER
Symbol: MIPS_CMDLINE_FROM_BOOTLOADER [=y] │ │ Type : boolean │ │ Prompt: Bootloader kernel arguments if available │ │ Location: │ │ -> Kernel type │ │ (1) -> Kernel command line type (<choice> [=y]) │ │ Defined at arch/mips/Kconfig:2993 │ │ Depends on: <choice>
再通过修改arch/mips/ralink/of.c文件将strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE)屏蔽,这样kernel就会默认从uboot的bootargs中获取参数,重新编译固件
__dt_setup_arch(dtb); - strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE); + //strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE); of_scan_flat_dt(early_init_dt_find_memory, NULL); if (memory_dtb) of_scan_flat_dt(early_init_dt_scan_memory, NULL);
uboot在bootargs中设置mem=128m(这里只设置mem,还有其他参数根据实际情况设置)
MT7621 # setenv bootargs mem=128m MT7621 # saveenv Saving Environment to SPI Flash... Erasing SPI Flash... . Writing to SPI Flash... . done MT7621 # printenv bootcmd=tftp bootdelay=7 baudrate=115200 ethaddr="00:AA:BB:CC:DD:10" ipaddr=192.168.1.1 serverip=192.168.1.2 uboot_name=uboot-gl-mt1300.bin firmware_name=openwrt-gl-mt1300.bin lc=if ping $serverip; then tftp 0x81000000 config.bin && cp.b 0xbc40000 0x81100000 0xffff && cp 0x81000000 0x81100000 0x40 && cp.b 0x81000000 0x81101002 0x06 && erase 0xbc040000 +0xffff && cp 0x81000000 0xbc040000 0xffff; fi lu=if ping $serverip; then tftp 0x81000000 $uboot_name && erase 0xbc000000 +0x40000 && cp $fileaddr 0xbc000000 $filesize && echo OK!; else echo ERROR! Server not reachable!; fi lf=if ping $serverip; then tftp 0x81000000 $firmware_name && erase 0xbc050000 +$filesize && cp $fileaddr 0xbc050000 $filesize && echo OK!; else echo ERROR! Server not reachable!; fi BootType=3 aaa=bbb stdin=serial stdout=serial stderr=serial bootargs=mem=128m Environment size: 838/4092 bytes MT7621 # reset
kernel启动日志:
[ 0.000000] Linux version 4.14.171 (deng@ubuntu) (gcc version 7.5.0 (OpenWrt GCC 7.5.0 r10947-65030d81f3)) #0 SMP Thu Feb 27 21:05:12 2020 [ 0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3 [ 0.000000] bootconsole [early0] enabled [ 0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc) [ 0.000000] MIPS: machine is GL-MT1300 [ 0.000000] Determined physical RAM map: [ 0.000000] memory: 10000000 @ 00000000 (usable) #DTS设置DDR为256Mb [ 0.000000] User-defined physical RAM map: [ 0.000000] memory: 08000000 @ 00000000 (usable) #通过获取bootargs参数修改DDR为128Mb [ 0.000000] Initrd not found or empty - disabling initrd [ 0.000000] VPE topology {2,2} total 4 [ 0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes. [ 0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes [ 0.000000] MIPS secondary cache 256kB, 8-way, linesize 32 bytes. [ 0.000000] Zone ranges: [ 0.000000] Normal [mem 0x0000000000000000-0x0000000007ffffff] [ 0.000000] HighMem empty [ 0.000000] Movable zone start for each node [ 0.000000] Early memory node ranges [ 0.000000] node 0: [mem 0x0000000000000000-0x0000000007ffffff] [ 0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff] [ 0.000000] random: get_random_bytes called from start_kernel+0x94/0x4a8 with crng_init=0 [ 0.000000] percpu: Embedded 14 pages/cpu s26192 r8192 d22960 u57344 [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 32512 [ 0.000000] Kernel command line: console=ttyS0,115200 mem=128m rootfstype=squashfs,jffs2 #kernel cmdline发现mem=128m传参成功
这样也可以解决DDR大小识别错误问题
点击链接加入群聊三群:751529538
点击链接加入群聊二群:376877156
点击链接加入群聊【路由器交流群:622891808已满】
本站附件分享,如果附件失效,可以去找找看
饿了么红包
于2022-10-22发布