How to Load initramfs from SD Card (Single FAT32 Boot Partition)

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

How to Load initramfs from SD Card (Single FAT32 Boot Partition)

165 Views
Sunil_13
Contributor I

Hi,

I am working on  i.MX8M Plus EVK board and would like to boot Linux using initramfs as the root filesystem, loaded directly from an SD card boot partition only(FAT32). 

The SD card does not contain a separate root filesystem partition.

Current Setup

  • SD card contains only one FAT32 boot partition

  • Files present on the FAT32 partition:

    • Image(U-boot+kernel)

    • Device Tree Blob (.dtb)

    • initramfs image

Questions

  1. initramfs Generation

    • What is the recommended method to generate an initramfs image?

    • Should initramfs be built into the kernel or loaded as a separate image?

    • How can initramfs be loaded from the SD card (FAT32 partition) using U-Boot?
  2. U-Boot Environment Commands

    • What are the U-Boot commands or environment variables needed to Load the kernel, device tree, and initramfs from SD.

 

0 Kudos
Reply
2 Replies

88 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi,

 

What is the recommended method to generate an initramfs image?

--> You can build it with bitbake core-image-minimal-initramfs in Yocto.

Should initramfs be built into the kernel or loaded as a separate image?

--> It depends on your needs.

How can initramfs be loaded from the SD card (FAT32 partition) using U-Boot?
-->Here is example:

# If mmc0 is your sd card.
setenv bootargs console=ttymxc0,115200 root=/dev/ram rw
fatload mmc 0:1 ${loadaddr} Image
fatload mmc 0:1 ${fdt_addr} imx8mp-evk.dtb
fatload mmc 0:1 ${ramdisk_addr} xxxx_initramfs.cpio.gz
booti ${loadaddr} ${ramdisk_addr}:${filesize} ${fdt_addr}

You can refer board/beacon/imx8mn/imx8mn_beacon.env

boot_fdt=try
bootdelay=2
bootscript=echo Running bootscript from mmc ...; source
console=ttymxc1
fdt_addr=0x45000000
fdt_file=imx8mn-beacon-kit.dtb
finduuid=part uuid mmc ${mmcdev}:2 uuid
image=Image
initrd_addr=0x46000000
loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};
loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}
loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}
loadramdisk=load mmc ${mmcdev} ${ramdisk_addr} ${ramdiskimage}
mmcargs=setenv bootargs console=${console},${baudrate}  root=PARTUUID=${uuid} rootwait rw ${mtdparts} ${optargs}
mmcautodetect=yes
mmcboot=echo Booting from mmc ...; run finduuid; run mmcargs; if test ${boot_fdt} = yes || test ${boot_fdt} = try; then if run loadfdt; then booti ${loadaddr} - ${fdt_addr}; else echo WARN: Cannot load the DT; fi; else echo wait for boot; fi;
mmcdev=1
mmcpart=1
netargs=setenv bootargs console=${console},${baudrate}  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_fdt} = yes || test ${boot_fdt} = try; then if ${get_cmd} ${fdt_addr} ${fdt_file}; then booti ${loadaddr} - ${fdt_addr}; else echo WARN: Cannot load the DT; fi; else booti; fi;
ramargs=setenv bootargs console=${console},${baudrate}  root=/dev/ram rw  ${optargs}
ramboot=echo Booting from RAMdisk...; run loadimage; run loadfdt; fdt addr $fdt_addr; run loadramdisk; run ramargs; booti ${loadaddr} ${ramdisk_addr} ${fdt_addr} ${optargs}
ramdisk_addr=0x46000000
ramdiskimage=rootfs.cpio.uboot
script=boot.scr



Best Regards,
Zhiming

0 Kudos
Reply

64 Views
Sunil_13
Contributor I

Hi @Zhiming_Liu ,

 

As per your guidance, I followed the procedure you shared.
I am able to successfully load the kernel Image and DTB, but the initramfs (cpio.gz) root filesystem is not being loaded by the kernel.

Below are the exact U-Boot commands and behavior.

U-Boot Commands Used

u-boot=> setenv bootargs console=ttymxc1,115200 root=/dev/ram rw
u-boot=> fatload mmc 1:1 ${loadaddr} Image_copy.gz 13450466 bytes read in 282 ms (45.5 MiB/s)
u-boot=> fatload mmc 1:1 ${fdt_addr} imx8mp-evk.dtb 82784 bytes read in 4 ms (19.7 MiB/s)
u-boot=> fatload mmc 1:1 ${ramdisk_addr_r} core-image-minimal-initramfs-imx8mp-ddr4-evk.cpio.gz 12602736 bytes read in 264 ms (45.5 MiB/s)
u-boot=> booti ${loadaddr} ${ramdisk_addr_r}:${filesize} ${fdt_addr}
 

