Bundle a core-image-tiny-initramfs to a core-image-minimal .wic image file in my "zeus" yocto-Linux project

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

Bundle a core-image-tiny-initramfs to a core-image-minimal .wic image file in my "zeus" yocto-Linux project

Jump to solution
15,363 Views
fbre
Contributor III

Hi,

I have problems to get an initramfs work which should be bundled to the kernel via INITRAMFS_IMAGE_BUNDLE.

I switched to "zeus" as yocto version to be able to work with .wic files. I have an i.MX8mm evalboard where I boot Linux from SD card.

That's why I configured the build with: DISTRO=fsl-imx-wayland MACHINE=imx8mmevk source imx-setup-release.sh -b build which results to the following variables in local.conf:

MACHINE  ??= 'imx8mmevk'

DISTRO ?= 'fsl-imx-wayland'

The rest is as it comes by default.

What did I do?:

  1. First, I added the following lines to my yocto/build/conf/local.conf of yocto:

    INITRAMFS_IMAGE = "core-image-tiny-initramfs"

    INITRAMFS_IMAGE_BUNDLE = "1"

    VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"

  2. Second, for a fast trial, I also changed a line in yocto/sources/poky/meta/recipes-core/images/core-image-tiny-initramfs.bb to add aarch64 support:

    COMPATIBLE_HOST = "(i.86|x86_64|aarch64).*-linux"

  3. and I commented out a line in yocto/sources/meta-imx/meta-bsp/conf/layer.conf this way:

    #IMAGE_CLASSES += "image_types_create_sdcard_symlink"

  4. Now I was able to build the whole thing with bitbake core-image-minimal without errors. I think, the resulting key files in yocto/build/tmp/deploy/images/imx8mmevk are the following, and I also extracted the wic.bz2 already here:

    core-image-minimal-imx8mmevk-[timestamp].rootfs.wic.bz2     42,3 MiB

    core-image-minimal-imx8mmevk-[timestamp].rootfs.wic         271,2 MiB
    core-image-tiny-initramfs.imx8mmevk-[timestamp].rootfs.cpio.gz 11,8 MiB
    core-image-tiny-initramfs.imx8mmevk.cpio.gz    (link to file above)
  5. Next I wrote that .wic file to my SD card with dd (as described in the NXP docs).
  6. I plugged that SD card into my eval board, switched on and typed on u-boot command line this one:

    setenv mmcroot /dev/ram0 rootwait rw

    boot
  7. Now the Linux boots properly but hangs with: Waiting for root device /dev/ram0...

  8. When I keep the mmcroot in u-boot to /dev/mmcblk1p2, Linux boots without problems! But in that case I cannot see it boots via initramfs. It uses the common rootfs of core-image-minimal.

It seems to me a core-image-minimal image without bundled initramfs image is just 200KB smaller. So I suspect the bundling does not properly work.

What goes wrong? What must be changed to let the Linux kernel use the bundled initramfs RAM filesystem??? Is there a problem with the scripts which bundle the initramfs to the wic file?

The actual thing I want to do is to setup my Linux with an overlayfs over the whole rootfs, and I can see core-image-tiny-initramfs is exactly doing that as it is configured so via its yocto/sources/poky/meta/recipes-core/initrdscripts/files/init-live.sh.

Thanx in advance for your help.

Tags (2)
0 Kudos
Reply
1 Solution
15,202 Views
fbre
Contributor III

Meanwhile I found out I also have to do 2 things more to really boot with that bundled initramfs:

  1. It is also necessary to add this IMAGE_BOOT_FILES_append = " ${KERNEL_IMAGETYPE}-initramfs-${MACHINE}.bin" to conf/local.conf. This let the build system put the file Image-initramfs-imx8mmevk.bin to the boot partition of the SD card also. Now we have 2 kernel images, Image is the default one and that new Image-initramfs-imx8mmevk.bin which is the kernel with the bundled initramfs.
  2. Now when I stop in u-boot on command line I have to call the following command to tell u-boot to use the other Linux kernel on boot:     setenv image Image-initramfs-imx8mmevk.bin

