Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching out the kernel zImage for custom compiled Image #2

Open
manyids2 opened this issue Sep 22, 2024 · 6 comments
Open

Switching out the kernel zImage for custom compiled Image #2

manyids2 opened this issue Sep 22, 2024 · 6 comments

Comments

@manyids2
Copy link

Thank you for making this!
It took me some time to figure out, and I ended up at the following diagram:

Red: Original
Blue: Replaced
Green: Mixed

build

I was wondering if it is possible to also replace the zImage?

@mporrato
Copy link
Owner

mporrato commented Sep 22, 2024

Thank you for sharing your diagram: it's a neat way to summarise the process!
To answer your question: in theory, yes, you could provide your own zImage and bootimg.cfg by just dropping them in the resources directory before running make: you will have to make sure they have a fresh timestamp to avoid getting them overwritten by make: I have not tried it but it should work. In practice, it depends on what you want to do with the finished image: not all of the features of the H700 SoC are supported in the mainline kernel and I'm not aware of any usable downstream kernel source provided by vendors of H700 based systems.
If you try it, please let me know how it goes.

Update: I forgot to specify that, if you provide an alternative zImage, you most likely will also have to provide suitable kernel modules and firmware blobs by also dropping your own firmware.tar and modules.tar in the artifacts directory.

@manyids2
Copy link
Author

manyids2 commented Sep 22, 2024

Thank you for the reference to the mainlining effort!

Does that mainly have to do with creating the proper dts files? Or some more support from the kernel?
In case it is about the dts files, I dont know how, but somehow it loads the dtb without it being explicitly specified in the boot command ( I expected something like load mmc ... board.dtb and booti <kernel> <ramdisk> <dtb>, but there is only bootm 45000000 ). I feel like if I can load the proper dtb I can probably boot a corresponding kernel with the features I need (As long as the kernel is the same version, 4.9.170, I assume the firmware and modules will work as well) .

About replacing the zImage, I also am stuck there, as compiling linux gives us an Image for arm64, while somehow the one on the stock image is a zImage. Reading up online says that conversion between the two is not possible, as the arm64 kernel does not have decompressing ability (?). I wonder how they got it in the first place, and if they possibly just renamed the files?

A bit more context, I want to run the audio server jack which needs System V IPC/Semaphores ( I think ), which is probably missing from the current kernel. ( tangentially, even snd-usb-audio module was missing, but I was able to load it with insmod -f ... after compiling the corresponding .ko file. ) However, I cannot seem to compile System V IPC as an external kernel module, so I concluded have no option but to 'replace' the kernel. Is this a valid conclusion?

@manyids2
Copy link
Author

Also, the source for the diagram (d2 --watch build.d2 build.svg) :

vars: {
  d2-config: {
    layout-engine: elk
    dark-theme-id: 1
    pad: 50
  }
}

RESOURCES_DIR {
  "logos"
  "fonts"
  "magic"
  "bat"
}

CONFIG_DIR {
  ".build"
}

"spl.img"            <- FACTORY_IMAGE_A       : extract-blobs.py
"u-boot.img"         <- FACTORY_IMAGE_A       : extract-blobs.py
"env.img"            <- "env.txt"             : mkenv.py

"boot.img"           <- "bootimg.cfg"         : abootimg --create
"boot.img"           <- "zImage"              : abootimg --create
"boot.img"           <- "initramfs"           : abootimg --create

"initramfs"          <- ALPINE_VERSION        : mkinitrd.sh

"boot-resources.img" <- RESOURCES             : mkfsimage.sh vfat
"boot-resources.img" <- RESOURCES_SIZE        : truncate

"zImage"             <- FACTORY_IMAGE_A       : extract-kernel.sh
"bootimg.cfg"        <- FACTORY_IMAGE_A       : extract-kernel.sh

"firmware.tar"       <- FACTORY_IMAGE_B       : extract-modules.sh
"modules.tar"        <- FACTORY_IMAGE_B       : extract-modules.sh
"config.tar"         <- CONFIG                : fakeroot tar

"rootfs.tar"         <- ALPINE_VERSION        : build-rootfs.sh

"rootfs.img"         <- "rootfs.tar"          : mkfsimage.sh ext4
"rootfs.img"         <- "config.tar"          : mkfsimage.sh ext4
"rootfs.img"         <- "firmware.tar"        : mkfsimage.sh ext4
"rootfs.img"         <- "modules.tar"         : mkfsimage.sh ext4

"alpine-h700.img"    <- "spl.img"             : mkpart.sh
"alpine-h700.img"    <- "u-boot.img"          : mkpart.sh
"alpine-h700.img"    <- "env.img"             : mkpart.sh
"alpine-h700.img"    <- "boot-resources.img"  : mkpart.sh
"alpine-h700.img"    <- "boot.img"            : mkpart.sh
"alpine-h700.img"    <- "rootfs.img"          : mkpart.sh
"alpine-h700.img"    <- SD_SIZE               : truncate -s

