Devuan on Khadas VIM3

Hello Everybody,

I have been trying to use Devuan on my Khadas VIM3. So far, I am still having difficulties to align the boot loader with linux kernel that I am using.

The steps that I took are the following:

  1. Dump the image from https://dl.khadas.com/Firmware/VIM3/Debian/ to an SD Card
  2. Create ROOTFS of Devuan Beowulf using Debootstrap on my Devuan Desktop
  3. Delete all files and directories on the ROOTFS of SD Card on step 1
  4. Copy all files and directories of Devuan Beowulf ROOTFS created on step 2, into the ROOTFS partition of the SD card
  5. Insert SD card into Khadas VIM3 and boot it up
  6. Compile linux-5.9.0-rc2 kernel on Khadas VIM3 (source: linux-5.9-rc2 on https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/)
  7. Rename the following files into *-Original:
    • /boot/System.map-5.9.0-rc2
    • /boot/config-5.9.0-rc2
    • /boot/vmlinuz-5.9.0-rc2
    • /boot/initrd.img-5.9.0-rc2
  8. Install linux-image-5.9.0-rc2-1_arm64.deb (built at step 6)
  9. Build uInitrd using the following command
    mkimage -A arm64 -O linux -T ramdisk -C gzip -n uInitrd -d /boot/initrd.img-5.9.0-rc2 /boot/uInitrd
  10. Boot Khadas VIM3

I have no idea how to build the zImage. The target zImage is not available anymore on the Makefile of the kernel source so I cannot build it using command make zImage.

So as expected, I got the following error:

