fw_setenv not setting mmcroot value i.MX8MP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fw_setenv not setting mmcroot value i.MX8MP

2,476 Views
GrzesiakLu
Contributor II

Hi!
After recently styruggling with OFFSET and SIZE values for i.MX8MP  and then later with the WDOG_B signal assertion on each reset. I am now experiencing very weird behaviour when attempting to change the value of variable "mmcroot" responsible for pointing to the rootFS partition to be mounted.

When attempting to write to the U-boot environment from Linux, I am able to define extra variables and change such variables like "splashimage" and "bootdelay" and then see these changes via fw_printenv. 

 

root@edm-g-imx8mp:~# fw_printenv
baseboard=wb
baudrate=115200
board_name=EDM-G
board_rev=iMX8MP
boot_fit=no
bootcmd_mfg=run mfgtool_args;if iminfo ${initrd_addr}; then if test ${tee} = yes; then bootm ${tee_addr} ${initrd_addr} ${fdt_addr}; else bo
oti ${loadaddr} ${initrd_addr} ${fdt_addr}; fi; else echo "Run fastboot ..."; fastboot 0; fi;
bootscript=echo Running bootscript from mmc ...; source
console=ttymxc1,115200
emmc_dev=2
ethprime=eth1
fastboot_dev=mmc2
fdt_addr=0x43000000
fdt_buffer=8192
fdt_file=imx8mp-edm-g-wb.dtb
fdt_high=0xffffffffffffffff
fdtcontroladdr=fcbf78b8
image=Image
initrd_addr=0x43800000
initrd_high=0xffffffffffffffff
jh_clk=
jh_mmcboot=setenv fdt_file imx8mp-evk-root.dtb;setenv jh_clk clk_ignore_unused; if run loadimage; then run mmcboot; else run jh_netboot; fi; 
jh_netboot=setenv fdt_file imx8mp-evk-root.dtb; setenv jh_clk clk_ignore_unused; run netboot;
kboot=booti
loadaddr=0x40480000
loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};
loadfdt=echo Loading fdt_file ${fdt_file}...; fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}
loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}
loadoverlay=fdt addr ${fdt_addr} && fdt resize ${fdt_buffer}; setexpr fdtovaddr ${fdt_addr} + 0xF0000; for ov in ${dtoverlay}; do echo Overlaying ${ov}...; fatload mmc ${mmcdev}:${mmcpart} ${fdtovaddr} imx8mp-edm-g-${baseboard}-${ov}.dtbo && fdt apply ${fdtovaddr}; done
m7boot=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${m7image}; cp.b ${loadaddr} ${m7loadaddr} ${filesize}; dcache flush; bootaux ${m7loadaddr}
m7image=hello_world.bin
m7loadaddr=0x007E0000
mfgtool_args=setenv bootargs console=${console},${baudrate} rdinit=/linuxrc clk_ignore_unused
mmcargs=setenv bootargs ${jh_clk} console=${console} root=${mmcroot}
mmcautodetect=yes
mmcboot=echo Booting from mmc ...; run mmcargs; if test ${boot_fit} = yes || test ${boot_fit} = try; then bootm ${loadaddr}; else if run loadfdt; then run loadoverlay; booti ${loadaddr} - ${fdt_addr}; else echo WARN: Cannot load the DT; fi; fi;
mmcdev=2
mmcpart=1
nandfit_part=yes
netargs=setenv bootargs ${jh_clk} console=${console} root=/dev/nfs ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp
netboot=echo Booting from net ...; run netargs;  if test ${ip_dyn} = yes; then setenv get_cmd dhcp; else setenv get_cmd tftp; fi; ${get_cmd} ${loadaddr} ${image}; if test ${boot_fit} = yes || test ${boot_fit} = try; then bootm ${loadaddr}; else if ${get_cmd} ${fdt_addr} ${fdt_file}; then booti ${loadaddr} - ${fdt_addr}; else echo WARN: Cannot load the DT; fi; fi;
script=boot.scr
sd_dev=1
serial#=1b234800497c1a31
soc_type=imx8mp
splashimage=0x50000000
bootcmd=mmc dev ${mmcdev}; if run loadbootscript; then run bootscript; else if run loadimage; then run mmcboot; else run netboot; fi; fi;
bootdelay=2
mmcroot=/dev/mmcblk2p2 rootwait rw​
root@edm-g-imx8mp:~# fw_setenv CRAP 100
root@edm-g-imx8mp:~# fw_setenv bootdelay 10
root@edm-g-imx8mp:~# fw_setenv mmcroot /dev/mmcblk2p3 rootwait rw
root@edm-g-imx8mp:~# fw_printenv
CRAP=100
bootdelay=10
mmcroot=/dev/mmcblk2p3 rootwait rw

 