Well, now it boots the kernel with the bundled initramfs but stops now here:

[    3.806081] mmc1: new ultra high speed SDR104 SDHC card at address 0001
[    3.813856] mmcblk1: mmc1:0001 EB1QT 29.8 GiB
[    3.820328]  mmcblk1: p1 p2
[    4.131276] imx6q-pcie 33800000.pcie: Phy link never came up
[    4.136983] imx6q-pcie 33800000.pcie: failed to initialize host
[    4.142921] imx6q-pcie 33800000.pcie: unable to add pcie port.
[    4.161500] Freeing unused kernel memory: 40640K
[    4.166205] Run /init as init process
Starting version 243.2+
Waiting for removable media...

I've searched the internet for this problem and found this one: Waiting for removable media ... 

So the cool thing is I realise my core-image-tiny-initramfs has started up. :-) I just need to tweak the script recipes-core/initrdscripts/files/init-live.sh a bit, and I must remove the script part with the loop of waiting for plugging in a live-CD to get over that hang on "Waiting for removable media". I must set my own /dev/mmcblk1p2 partition to be the lower layer for the overlayfs. Just look at script function mount_and_boot() in init-live.sh...

I hope this answer may help other people, too. It took me lots of hours, and I have to thank the yocto guys at freenode chat irc for their incredible help to solve this problem.

-- Cheers, F.B.

View solution in original post

0 Kudos
Reply
9 Replies
13,509 Views
fbre
Contributor III

OK, in the end I switched to yocto-version "dunfell" and it works there pretty easy with these settings:

INITRAMFS_IMAGE = "core-image-tiny-initramfs"
INITRAMFS_IMAGE_BUNDLE = "1"
INITRAMFS_KERNEL_IMAGE="${KERNEL_IMAGETYPE}-initramfs-${MACHINE}.bin"
VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
IMAGE_BOOT_FILES_append = " ${INITRAMFS_KERNEL_IMAGE};${KERNEL_IMAGETYPE}"

 

6,277 Views
mcuboot
Contributor II

Hi,

Update 22 Oct 2023: If you are building from Yocto honister (3.4) and above (ie. honister, kirkstone etc) you may get this error message:

"ERROR: Variable IMAGE_BOOT_FILES_append file: [you base folder]/imx-linux-kirkstone/build/conf/local.conf line: 31 contains an operation using the old override syntax. Please convert this layer/metadata before attempting to use with a newer bitbake."

To fix this, you may need to replace the "_" to ":" due to syntax change to override from honister onwards (i built in kirkstone, didn't verify on newer releases though).

IMAGE_BOOT_FILES_append = " ${INITRAMFS_KERNEL_IMAGE};${KERNEL_IMAGETYPE}"

needs to be changed to

IMAGE_BOOT_FILES:append = " ${INITRAMFS_KERNEL_IMAGE};${KERNEL_IMAGETYPE}"

due to change in syntax for override documented here:

https://docs.yoctoproject.org/next/migration-guides/migration-3.4.html

 

0 Kudos
Reply
15,203 Views
fbre
Contributor III

Meanwhile I found out I also have to do 2 things more to really boot with that bundled initramfs:

  1. It is also necessary to add this IMAGE_BOOT_FILES_append = " ${KERNEL_IMAGETYPE}-initramfs-${MACHINE}.bin" to conf/local.conf. This let the build system put the file Image-initramfs-imx8mmevk.bin to the boot partition of the SD card also. Now we have 2 kernel images, Image is the default one and that new Image-initramfs-imx8mmevk.bin which is the kernel with the bundled initramfs.
  2. Now when I stop in u-boot on command line I have to call the following command to tell u-boot to use the other Linux kernel on boot:     setenv image Image-initramfs-imx8mmevk.bin

Well, now it boots the kernel with the bundled initramfs but stops now here:

[    3.806081] mmc1: new ultra high speed SDR104 SDHC card at address 0001
[    3.813856] mmcblk1: mmc1:0001 EB1QT 29.8 GiB
[    3.820328]  mmcblk1: p1 p2
[    4.131276] imx6q-pcie 33800000.pcie: Phy link never came up
[    4.136983] imx6q-pcie 33800000.pcie: failed to initialize host
[    4.142921] imx6q-pcie 33800000.pcie: unable to add pcie port.
[    4.161500] Freeing unused kernel memory: 40640K
[    4.166205] Run /init as init process
Starting version 243.2+
Waiting for removable media...

I've searched the internet for this problem and found this one: Waiting for removable media ... 

So the cool thing is I realise my core-image-tiny-initramfs has started up. :-) I just need to tweak the script recipes-core/initrdscripts/files/init-live.sh a bit, and I must remove the script part with the loop of waiting for plugging in a live-CD to get over that hang on "Waiting for removable media". I must set my own /dev/mmcblk1p2 partition to be the lower layer for the overlayfs. Just look at script function mount_and_boot() in init-live.sh...

