u-boot environment preset for sdcard mirror

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

u-boot environment preset for sdcard mirror

u-boot environment preset for sdcard mirror

In some cases, such as mass production or preparing a demo.

We need u-boot environment stored in demo sdcard mirror image. 

Here is a way:

HW:  i.MX8MP evk

SW:  LF_v5.15.52-2.1.0_images_IMX8MPEVK.zip

The idea is to use fw_setenv to set the sdcard mirror as the operation on a real emmc/sdcard.
Add test=ABCD in u-boot-initial-env for test purpose.
And use fw_printenv to check and use hexdump to double confirm it.
The uboot env is already written into sdcard mirror(imx-image-multimedia-imx8mpevk.wic).
All those operations are on the host x86/x64 PC.

 ./fw_setenv -c fw_env.config -f u-boot-initial-env
Environment WRONG, copy 0
Cannot read environment, using default

 ./fw_printenv -c fw_env.config
Environment OK, copy 0
 jh_root_dtb=imx8mp-evk-root.dtb
 loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${bsp_script};
 mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
arch=arm
baudrate=115200
......
......
......
splashimage=0x50000000
test=ABCD
usb_boot=usb start; if usb dev ${devnum}; then devtype=usb; run scan_dev_for_boot_part; fi
vendor=freescale

 
hexdump -s 0x400000 -n 2000 -C imx-image-multimedia-imx8mpevk.wic
            
00400000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

hexdump -s 0x400000 -n 10000 -C imx-image-multimedia-imx8mpevk.wic
00400000  5f a4 9b 97 20 6a 68 5f  72 6f 6f 74 5f 64 74 62  |_... jh_root_dtb|
00400010  3d 69 6d 78 38 6d 70 2d  65 76 6b 2d 72 6f 6f 74  |=imx8mp-evk-root|
00400020  2e 64 74 62 00 20 6c 6f  61 64 62 6f 6f 74 73 63  |.dtb. loadbootsc|
00400030  72 69 70 74 3d 66 61 74  6c 6f 61 64 20 6d 6d 63  |ript=fatload mmc|
00400040  20 24 7b 6d 6d 63 64 65  76 7d 3a 24 7b 6d 6d 63  | ${mmcdev}:${mmc|
00400050  70 61 72 74 7d 20 24 7b  6c 6f 61 64 61 64 64 72  |part} ${loadaddr|
00400060  7d 20 24 7b 62 73 70 5f  73 63 72 69 70 74 7d 3b  |} ${bsp_script};|
00400070  00 20 6d 6d 63 5f 62 6f  6f 74 3d 69 66 20 6d 6d  |. mmc_boot=if mm|
......
......
......
00401390  76 3d 31 00 73 6f 63 3d  69 6d 78 38 6d 00 73 70  |v=1.soc=imx8m.sp|
004013a0  6c 61 73 68 69 6d 61 67  65 3d 30 78 35 30 30 30  |lashimage=0x5000|
004013b0  30 30 30 30 00 74 65 73  74 3d 41 42 43 44 00 75  |0000.test=ABCD.u|
004013c0  73 62 5f 62 6f 6f 74 3d  75 73 62 20 73 74 61 72  |sb_boot=usb star|
004013d0  74 3b 20 69 66 20 75 73  62 20 64 65 76 20 24 7b  |t; if usb dev ${|
004013e0  64 65 76 6e 75 6d 7d 3b  20 74 68 65 6e 20 64 65  |devnum}; then de|

flash the sdcard mirror into i.MX8MP evk board emmc to check

uuu -b emmc_all imx-boot-imx8mp-lpddr4-evk-sd.bin-flash_evk  imx-image-multimedia-imx8mpevk.wic

 The first time boot, the enviroment is already there.

Untitled.png

 How to achieve that:

a. fw_setenv/fw_printenv:

https://github.com/sbabic/libubootenv.git

Note: Please do not use uboot fw_setenv/fw_printenv

Compile it on the host x86/x64 PC. It is used on host.

b. u-boot-initial-env

Under uboot, make u-boot-initial-env

Note: Yocto deploys u-boot-initial-env by default

c. fw_env.config 

imx-image-multimedia-imx8mpevk.wic 0x400000 0x4000

0x400000 0x4000 are from uboot-imx\configs\imx8mp_evk_defconfig

CONFIG_ENV_SIZE=0x4000
CONFIG_ENV_OFFSET=0x400000

Now, you can run 