("zImage"             <- FACTORY_IMAGE_A )[0].style.stroke: red
("bootimg.cfg"        <- FACTORY_IMAGE_A )[0].style.stroke: red
("spl.img"            <- FACTORY_IMAGE_A )[0].style.stroke: red
("u-boot.img"         <- FACTORY_IMAGE_A )[0].style.stroke: red
("modules.tar"        <- FACTORY_IMAGE_B )[0].style.stroke: red
("firmware.tar"       <- FACTORY_IMAGE_B )[0].style.stroke: red
("rootfs.img"         <- "modules.tar"   )[0].style.stroke: red
("rootfs.img"         <- "firmware.tar"  )[0].style.stroke: red
("boot.img"           <- "bootimg.cfg"   )[0].style.stroke: red
("boot.img"           <- "zImage"        )[0].style.stroke: red

("boot-resources.img" <- RESOURCES       )[0].style.stroke: blue
("boot-resources.img" <- RESOURCES_SIZE  )[0].style.stroke: blue
("env.img"            <- "env.txt"       )[0].style.stroke: blue
("rootfs.tar"         <- ALPINE_VERSION  )[0].style.stroke: blue
("initramfs"          <- ALPINE_VERSION  )[0].style.stroke: blue
("config.tar"         <- CONFIG          )[0].style.stroke: blue
("boot.img"           <- "initramfs"     )[0].style.stroke: blue
("rootfs.img"         <- "rootfs.tar"    )[0].style.stroke: blue
("rootfs.img"         <- "config.tar"    )[0].style.stroke: blue

("alpine-h700.img"    <- "spl.img"             )[0].style.stroke: red
("alpine-h700.img"    <- "u-boot.img"          )[0].style.stroke: red
("alpine-h700.img"    <- "env.img"             )[0].style.stroke: blue
("alpine-h700.img"    <- "boot-resources.img"  )[0].style.stroke: blue
("alpine-h700.img"    <- SD_SIZE               )[0].style.stroke: blue
("alpine-h700.img"    <- "boot.img"            )[0].style.stroke: green
("alpine-h700.img"    <- "rootfs.img"          )[0].style.stroke: green

@mporrato
Copy link
Owner

Mainlining H700 support is not just a matter of coming up with the right device tree because entire drivers are missing: see for example the RG35XX+ page on the linux-sunxi wiki.
I don't think that building a mainline 4.9.170 kernel will get you anywhere: you may be able to build some device drivers and get them to load in the stock kernel but I bet you can't do the other way around: the anbernic kernel has pretty much everything built in and only a few drivers are modules (wifi, bt, lcd, gpu and a bunch of sensors): there is a bunch of important stuff that cannot be built into modules or specified in a dtb and has to live in the actual kernel image.
If you want to play with the dtbs, AFAIK, at least in the anbernic images, the dtb is embedded in the u-boot image:

$ binwalk artifacts/u-boot.img | grep "device tree"
1174528       0x11EC00        Flattened device tree, size: 2336 bytes, version: 17
1177600       0x11F800        Flattened device tree, size: 139760 bytes, version: 17

I believe the former (smaller) is the dtb used by u-boot itself and the latter (larger) is the one used by the kernel.
If you want to provide your own you will have to overwrite that section of the image: it should be quite straightforward, but it's not something that the scripts in this repo support out of the box.

As for the kernel image format, as long as it's a "Linux kernel ARM64 boot executable Image, little-endian, 4K pages" file (you can check using file), it should be fine.

For the jack part, I'm not familiar with the audio subsystem, but I've heard that pipewire has a jack compatibility layer so you may want to give it a try, but I don't know if the SysV IPC requirement also applies to that compatibility layer. And yes, you are right, the SysV IPC mechanism can't be built as a module: it's either enabled or disabled: I've checked the kernel config from an earlier stock kernel for the RG35XX+ and I can confirm it's disabled:

$ zgrep SYSVIPC kernel-config.gz
# CONFIG_SYSVIPC is not set

Finally, if you want to go down the rabbit hole of compiling your own kernel for this platform, you may be better off using postmarketos since it provides nice helpers to apply patches to the kernel sources. On the other hand, since you mentioned jack, from the info on the linux-sunxi wiki, to me it looks like there is still no working driver for the audio codec in the H700 SoC, so if audio is what you are after, you should probably stick to the vendor's kernel for the time being.

@tokyovigilante
Copy link

Ummm... team....

Welcome to Alpine Linux 3.20
Kernel 6.13.0-rc1+ on an aarch64 (/dev/ttyS0)

localhost login: muos
Password:
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

localhost:~$ fastfetch
       .hddddddddddddddddddddddh.           muos@localhost
      :dddddddddddddddddddddddddd:          --------------
     /dddddddddddddddddddddddddddd/         OS: Alpine Linux 3.20.2 aarch64
    +dddddddddddddddddddddddddddddd+        Host: Anbernic RG35XX H
  `sdddddddddddddddddddddddddddddddds`      Kernel: Linux 6.13.0-rc1+
 `ydddddddddddd++hdddddddddddddddddddy`     Uptime: 1 min
