I am following the book "Mastering Embedded Linux Programming - Second Edition" trying to boot up the Linux kernel mounting a ramdisk.

I have U-boot 2020.01 working and the Linux kernel image made. I have made a file system on my computer where I have added busybox and the libraries required by it manually as so files. Here is summarized copy of tree in my filesystem.

├── bin
│   ├── arch -> busybox
│   ├── busybox
│   ├── cat -> busybox
├── dev
├── etc
├── home
├── lib
│   ├── ld-2.30.so
│   ├── ld-linux-armhf.so.3 -> ld-2.30.so
│   ├── libc-2.30.so
│   ├── libc.so.6 -> libc-2.30.so
│   ├── libm-2.30.so
│   ├── libm.so.6 -> libm-2.30.so
│   ├── libresolv-2.30.so
│   └── libresolv.so.2 -> libresolv-2.30.so
├── linuxrc -> bin/busybox
├── proc
├── sbin
│   ├── acpid -> ../bin/busybox
├── sys
├── tmp
├── usr
│   ├── bin
│   │   ├── [ -> ../../bin/busybox
│   ├── lib
│   └── sbin
│       ├── addgroup -> ../../bin/busybox
└── var
    └── log

I have created my ramdisk image following the snippet:

cd ~/rootfs
find . | cpio -H newc -ov --owner root:root > ../initramfs.cpio
cd ..
gzip initramfs.cpio
mkimage -A arm -O linux -T ramdisk -d initramfs.cpio.gz uRamdisk

I have placed all the needed files in the SD card and in u-boot in the Beaglebone black tried to boot as:

fatload mmc 0:1 0x80200000 zImage
fatload mmc 0:1 0x80f00000 am335x-boneblack.dtb
fatload mmc 0:1 0x81000000 uRamdisk
setenv bootargs console=ttyO0,115200 rdinit=/bin/sh
bootz 0x80200000 0x81000000 0x80f00000

The problem is after the bootz it complains about my ramdisk image being wrong.

=> fatload mmc 0:1 0x80200000 zImage
7109016 bytes read in 464 ms (14.6 MiB/s)
=> fatload mmc 0:1 0x80f00000 am335x-boneblack.dtb
34220 bytes read in 5 ms (6.5 MiB/s)
=> fatload mmc 0:1 0x81000000 uRamdisk
2828897 bytes read in 185 ms (14.6 MiB/s)
=> setenv bootargs console=ttyO0,115200 rdinit=/bin/sh
=> bootz 0x80200000 0x81000000 0x80f00000
Wrong Ramdisk Image Format
Ramdisk image is corrupt or invalid

As I am starting with Linux on embedded devices I am completely out of ideas on how to solve the issue. I have found the reason is that the filesystem image has been created wrong. I have tried to use mkimage with -c none to no avail. I have tried using the mkimage inside my u-boot copy instead of the one that you can install in Ubuntu (with sudo apt-get install u-boot-tools).

Before mkimage is called initramfs.cpio.gz looks as as follow:

Ramdisk compressed file before mkimage is used

Am I missing some folders/files in my filesystem? Is it a problem my computer has ext4 but the boot partition uses fat32? Do I need to use a different mkimage toolset? What could be the problem?


Simple answer

You need to enable CONFIG_LEGACY_IMAGE_FORMAT in U-Boot:

  1. Go to the u-boot source directory.
  2. Type: $ make menuconfig
  3. In Boot images -> Enable support for the legacy image format
  4. Exit and save, then build U-Boot again

Now it will be able to load your uRamdisk :-)

Longer answer

The book was written using U-Boot v2017.01 and configuration am335x_boneblack_defconfig. U-Boot version v2020.01 does not have that configuration file. Instead it has am335x_boneblack_vboot_defconfig, which works fine except that it does not enable support for the mkimage format.

Speaking as the author of the book, I can only say that it is hard to write detailed instructions that will work for all future versions of software. But I do try.

  • Thank you for the answer and thank you for the book - it helps a lot as an introduction. Regarding the question I managed to get it to work at the end by updating uBoot and using a newer defconfig. There was a version of U-boot or the kernel I could not use as in the book as one of the sources was missing and could not download the libraries to compile so I had to update. Later I had some problems starting the kernel and I solved it by updating to a newer version of the kernel. So in my little experience if something doesn't work I try to get a newer version and hopefully it is fixed :) – Carlos Jul 21 '20 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.