./fw_setenv -c fw_env.config -f u-boot-initial-env
%3CLINGO-SUB%20id%3D%22lingo-sub-1702549%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Eu-boot%20environment%20preset%20for%20sdcard%20mirror%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1702549%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%0A%3CP%3EIn%20some%20cases%2C%20such%20as%20mass%20production%20or%20preparing%20a%20demo.%3C%2FP%3E%0A%3CP%3EWe%20need%20u-boot%20environment%20stored%20in%20demo%20sdcard%20mirror%20image.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20a%20way%3A%3C%2FP%3E%0A%3CP%3EHW%3A%26nbsp%3B%20i.MX8MP%20evk%3C%2FP%3E%0A%3CP%3ESW%3A%26nbsp%3B%26nbsp%3BLF_v5.15.52-2.1.0_images_IMX8MPEVK.zip%3C%2FP%3E%0A%3CP%3EThe%20idea%20is%20to%20use%20fw_setenv%20to%20set%20the%20sdcard%20mirror%20as%20the%20operation%20on%20a%20real%20emmc%2Fsdcard.%20%3CBR%20%2F%3EAdd%20test%3DABCD%20in%20u-boot-initial-env%20for%20test%20purpose.%20%3CBR%20%2F%3EAnd%20use%20fw_printenv%20to%20check%20and%20use%20hexdump%20to%20double%20confirm%20it.%3CBR%20%2F%3EThe%20uboot%20env%20is%20already%20written%20into%20sdcard%20mirror(imx-image-multimedia-imx8mpevk.wic).%20%3CBR%20%2F%3EAll%20those%20operations%20are%20on%20the%20host%20x86%2Fx64%20PC.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%20.%2Ffw_setenv%20-c%20fw_env.config%20-f%20u-boot-initial-env%0AEnvironment%20WRONG%2C%20copy%200%0ACannot%20read%20environment%2C%20using%20default%0A%0A%20.%2Ffw_printenv%20-c%20fw_env.config%0AEnvironment%20OK%2C%20copy%200%0A%20jh_root_dtb%3Dimx8mp-evk-root.dtb%0A%20loadbootscript%3Dfatload%20mmc%20%24%7Bmmcdev%7D%3A%24%7Bmmcpart%7D%20%24%7Bloadaddr%7D%20%24%7Bbsp_script%7D%3B%0A%20mmc_boot%3Dif%20mmc%20dev%20%24%7Bdevnum%7D%3B%20then%20devtype%3Dmmc%3B%20run%20scan_dev_for_boot_part%3B%20fi%0Aarch%3Darm%0Abaudrate%3D115200%0A......%0A......%0A......%0Asplashimage%3D0x50000000%0Atest%3DABCD%0Ausb_boot%3Dusb%20start%3B%20if%20usb%20dev%20%24%7Bdevnum%7D%3B%20then%20devtype%3Dusb%3B%20run%20scan_dev_for_boot_part%3B%20fi%0Avendor%3Dfreescale%0A%0A%20%0Ahexdump%20-s%200x400000%20-n%202000%20-C%20imx-image-multimedia-imx8mpevk.wic%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A00400000%20%2000%2000%2000%2000%2000%2000%2000%2000%20%2000%2000%2000%2000%2000%2000%2000%2000%20%20%7C................%7C%0A%0Ahexdump%20-s%200x400000%20-n%2010000%20-C%20imx-image-multimedia-imx8mpevk.wic%0A00400000%20%205f%20a4%209b%2097%2020%206a%2068%205f%20%2072%206f%206f%2074%205f%2064%2074%2062%20%20%7C_...%20jh_root_dtb%7C%0A00400010%20%203d%2069%206d%2078%2038%206d%2070%202d%20%2065%2076%206b%202d%2072%206f%206f%2074%20%20%7C%3Dimx8mp-evk-root%7C%0A00400020%20%202e%2064%2074%2062%2000%2020%206c%206f%20%2061%2064%2062%206f%206f%2074%2073%2063%20%20%7C.dtb.%20loadbootsc%7C%0A00400030%20%2072%2069%2070%2074%203d%2066%2061%2074%20%206c%206f%2061%2064%2020%206d%206d%2063%20%20%7Cript%3Dfatload%20mmc%7C%0A00400040%20%2020%2024%207b%206d%206d%2063%2064%2065%20%2076%207d%203a%2024%207b%206d%206d%2063%20%20%7C%20%24%7Bmmcdev%7D%3A%24%7Bmmc%7C%0A00400050%20%2070%2061%2072%2074%207d%2020%2024%207b%20%206c%206f%2061%2064%2061%2064%2064%2072%20%20%7Cpart%7D%20%24%7Bloadaddr%7C%0A00400060%20%207d%2020%2024%207b%2062%2073%2070%205f%20%2073%2063%2072%2069%2070%2074%207d%203b%20%20%7C%7D%20%24%7Bbsp_script%7D%3B%7C%0A00400070%20%2000%2020%206d%206d%2063%205f%2062%206f%20%206f%2074%203d%2069%2066%2020%206d%206d%20%20%7C.%20mmc_boot%3Dif%20mm%7C%0A......%0A......%0A......%0A00401390%20%2076%203d%2031%2000%2073%206f%2063%203d%20%2069%206d%2078%2038%206d%2000%2073%2070%20%20%7Cv%3D1.soc%3Dimx8m.sp%7C%0A004013a0%20%206c%2061%2073%2068%2069%206d%2061%2067%20%2065%203d%2030%2078%2035%2030%2030%2030%20%20%7Clashimage%3D0x5000%7C%0A004013b0%20%2030%2030%2030%2030%2000%2074%2065%2073%20%2074%203d%2041%2042%2043%2044%2000%2075%20%20%7C0000.test%3DABCD.u%7C%0A004013c0%20%2073%2062%205f%2062%206f%206f%2074%203d%20%2075%2073%2062%2020%2073%2074%2061%2072%20%20%7Csb_boot%3Dusb%20star%7C%0A004013d0%20%2074%203b%2020%2069%2066%2020%2075%2073%20%2062%2020%2064%2065%2076%2020%2024%207b%20%20%7Ct%3B%20if%20usb%20dev%20%24%7B%7C%0A004013e0%20%2064%2065%2076%206e%2075%206d%207d%203b%20%2020%2074%2068%2065%206e%2020%2064%2065%20%20%7Cdevnum%7D%3B%20then%20de%7C%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eflash%20the%20sdcard%20mirror%20into%20i.MX8MP%20evk%20board%20emmc%20to%20check%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Euuu%20-b%20emmc_all%20imx-boot-imx8mp-lpddr4-evk-sd.bin-flash_evk%20%20imx-image-multimedia-imx8mpevk.wic%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3CSPAN%3EThe%20first%20time%20boot%2C%20the%20enviroment%20is%20already%20there.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Untitled.png%22%20style%3D%22width%3A%20742px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Untitled.png%22%20style%3D%22width%3A%20742px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F235876iE5C6AA09388F02E7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Untitled.png%22%20alt%3D%22Untitled.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3CSPAN%3EHow%20to%20achieve%20that%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Ea.%20fw_setenv%2Ffw_printenv%3A%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%20style%3D%22padding-left%20%3A%2030px%3B%22%20style%3D%22padding-left%20%3A%2030px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsbabic%2Flibubootenv.git%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fsbabic%2Flibubootenv.git%3C%2FA%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%20style%3D%22padding-left%20%3A%2030px%3B%22%20style%3D%22padding-left%20%3A%2030px%3B%22%3ENote%3A%20Please%20do%20not%20use%20uboot%20fw_setenv%2Ffw_printenv%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%20style%3D%22padding-left%20%3A%2030px%3B%22%20style%3D%22padding-left%20%3A%2030px%3B%22%3ECompile%20it%20on%20the%20host%20x86%2Fx64%20PC.%20It%20is%20used%20on%20host.%3C%2FP%3E%0A%3CP%3Eb.%20u-boot-initial-env%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%20style%3D%22padding-left%20%3A%2030px%3B%22%20style%3D%22padding-left%20%3A%2030px%3B%22%3EUnder%20uboot%2C%20make%20u-boot-initial-env%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%20style%3D%22padding-left%20%3A%2030px%3B%22%20style%3D%22padding-left%20%3A%2030px%3B%22%3ENote%3A%20Yocto%20deploys%20u-boot-initial-env%20by%20default%3C%2FP%3E%0A%3CP%3Ec.%20fw_env.config%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eimx-image-multimedia-imx8mpevk.wic%200x400000%200x4000%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E0x400000%200x4000%20are%20from%20uboot-imx%5Cconfigs%5Cimx8mp_evk_defconfig%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ECONFIG_ENV_SIZE%3D0x4000%0ACONFIG_ENV_OFFSET%3D0x400000%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3ENow%2C%20you%20can%20run%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E.%2Ffw_setenv%20-c%20fw_env.config%20-f%20u-boot-initial-env%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1702549%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3Ei.MX%208%20Family%20%7C%20i.MX%208QuadMax%20(8QM)%20%7C%208QuadPlus%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX%208M%20%7C%20i.MX%208M%20Mini%20%7C%20i.MX%208M%20Nano%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6%20All%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6DL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6Dual%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6DualPlus%20%7C%206QuadPlus%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6Quad%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6S%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6SL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6SoloX%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX6UL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX7Dual%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX7Solo%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX7ULP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX8ULP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ELinux%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
0% helpful (0/2)
Version history
Last update:
‎08-09-2023 07:48 PM
Updated by: