To use proper uboot wrapper initramfs

Talk about the project itself, the community, where we are and what we need. Great place to introduce yourself and make friends as well.

To use proper uboot wrapper initramfs

Postby adam900710 » Thu Oct 17, 2019 1:56 am

Hi,

I found alarm kernel pretty big (20+M for aarch64) as it includes all needed fs/mmc drivers.
I guess the main reason is, uboot won't really load plain initramfs.

Uboot needs uboot wrapped initramfs (mkimage -T ramdisk) to proper pass it to kernel.
So under most case, uboot won't pass initramfs proper to kernel, thus we rely kernel sololy to boot whatever the board.

This is completely against the normal idea of initramfs. With initramfs, we should only compile what we need into initramfs for mounting the rootfs.

I have crafted uboot-rockpi4 and uboot-rockpro64, which included hooks for pacman to generate uboot wrapperd initramfs (initramfs-linux.img.uboot), and include uboot-tools as dep for mkimage.
https://github.com/adam900710/PKGBUILDs ... 8345684fd7

I guess we should follow the same principle to make all uboot-* packages to properly generate the wrapped initramfs, and then change kernel config to make everything compiled into modules other than into the kernel.

I tried to send out an issue to the PKGBUILDs repo, but the author has disabled issues.
Hopes this is the proper place to ask for such modification.

Thanks.
adam900710
 
Posts: 35
Joined: Thu Sep 13, 2012 1:27 pm

Re: To use proper uboot wrapper initramfs

Postby summers » Thu Oct 17, 2019 9:15 am

Thought in your other thread you were asking how to make and modify the initramfs under arch, but here you see to have a different problem.

First off, the initramfs is loaded by the kernel, specifically one of the parameters that uboot passes to the kernel is the address of the initramfs in memory. This has been in uboot since the year dot, way before I started using it anyway, maybe 10 years ago.

So part of what is confusing you is how the initramfs gets into memory. This has changed in various versions of uboot. A long time ago, yes it had to be wrapped up in an image, and the header of that image told uboot how to load it into memory. All recent uboot though have been able to read the file systems (with common formats, e.g. ext4), take a file and load it to an area of memory. This is whats done these days with initramfs, the file is loaded into memory and that address passed to the kernel.

You also seem to question why the default arm arch kernel has so much enabled by default, and isn't loaded as a module. Thats a question for the arch arm maintainers, its set in the PKGBUILD in particular in the .config file. Can't say I've ever had a problem with it.

Just check your git set up - you havn't passed the addresses to the kernel in the modern way. Try looking at a modern boot.txt and understand how it works:

https://archlinuxarm.org/packages/armv7h/uboot-beaglebone/files/boot.txt
summers
 
Posts: 922
Joined: Sat Sep 06, 2014 12:56 pm

Re: To use proper uboot wrapper initramfs

Postby adam900710 » Sun Oct 20, 2019 1:31 pm

Thought in your other thread you were asking how to make and modify the initramfs under arch, but here you see to have a different problem.

First off, the initramfs is loaded by the kernel, specifically one of the parameters that uboot passes to the kernel is the address of the initramfs in memory. This has been in uboot since the year dot, way before I started using it anyway, maybe 10 years ago.


Nope, you should try the latest Uboot.
booti command no longer pass that memory address directly to kernel.
U-boot now do extra check on the initrd/initramfs, if it find the image at ${ramdisk_addr_r} doesn't start with U-boot header, it refuse to boot with ${ramdisk_addr_r} passed.

So part of what is confusing you is how the initramfs gets into memory. This has changed in various versions of uboot. A long time ago, yes it had to be wrapped up in an image, and the header of that image told uboot how to load it into memory. All recent uboot though have been able to read the file systems (with common formats, e.g. ext4), take a file and load it to an area of memory. This is whats done these days with initramfs, the file is loaded into memory and that address passed to the kernel.