However although the changes to bootdelay happen imidiately after issuing reboot command from Linux the mmcroot variable refuses to have the same value as sat via fw_setenv.

 

U-Boot 2020.04-235350493ba888d2340e29b6ec942314f2792761+g235350493b (Jun 11 2021 - 07:21:49 +0000)

CPU:   i.MX8MP[8] rev1.1 1800 MHz (running at 1200 MHz)
CPU:   Commercial temperature grade (0C to 95C) at 42C
Reset cause: POR
Model: TechNexion EDM-G-IMX8MP
DRAM:  4 GiB
MMC:   FSL_SDHC: 1, FSL_SDHC: 2
Loading Environment from MMC... OK
Can't find cec device id=0x3c
[*]-Video Link 1probe video device failed, ret -2

        [0] lcd-controller@32e80000, video
        [1] mipi_dsi@32e60000, video_bridge
        [2] rm67191_panel, panel
probe video device failed, ret -2
In:    serial
Out:   serial
Err:   serial

 BuildInfo:
  - ATF f1d7187
  - U-Boot 2020.04-235350493ba888d2340e29b6ec942314f2792761+g235350493b

switch to partitions #0, OK
mmc2(part 0) is current device
flash target is MMC:2
Net:   No ethernet found.
Fastboot: Normal
Normal Boot
Hit any key to stop autoboot:  10               

u-boot=> printenv CRAP
CRAP=100
u-boot=> printenv bootdelay 
bootdelay=10
u-boot=> printenv mmcroot 
mmcroot=/dev/mmcblk2p2 rootwait rw

 

Here's trimmed output of fw_printenv after rebooting of the device.

 

root@edm-g-imx8mp:~# fw_printenv
bootcmd=mmc dev ${mmcdev}; if run loadbootscript; then run bootscript; else if run loadimage; then run mmcboot; else run netboot; fi; fi;
CRAP=100
bootdelay=10
mmcroot=/dev/mmcblk2p3 rootwait rw

 


I have tested and I am able to change that variable manually to mount two separate rootFS partitions when overriding the variable from U-boot. However as I am supposed to implement A/B partition Software Update I really need to be able to do so via script from Linux.

Can somebody enlighten me how to fix this issue?

0 Kudos
Reply
3 Replies

2,457 Views
GrzesiakLu
Contributor II

I found the solution. Due to the settings defined within edm-g-imx8mp_defconfig file my board does performs additional writes to the U-boot environment after said environment is read from RAW Flash memory. This is governed by the CONFIG_BOARD_LATE_INIT variable in defconfig file.

CONFIG_BOARD_LATE_INIT=y
CONFIG_BOARD_EARLY_INIT_F=y
CONFIG_SPL_BOARD_INIT=y

 What ends up happening is that board_r.c found in /git/common directory calls board_late_init() function of edm-g-imx8mp.c file found in git/board/technexion directory, which further calls board_late_mmc_env_init() defined in the same file. This call performs to writes to the U-boot environment AFTER it was initialized and read via initr_env of board_r.c file (I believe). One of the calls is to put the /dev/mmcblk2p2 as the rootFS partition independent of the values written to it previously via fw_setenv mmcroot /dev/mmcblk2p3 rootwait rw. This explains the behaviour where some variables would retain their values while this one was always sat to default. The problematic code is shown below and can be found on line 380 in edm-g-imx8mp.c file

void board_late_mmc_env_init(void)
{
	char cmd[32];
//	char mmcblk[32];
	u32 dev_no = mmc_get_env_dev();

	if (!check_mmc_autodetect())
		return;

	env_set_ulong("mmcdev", dev_no);

	/* Set mmcblk env */
	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
		mmc_map_to_kernel_blk(dev_no));
	env_set("mmcroot", mmcblk);

	sprintf(cmd, "mmc dev %d", dev_no);
	run_command(cmd, 0);
}
0 Kudos
Reply

2,127 Views
DungTA98
Contributor II

Hi, 

I''m facing the same problem. I read your solution.
I'm using the yocto project to build the image so I don't want to modify the defconfig file and rebuild. 
Do you have any solution for me?

Best regards,
Dung Tran Anh

0 Kudos
Reply

2,121 Views
GrzesiakLu
Contributor II

Hi!

As the solution I propose worked and didn't impact other aspects of the boot sequence, I haven't researched other approaches.

I believe the while function is i cluded in the code snippet so as you can see it isn't an awful amount of code you comment out.

 

I would remove/comme t our the problematic function and apply the change as a patch to u-boot recipe.

 

Best regards.

Lukasz

0 Kudos
Reply