I hope this answer may help other people, too. It took me lots of hours, and I have to thank the yocto guys at freenode chat irc for their incredible help to solve this problem.

-- Cheers, F.B.

0 Kudos
Reply
11,943 Views
adde_ado
Contributor III

Hi F.B.,

Have you managed to tweak init-live.sh script so that your rootfs starts from /dev/mmcblk1p2?

Best regards,

Adde

0 Kudos
Reply
11,881 Views
fbre
Contributor III

Hi,

u-boot should set a command-line parameter flash_device=/dev/mmcblk1p2. Parse that in your script:

#
#early setup
#
mkdir -p /proc /sys /run /var/run
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs none /dev

# parse u-boot parameters
CMDLINE=$(cat /proc/cmdline)
for x in $CMDLINE
do
    case $x in
        flash_device*)
        FLASHDEVICE="${x//flash_device=}"
        ;;
    esac
done

Next, create a directory and mount the partition to that created dir.

Finally, switch to root of your filesystem to that mounted dir (here I assign it to a variable ROOT_MOUNT):

# Watches the udev event queue, and exits if all current events are handled
udevadm settle --timeout=3

# Don't run systemd-update-done on systemd-based live systems
# because it triggers a slow rebuild of ldconfig caches.
touch ${ROOT_MOUNT}/etc/.updated ${ROOT_MOUNT}/var/.updated

mount -n --move /proc ${ROOT_MOUNT}/proc
mount -n --move /sys ${ROOT_MOUNT}/sys
mount -n --move /dev ${ROOT_MOUNT}/dev

cd $ROOT_MOUNT

# busybox switch_root supports -c option
exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init $CMDLINE ||
    fatal "Couldn't switch_root, dropping to shell"

I hope this helps

11,871 Views
adde_ado
Contributor III

Thank you so much fbre for you help! It works like a charm.:)

Best regards,

Adde

 

15,202 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello F B,

Have you tried to generate the core-image-minimal-initramfs? The image is used for minimal RAM based rootfs. Let me know more details about the issue - how it can be reproduced ?

Regards

0 Kudos
Reply
15,202 Views
fbre
Contributor III

Yes, I also tried INITRAMFS_IMAGE = core-image-minimal-initramfs instead of INITRAMFS_IMAGE = core-image-tiny-initramfs. Also here, I had to add aarch64 to the .bb file of this image. But in the end I get a strange bitbake error on generating the rootfs:

"Some packages could not be installed....

The following packages have unmet dependencies:

initramfs-module-install : Depends: grub but it is not installable"

I haven't tried to go this path further since my actual aim was to have that overlayfs stuff of init-live.sh which is not in the scripts of core-image-minimal-initramfs, you know.

This all can be reproduced with a fresh git checkout of the current zeus branch. Just follow the instructions of https://www.nxp.com/docs/en/user-guide/IMX_YOCTO_PROJECT_USERS_GUIDE.pdf A.1Quick Start, and additionally do the things described in this posting.

0 Kudos
Reply
8,445 Views
abible
Contributor I

I am currently running into the same issue on Zeus (5.4.70-2.3.11 release). Is there a quick resolution for this issue that anyone has found? I would rather not dive in if I don't have to, but since this is the last hurdle for my build I may not have much of a choice.

0 Kudos
Reply