root@khadas-vim3:~# dmesg | head -5
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[ 0.000000] Linux version 5.9.0-rc2 (master@universe) (aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 9.2.1 20191025, GNU ld (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 2.33.1.20191209) #0.9.3 SMP Thu Aug 27 17:22:08 CST 2020
[ 0.000000] Machine model: Khadas VIM3
[ 0.000000] [Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader! <------------ Of course!
[ 0.000000] Reserved memory: created CMA memory pool at 0x00000000bd800000, size 768 MiB
root@khadas-vim3:~#

Does anybody know how to build the zImage?

Thanks a lot in advance for your help.

Kind regards,

Anto

I forgot to mention.

I also tried to copy the Image file of the kernel that I previously compiled to be zImage as below:

root@khadas-vim3:~# cp /usr/src/linux-5.9.0-rc2/arch/arm64/boot/Image /boot/zImage

But my Khadas VIM3 just refuses to boot.

I also tried to use the vmlinuz file (compressed or uncompressed) from the kernel that I compiled as zImage, but my Khadas VIM3 does not want to boot.

It can only boot when I use the zImage file from the original Debian Buster image (see step 1 on my initial post).

It can also boot with the uInitrd that I created based on the initrd file of the kernel that I compiled (see point 9 on my initial post).

The content of the /boot partition on my SD Card is the following:

root@khadas-vim3:/boot# ls -ltr
total 76252
-rwxr-xr-x 1 root root 3717 Sep 20 02:27 env.txt
-rwxr-xr-x 1 root root 9581 Sep 20 03:07 boot.scr
-rwxr-xr-x 1 root root 9263 Sep 20 03:07 boot.ini
-rwxr-xr-x 1 root root 51424 Sep 20 03:07 dtb.img
-rwxr-xr-x 1 root root 8309707 Sep 20 03:07 uInitrd.Original
-rwxr-xr-x 1 root root 21067784 Sep 20 03:07 zImage.Original
-rwxr-xr-x 1 root root 21067784 Sep 20 03:07 zImage
-rwxr-xr-x 1 root root 8643083 Sep 20 20:17 vmlinuz-5.9.0-rc2
-rwxr-xr-x 1 root root 4665085 Sep 20 20:17 System.map-5.9.0-rc2
-rwxr-xr-x 1 root root 7023415 Sep 20 20:17 initrd.img-5.9.0-rc2
-rwxr-xr-x 1 root root 185355 Sep 20 20:17 config-5.9.0-rc2
-rwxr-xr-x 1 root root 7023479 Sep 22 23:52 uInitrd
root@khadas-vim3:/boot#
root@khadas-vim3:/boot# file zImage
zImage: data
root@khadas-vim3:/boot# file vmlinuz-5.9.0-rc2
vmlinuz-5.9.0-rc2: gzip compressed data, max compression, from Unix, original size 21002248
root@khadas-vim3:/boot#

I expected the zImage is a compressed image, but as we can see above it is not.

Does anybody have any hints or suggestions to fix this issue?

Or in more generic question, how do we update the zImage after we install a new linux kernel?

Thanks again in advance for your help.

Hello @_anto,
one of our users @clort76 gave a little detailed instruction of how to convert Debian to Devuan,
I suggest you check it out :slight_smile:

1 Like

Hello Electr1,

Thanks a lot for the hints.

I have actually already had a look on that instruction and dug up this forum for similar issues, but I could not find any solution.

My problem is on how to build the new boot loader for a new Linux kernel.

That instruction only explains how to convert Debian/Ubuntu into Devuan via dist-upgrade. It of course can work, but it is not effective in my opinion. You will get the left over packages and libraries from Debian/Ubuntu which do not exist in Devuan. So you will have to manually clean that up. And if you are unlucky, you will have to manually deal with the package dependency madness.

For that reason, some people like me prefer to have a clean install OS. In my case, I use debootstrap to clean install Devuan Beowulf.

Kind regards,

Anto

1 Like

I understand that, Its something that needs to be dealt with…
hopefully someone can help you with your process, best of luck :slight_smile:

I looked into this a bit, you need to make a .dtb. And learn about uboot and stuff. I didn’t have the energy.

It would be nice if you figure it out and post it here _anto :slight_smile:

Or someone else. But khadas kernel works for me too.

If you see systemd, pulseaudio and networkmanager as the trifecta of failure then you will be unhappy here.

A problem is that if you remove systemd, you lose HDMI output. I have tested it. If you take a look at the init scripts for systemd you can see one that sets some things in /sys/class to program the HDMI. These are not executed by default by sysvinit. A little disappointing. Someone would need to find out if these are systemd specific and why they are not used by sysvinit.

There is another problem regarding networkmanager. It cannot be removed because it has many important dependencies. However, if you try to disable it then the suspend/standby/sleep function will break! The board will suddenly power off leaving the USB devices powered in a limbo state. Yikes.

At least my testing so far has shown that pulseaudio is not required. There are some nasty SBCs out there that require this to play all sound formats such as Odroid c0. The fail would be complete if they could somehow find a way to wedge pulseaudio in there. I know you guys can do it I have confidence in you. 2 out of 3 isn’t bad!

Thanks guys for your suggestions.

I just bought a USB serial TTL to debug this issue. But I still could not figure out what is going on.

I thought there must be something fundamentally wrong. So I tried to dump the image on https://dl.khadas.com/Firmware/VIM3/Debian/ into a new SD card, then I booted my Khadas VIM3 with that SD Card. You know what, the result is like this:

root@Khadas:~# dmesg
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[ 0.000000] Linux version 5.9.0-rc2 (master@universe) (aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 9.2.1 20191025, GNU ld (GNU Toolch0
[ 0.000000] Machine model: Khadas VIM3
[ 0.000000] [Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader!
[ 0.000000] Reserved memory: created CMA memory pool at 0x00000000bd800000, size 768 MiB
[ 0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool

So the boot loader of the original Debian Buster image already has that misaligned problem. I am wondering why I didn’t check that before. It was an expensive experience.

I checked dmesg output on one of my VIM3s with a 4.9 Debian kernel compiled by Fenix and flashed by usbtool and I did not see the misaligned error. It may be a red herring but I thought I would let you know.

Thanks a lot Jason for your confirmation.

I think I have to stick with kernel 4.9 as well, until I figure out how to solve this kernel image misaligned issue on newer kernel.

There seems to be something wrong with the Fenix script. It offers the following 2 options for building the image:

  1. U-Boot 2015 and kernel 4.9
  2. U-Boot mainline and kernel mainline (5.9)

However, the result of using those 2 options is that I always get the same U-Boot version. The serial console always shows “U-Boot 2015.01-g4752efb (Mar 19 2020 - 11:49:51)”. I think that is perhaps the cause of the kernel image misaligned issue. On my Debian Buster minimal image that I compiled with the 2nd option, I still get the issue:

G12B:BL:6e7c85:2a3b91;FEAT:E0F83180:402000;POC:F;RCY:0;EMMC:0;READ:0;0.
bl2_stage_init 0x01
bl2_stage_init 0x81
.
.
ERROR: Error initializing runtime service opteed_fast

U-Boot 2015.01-g4752efb (Mar 19 2020 - 11:49:51)

DRAM: 3.8 GiB
.
.
And no dtbos will be applied
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
[rsvmem] fdt get prop fail.
reserving fdt memory region: addr=1000000 size=d000
Loading Ramdisk to 7f11d000, end 7f7ff03d … OK
Loading Device Tree to 000000001ffef000, end 000000001ffff1b5 … OK

Starting kernel …

uboot time: 5865202 us
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[ 0.000000] Linux version 5.9.0-rc2 (anto@virtualbox) (aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 9.2.1 20191025, GNU ld (GNU Toolch0
[ 0.000000] Machine model: Khadas VIM3
[ 0.000000] [Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader!
[ 0.000000] Reserved memory: created CMA memory pool at 0x00000000bd800000, size 768 MiB
[ 0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
.

So I decided to use Debian Buster minimal image with kernel 4.9. I replaced the content of its ROOTFS with Devuan Beowulf, boot it up then I installed the following packages and pulled the dependencies from Devuan’s repositories prior to installing them:

  1. linux-board-package-buster-vim3_0.9.4_arm64.deb
  2. linux-image-amlogic-4.9_0.9.4_arm64.deb
  3. linux-dtb-amlogic-4.9_0.9.4_arm64.deb

Though I still need to clean up some scripts which use systemd specific commands like systemctl, so far it looks fine. I played around a bit with the fan.sh script to cool down the CPU.

1 Like

It would be interesting to see if the HDMI output works or the issue I outlined earlier prevents that. I see that you are using the serial console now. It may be that the output is working but my little touchscreen did not like the default resolution it was using. I forgot to take notes during that part so I don’t remember if I tried my TV during that phase. It is fortunate enough to support many resolutions.

Has anyone tried the 5.9.0-rc2 kernel from khadas with a Devuan conversion? Should be pretty easy. I’ll try in a day or two.

Anything bad/wrong about the debian buster 5.9.0-rc2 kernel # 0.9.3 from khadas? seems to run fine here, so far.