After executing the booti command, the kernel starts booting, but it does not mount or use the initramfs (cpio.gz) as root filesystem.

I have attached the full kernel boot log for reference.

Questions

  1. What could be the possible reasons for the kernel not loading the initramfs (cpio.gz) even though it is correctly loaded into memory by U-Boot?

  2. Are there any mandatory kernel configuration options required for initramfs support that I should verify?

  3. Is the bootargs configuration correct for booting with initramfs on i.MX8M Plus, or are additional parameters required?

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2259345%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHow%20to%20Load%20initramfs%20from%20SD%20Card%20(Single%20FAT32%20Boot%20Partition)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2259345%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20am%20working%20on%20%3CSTRONG%3E%26nbsp%3Bi.MX8M%20Plus%20EVK%26nbsp%3B%3C%2FSTRONG%3Eboard%20and%20would%20like%20to%20boot%20Linux%20using%20%3CSTRONG%3Einitramfs%20%3C%2FSTRONG%3Eas%20the%20root%20filesystem%2C%20loaded%20directly%20from%20an%20%3CSTRONG%3ESD%20card%20%3C%2FSTRONG%3Eboot%20partition%20only(FAT32).%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20SD%20card%20does%20%3CSTRONG%3Enot%3C%2FSTRONG%3E%20contain%20a%20separate%20root%20filesystem%20partition.%3C%2FP%3E%3CH3%20id%3D%22toc-hId-2002571121%22%20id%3D%22toc-hId-2003223638%22%20id%3D%22toc-hId-2003223638%22%20id%3D%22toc-hId-2003223638%22%3ECurrent%20Setup%3C%2FH3%3E%3CUL%3E%3CLI%3E%3CP%3ESD%20card%20contains%20%3CSTRONG%3Eonly%20one%20FAT32%20boot%20partition%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EFiles%20present%20on%20the%20FAT32%20partition%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EImage(U-boot%2Bkernel)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EDevice%20Tree%20Blob%20(.dtb)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3Einitramfs%20image%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3CH3%20id%3D%22toc-hId-195116658%22%20id%3D%22toc-hId-195769175%22%20id%3D%22toc-hId-195769175%22%20id%3D%22toc-hId-195769175%22%3EQuestions%3C%2FH3%3E%3COL%3E%3CLI%3E%3CP%3E%3CSTRONG%3Einitramfs%20Generation%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EWhat%20is%20the%20recommended%20method%20to%20generate%20an%20initramfs%20image%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EShould%20initramfs%20be%20built%20into%20the%20kernel%20or%20loaded%20as%20a%20separate%20image%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3EHow%20can%20initramfs%20be%20loaded%20from%20the%20SD%20card%20(FAT32%20partition)%20using%20U-Boot%3F%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3E%3CSTRONG%3EU-Boot%20Environment%20Commands%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EWhat%20are%20the%20U-Boot%20commands%20or%20environment%20variables%20needed%20to%26nbsp%3BLoad%20the%20kernel%2C%20device%20tree%2C%20and%20initramfs%20from%20SD.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FOL%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2262961%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20Load%20initramfs%20from%20SD%20Card%20(Single%20FAT32%20Boot%20Partition)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2262961%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F151788%22%20target%3D%22_blank%22%3E%40Zhiming_Liu%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EAs%20per%20your%20guidance%2C%20I%20followed%20the%20procedure%20you%20shared.%3CBR%20%2F%3EI%20am%20able%20to%20%3CSTRONG%3Esuccessfully%20load%20the%20kernel%20Image%20and%20DTB%3C%2FSTRONG%3E%2C%20but%20the%20%3CSTRONG%3Einitramfs%20(cpio.gz)%20root%20filesystem%20is%20not%20being%20loaded%20by%20the%20kernel%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3EBelow%20are%20the%20exact%20U-Boot%20commands%20and%20behavior.%3C%2FP%3E%3CH3%20id%3D%22toc-hId-2003291929%22%20id%3D%22toc-hId--1611685288%22%20id%3D%22toc-hId--1611685288%22%3E%3CSTRONG%3EU-Boot%20Commands%20Used%3C%2FSTRONG%3E%3C%2FH3%3E%3CDIV%20class%3D%22%22%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3Eu-boot%3D%26gt%3B%20setenv%20bootargs%20console%3Dttymxc1%2C115200%20root%3D%2Fdev%2Fram%20rw%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3Eu-boot%3D%26gt%3B%20fatload%20mmc%201%3A1%20%3CSPAN%20class%3D%22%22%3E%24%7Bloadaddr%7D%3C%2FSPAN%3E%20Image_copy.gz%2013450466%20bytes%20%3CSPAN%20class%3D%22%22%3Eread%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3Ein%3C%2FSPAN%3E%20282%20ms%20(45.5%20MiB%2Fs)%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3Eu-boot%3D%26gt%3B%20fatload%20mmc%201%3A1%20%3CSPAN%20class%3D%22%22%3E%24%7Bfdt_addr%7D%3C%2FSPAN%3E%20imx8mp-evk.dtb%2082784%20bytes%20%3CSPAN%20class%3D%22%22%3Eread%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3Ein%3C%2FSPAN%3E%204%20ms%20(19.7%20MiB%2Fs)%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3Eu-boot%3D%26gt%3B%20fatload%20mmc%201%3A1%20%3CSPAN%20class%3D%22%22%3E%24%7Bramdisk_addr_r%7D%3C%2FSPAN%3E%20core-image-minimal-initramfs-imx8mp-ddr4-evk.cpio.gz%2012602736%20bytes%20%3CSPAN%20class%3D%22%22%3Eread%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3Ein%3C%2FSPAN%3E%20264%20ms%20(45.5%20MiB%2Fs)%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%3CSPAN%3Eu-boot%3D%26gt%3B%20booti%20%3CSPAN%20class%3D%22%22%3E%24%7Bloadaddr%7D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%24%7Bramdisk_addr_r%7D%3C%2FSPAN%3E%3A%3CSPAN%20class%3D%22%22%3E%24%7Bfilesize%7D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22%22%3E%24%7Bfdt_addr%7D%3C%2FSPAN%3E%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EAfter%20executing%20the%20booti%20command%2C%20the%20%3CSTRONG%3Ekernel%20starts%20booting%3C%2FSTRONG%3E%2C%20but%20it%20%3CSTRONG%3Edoes%20not%20mount%20or%20use%20the%20initramfs%20(cpio.gz)%20as%20root%20filesystem%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3EI%20have%20attached%20the%20full%20kernel%20boot%20log%20for%20reference.%3C%2FP%3E%3CH3%20id%3D%22toc-hId-195837466%22%20id%3D%22toc-hId-875827545%22%20id%3D%22toc-hId-875827545%22%3E%3CSTRONG%3EQuestions%3C%2FSTRONG%3E%3C%2FH3%3E%3COL%3E%3CLI%3E%3CP%3EWhat%20could%20be%20the%20possible%20reasons%20for%20the%20kernel%20%3CSTRONG%3Enot%20loading%20the%20initramfs%20(cpio.gz)%3C%2FSTRONG%3E%20even%20though%20it%20is%20correctly%20loaded%20into%20memory%20by%20U-Boot%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EAre%20there%20any%20%3CSTRONG%3Emandatory%20kernel%20configuration%20options%3C%2FSTRONG%3E%20required%20for%20initramfs%20support%20that%20I%20should%20verify%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EIs%20the%20bootargs%20configuration%20correct%20for%20booting%20with%20initramfs%20on%20i.MX8M%20Plus%2C%20or%20are%20additional%20parameters%20required%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2262293%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20Load%20initramfs%20from%20SD%20Card%20(Single%20FAT32%20Boot%20Partition)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2262293%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EWhat%20is%20the%20recommended%20method%20to%20generate%20an%20initramfs%20image%3F%3C%2FP%3E%0A%3CP%3E--%26gt%3B%20You%20can%20build%20it%20with%20%3CSTRONG%3Ebitbake%26nbsp%3Bcore-image-minimal-initramfs%20%3C%2FSTRONG%3Ein%20Yocto.%3C%2FP%3E%0A%3CP%3EShould%20initramfs%20be%20built%20into%20the%20kernel%20or%20loaded%20as%20a%20separate%20image%3F%3C%2FP%3E%0A%3CP%3E--%26gt%3B%20It%20depends%20on%20your%20needs.%3C%2FP%3E%0A%3CP%3EHow%20can%20initramfs%20be%20loaded%20from%20the%20SD%20card%20(FAT32%20partition)%20using%20U-Boot%3F%3CBR%20%2F%3E--%26gt%3BHere%20is%20example%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%23%20If%20mmc0%20is%20your%20sd%20card.%0Asetenv%20bootargs%20console%3Dttymxc0%2C115200%20root%3D%2Fdev%2Fram%20rw%0Afatload%20mmc%200%3A1%20%24%7Bloadaddr%7D%20Image%0Afatload%20mmc%200%3A1%20%24%7Bfdt_addr%7D%20imx8mp-evk.dtb%0Afatload%20mmc%200%3A1%20%24%7Bramdisk_addr%7D%20xxxx_initramfs.cpio.gz%0Abooti%20%24%7Bloadaddr%7D%20%24%7Bramdisk_addr%7D%3A%24%7Bfilesize%7D%20%24%7Bfdt_addr%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EYou%20can%20refer%26nbsp%3Bboard%2Fbeacon%2Fimx8mn%2Fimx8mn_beacon.env%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eboot_fdt%3Dtry%0Abootdelay%3D2%0Abootscript%3Decho%20Running%20bootscript%20from%20mmc%20...%3B%20source%0Aconsole%3Dttymxc1%0Afdt_addr%3D0x45000000%0Afdt_file%3Dimx8mn-beacon-kit.dtb%0Afinduuid%3Dpart%20uuid%20mmc%20%24%7Bmmcdev%7D%3A2%20uuid%0Aimage%3DImage%0Ainitrd_addr%3D0x46000000%0Aloadbootscript%3Dfatload%20mmc%20%24%7Bmmcdev%7D%3A%24%7Bmmcpart%7D%20%24%7Bloadaddr%7D%20%24%7Bscript%7D%3B%0Aloadfdt%3Dfatload%20mmc%20%24%7Bmmcdev%7D%3A%24%7Bmmcpart%7D%20%24%7Bfdt_addr%7D%20%24%7Bfdt_file%7D%0Aloadimage%3Dfatload%20mmc%20%24%7Bmmcdev%7D%3A%24%7Bmmcpart%7D%20%24%7Bloadaddr%7D%20%24%7Bimage%7D%0Aloadramdisk%3Dload%20mmc%20%24%7Bmmcdev%7D%20%24%7Bramdisk_addr%7D%20%24%7Bramdiskimage%7D%0Ammcargs%3Dsetenv%20bootargs%20console%3D%24%7Bconsole%7D%2C%24%7Bbaudrate%7D%20%20root%3DPARTUUID%3D%24%7Buuid%7D%20rootwait%20rw%20%24%7Bmtdparts%7D%20%24%7Boptargs%7D%0Ammcautodetect%3Dyes%0Ammcboot%3Decho%20Booting%20from%20mmc%20...%3B%20run%20finduuid%3B%20run%20mmcargs%3B%20if%20test%20%24%7Bboot_fdt%7D%20%3D%20yes%20%7C%7C%20test%20%24%7Bboot_fdt%7D%20%3D%20try%3B%20then%20if%20run%20loadfdt%3B%20then%20booti%20%24%7Bloadaddr%7D%20-%20%24%7Bfdt_addr%7D%3B%20else%20echo%20WARN%3A%20Cannot%20load%20the%20DT%3B%20fi%3B%20else%20echo%20wait%20for%20boot%3B%20fi%3B%0Ammcdev%3D1%0Ammcpart%3D1%0Anetargs%3Dsetenv%20bootargs%20console%3D%24%7Bconsole%7D%2C%24%7Bbaudrate%7D%20%20root%3D%2Fdev%2Fnfs%20ip%3Ddhcp%20nfsroot%3D%24%7Bserverip%7D%3A%24%7Bnfsroot%7D%2Cv3%2Ctcp%0Anetboot%3Decho%20Booting%20from%20net%20...%3B%20run%20netargs%3B%20%20if%20test%20%24%7Bip_dyn%7D%20%3D%20yes%3B%20then%20setenv%20get_cmd%20dhcp%3B%20else%20setenv%20get_cmd%20tftp%3B%20fi%3B%20%24%7Bget_cmd%7D%20%24%7Bloadaddr%7D%20%24%7Bimage%7D%3B%20if%20test%20%24%7Bboot_fdt%7D%20%3D%20yes%20%7C%7C%20test%20%24%7Bboot_fdt%7D%20%3D%20try%3B%20then%20if%20%24%7Bget_cmd%7D%20%24%7Bfdt_addr%7D%20%24%7Bfdt_file%7D%3B%20then%20booti%20%24%7Bloadaddr%7D%20-%20%24%7Bfdt_addr%7D%3B%20else%20echo%20WARN%3A%20Cannot%20load%20the%20DT%3B%20fi%3B%20else%20booti%3B%20fi%3B%0Aramargs%3Dsetenv%20bootargs%20console%3D%24%7Bconsole%7D%2C%24%7Bbaudrate%7D%20%20root%3D%2Fdev%2Fram%20rw%20%20%24%7Boptargs%7D%0Aramboot%3Decho%20Booting%20from%20RAMdisk...%3B%20run%20loadimage%3B%20run%20loadfdt%3B%20fdt%20addr%20%24fdt_addr%3B%20run%20loadramdisk%3B%20run%20ramargs%3B%20booti%20%24%7Bloadaddr%7D%20%24%7Bramdisk_addr%7D%20%24%7Bfdt_addr%7D%20%24%7Boptargs%7D%0Aramdisk_addr%3D0x46000000%0Aramdiskimage%3Drootfs.cpio.uboot%0Ascript%3Dboot.scr%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3EBest%20Regards%2C%3CBR%20%2F%3EZhiming%3C%2FP%3E%3C%2FLINGO-BODY%3E