Of course I have tried that method, passing that initrd=<memory addr> option, but kernel still fails to extract that image.

You also seem to question why the default arm arch kernel has so much enabled by default, and isn't loaded as a module. Thats a question for the arch arm maintainers, its set in the PKGBUILD in particular in the .config file. Can't say I've ever had a problem with it.

Just check your git set up - you havn't passed the addresses to the kernel in the modern way. Try looking at a modern boot.txt and understand how it works:

https://archlinuxarm.org/packages/armv7 ... s/boot.txt


That modern way is what I did first for latest Uboot, and it won't even boot due to extra booti check.
Please try it on a modern aarch64 board with modern uboot.

Thanks
adam900710
 
Posts: 35
Joined: Thu Sep 13, 2012 1:27 pm

Re: To use proper uboot wrapper initramfs

Postby adam900710 » Sun Oct 20, 2019 1:58 pm

BTW, you can check if your board really loaded the initramfs properly.

For my setup, using the uboot wrapped initramfs, the dmesg looks like:
Code: Select all
 Kernel command line: console=ttyS2,1500000 root=PARTUUID=4d82c01e-01 rw rootwait
...
 Trying to unpack rootfs image as initramfs...
 Freeing initrd memory: 7204K
...


There is no initrd passed from cmdline, but kernel still get the proper initramfs, and freed its space.
I guess there is something like the X86 kernel boot protocol header, to pass the real initramfs address.
From my previous search, some device-tree like structure is used to pass the initramfs location and size, thus the initramfs must be handled by U-boot.

If not properly extracted, after that "Trying to unpack rootfs" line, it will output a decompression failure line.
Exactly what I got using the so-called modern u-boot wrapped script (firstly copied from rock64 boot.txt)

The current boot sequence works completely because XFS/EXT4 is compiled into the kernel.
If it's not, any initramfs problem will just prevent anyone from proper booting.

So the two problems are in fact related.
adam900710
 
Posts: 35
Joined: Thu Sep 13, 2012 1:27 pm

Re: To use proper uboot wrapper initramfs

Postby summers » Mon Oct 21, 2019 9:34 am

So what you are saying is on the latest uboot that the commands:
Code: Select all
if load ${devtype} ${devnum}:${bootpart} ${kernel_addr_r} /boot/Image; then
  echo fdt: ${fdtfile}
  if load ${devtype} ${devnum}:${bootpart} ${fdt_addr_r} /boot/dtbs/${fdtfile}; then
    if load ${devtype} ${devnum}:${bootpart} ${ramdisk_addr_r} /boot/initramfs-linux.img; then
      booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
    else
      booti ${kernel_addr_r} - ${fdt_addr_r};
    fi;
  fi;
fi

Do not load the initramfs? Exactly what version of uboot are you using, and what commands did you use to compile it?

Passing the initramfs as the second address of the kernel line is the standard, I can't see uboot ever breaking this its so standard; so you must have a broken uboot, and very badly broken at that.

When I get home, I'll give what log messages are on my latest uboot, which is IIRC a 2018 version I needed for my PocketBeagle.
summers
 
Posts: 922
Joined: Sat Sep 06, 2014 12:56 pm

Re: To use proper uboot wrapper initramfs

Postby adam900710 » Mon Oct 21, 2019 1:15 pm

Do not load the initramfs? Exactly what version of uboot are you using, and what commands did you use to compile it?


Obviously it doesn't load the initramfs properly.
I guess most guys don't really try to manually boot using interactive U-boot command as long as the scr can boot.

See this:
Code: Select all
U-Boot 2019.10 (Oct 08 2019 - 18:05:25 +0800)

Model: Radxa ROCK Pi 4
DRAM:  3.9 GiB
Cannot find regulator pwm init_voltage
MMC:   dwmmc@fe320000: 1, sdhci@fe330000: 0
Loading Environment from MMC... Card did not respond to voltage select!
*** Warning - No block device, using default environment

In:    serial@ff1a0000
Out:   serial@ff1a0000
Err:   serial@ff1a0000
Model: Radxa ROCK Pi 4
rockchip_dnl_key_pressed: adc_channel_single_shot fail!
Net:   eth0: ethernet@fe300000
Hit any key to stop autoboot:  0
=>
=> load mmc 1:1 ${kernel_addr_r} /boot/Image
27380224 bytes read in 1730 ms (15.1 MiB/s)
=> load mmc 1:1 ${fdt_addr_r} /boot/dtbs/rockchip/rk3399-rock-pi-4.dtb
71831 bytes read in 19 ms (3.6 MiB/s)
=> fdt addr ${fdt_addr_r}
=> load mmc 1:1 ${ramdisk_addr_r} /boot/initramfs-linux.img
7378692 bytes read in 475 ms (14.8 MiB/s)
=> booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
Wrong Ramdisk Image Format
Ramdisk image is corrupt or invalid


See it? Just as what I found in U-boot.
Maybe in script mode, it skips the check and discard the initramfs.

And just as you expected, if loaded the uboot wrapped initramfs, everything is fine.

Code: Select all
=> load mmc 1:1 ${ramdisk_addr_r} /boot/initramfs-linux.img.uboot
7378794 bytes read in 475 ms (14.8 MiB/s)
=> booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
## Loading init Ramdisk from Legacy Image at 04000000 ...
   Image Name:   U-boot ramdisk
   Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
   Data Size:    7378730 Bytes = 7 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 01f00000
   Booting using the fdt blob at 0x1f00000
   Loading Ramdisk to f5820000, end f5f2972a ... OK
   Loading Device Tree to 00000000f580b000, end 00000000f581f896 ... OK

Starting kernel ...


And I really don't believe it matters for how I compiled the U-boot.
But you can check it in my PKGBUILD, it's just board defconfig:
https://github.com/adam900710/PKGBUILDs ... 4/PKGBUILD

Maybe it's newer U-boot doing extra check in interactive mode, but even using that modern boot.txt, after boot, kernel doesn't load the initramfs properly anyway.
adam900710
 
Posts: 35
Joined: Thu Sep 13, 2012 1:27 pm

Re: To use proper uboot wrapper initramfs

Postby moonman » Mon Oct 21, 2019 6:13 pm

CONFIG_SUPPORT_RAW_INITRD needs to be enabled.
Also the syntax is a little different as you need to pass the size as well <initrd addres>:<initrd size> (which you did not in your example above).
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3304
Joined: Sat Jan 15, 2011 3:36 am

Re: To use proper uboot wrapper initramfs

Postby summers » Mon Oct 21, 2019 6:58 pm

As moonman said. Also note that the load command sets ${filesize} - this isn't well documented, you need to read the source code to see this. So as initramfs needs a size, make sure its the last thing loaded, and so ${filesize} isn't overwritten by subsequent load commands.

The latest defconfig can be seen here https://gitlab.denx.de/u-boot/u-boot/blob/master/configs%2Frock-pi-4-rk3399_defconfig and indeed doesn't set raw intramfs.

And this README, the main uboot one, gives the config option described by Kevin. https://gitlab.denx.de/u-boot/u-boot/blob/master/README
summers
 
Posts: 922
Joined: Sat Sep 06, 2014 12:56 pm

Re: To use proper uboot wrapper initramfs

Postby adam900710 » Tue Oct 22, 2019 12:09 am

CONFIG_SUPPORT_RAW_INITRD needs to be enabled.


This is enabled by default.

And you're right about the ${filesize}.

I need to update the PKGBUILD of that two boards.

Thanks.
adam900710
 
Posts: 35
Joined: Thu Sep 13, 2012 1:27 pm


Return to Community

Who is online

Users browsing this forum: No registered users and 1 guest