.hddddddddddd+`  `+ddddh:-sdddddddddddh.    Packages: 442 (apk)
hdddddddddd+`      `+y:    .sddddddddddh    Shell: sh
ddddddddh+`   `//`   `.`     -sddddddddd    Display (Unknown-1): 640x480 @ 60 Hz in 7″
ddddddh+`   `/hddh/`   `:s-    -sddddddd    Terminal: vt102
ddddh+`   `/+/dddddh/`   `+s-    -sddddd    CPU: Cortex-A53*4 (4)
ddd+`   `/o` :dddddddh/`   `oy-    .yddd    GPU: Allwinner sun50i-h616-mali [Integrated]
hdddyo+ohddyosdddddddddho+oydddy++ohdddh    Memory: 239.01 MiB / 980.85 MiB (24%)
.hddddddddddddddddddddddddddddddddddddh.    Swap: Disabled
 `yddddddddddddddddddddddddddddddddddy`     Disk (/): 2.80 GiB / 9.80 GiB (29%) - ext4
  `sdddddddddddddddddddddddddddddddds`      Local IP (wlan0): 192.168.1.202/24
    +dddddddddddddddddddddddddddddd+        Locale: C.UTF-8
     /dddddddddddddddddddddddddddd/
      :dddddddddddddddddddddddddd:
       .hddddddddddddddddddddddh.

Maybe come and join the effort on the Rocknix discord, or IRC at #sunxi-linux?

The audio driver is in 6.13rc1, just missing the jack detection which I'm working on currently. I do need to update the wiki page...

Have attached my notes/script for building a straightforward image with a single ext4 rootfs (from an Alpine host, but should work wherever).

root-image.md

@tokyovigilante
Copy link

Sorry you'll also need these base image packages (enough to get the system booted with wifi, then just apk add whatever else you need.
wget -i apklist -nc -P apks/

https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/alpine-base-3.20.2-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/alpine-baselayout-3.6.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/alpine-baselayout-data-3.6.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/alpine-conf-3.18.1-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/alpine-keys-2.4-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/alpine-release-3.20.2-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/bonding-2.6-r5.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/bridge-1.5-r5.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/busybox-1.36.1-r29.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/busybox-binsh-1.36.1-r29.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/busybox-mdev-openrc-1.36.1-r29.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/busybox-openrc-1.36.1-r29.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/busybox-suid-1.36.1-r29.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/ca-certificates-20240705-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/ca-certificates-bundle-20240705-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/chrony-4.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/chrony-openrc-4.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/dbus-1.14.10-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/dbus-libs-1.14.10-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/dbus-openrc-1.14.10-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/dhcpcd-10.0.6-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/dhcpcd-openrc-10.0.6-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/doas-6.8.2-r7.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/e2fsprogs-1.47.0-r5.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/e2fsprogs-extra-1.47.0-r5.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/e2fsprogs-libs-1.47.0-r5.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/eudev-3.2.14-r2.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/eudev-libs-3.2.14-r2.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/gmp-6.3.0-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/gnutls-3.8.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/ifupdown-ng-0.12.1-r5.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/iw-6.9-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/kbd-bkeymaps-2.6.4-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/kmod-libs-32-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libblkid-2.40.1-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libcap2-2.70-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libcom_err-1.47.0-r5.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libcrypto3-3.3.1-r3.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libeconf-0.6.3-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libedit-20240517.3.1-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libexpat-2.6.2-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libffi-3.4.6-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libgcc-13.2.1_git20240309-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libidn2-2.3.7-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libmount-2.40.1-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libncursesw-6.4_p20240420-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libnl3-3.9.0-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libpcap-1.10.4-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libretls-3.7.0-r2.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libseccomp-2.5.5-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libsmartcols-2.40.1-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libssl3-3.3.1-r3.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libstdc++-13.2.1_git20240309-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libtasn1-4.19.0-r2.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libunistring-1.2-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libusb-1.0.27-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/libuuid-2.40.1-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/lsblk-2.40.1-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/mdev-conf-4.7-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/musl-1.2.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/musl-utils-1.2.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/ncurses-terminfo-base-6.4_p20240420-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/nettle-3.9.1-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openrc-0.54-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openresolv-3.13.2-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-client-common-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-client-default-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-keygen-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-server-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-server-common-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-server-common-openrc-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssh-sftp-server-9.7_p1-r4.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/openssl-3.3.1-r3.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/p11-kit-0.25.3-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/pcre2-10.43-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/pcsc-lite-libs-2.2.3-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/popt-1.19-r3.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/readline-8.2.10-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/scanelf-1.3.7-r2.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/sgdisk-1.0.10-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/ssl_client-1.36.1-r29.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/tzdata-2024a-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/udev-init-scripts-35-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/udev-init-scripts-openrc-35-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/usb-modeswitch-2.6.1-r3.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/wget-1.24.5-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/xz-libs-5.6.1-r3.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/zlib-1.3.1-r1.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/zstd-libs-1.5.6-r0.apk

https://dl-cdn.alpinelinux.org/alpine/v3.20/community/aarch64/exfatprogs-1.2.2-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/community/aarch64/iwd-2.17-r0.apk
https://dl-cdn.alpinelinux.org/alpine/v3.20/community/aarch64/iwd-openrc-2.17-r0.apk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants