[Dev] Parabola ppc64le mkinitcpio

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Tue Nov 27 13:51:09 GMT 2018


On Thu, 22 Nov 2018 13:33:35 +0100
Bruno Cichon <ebrasca at librepanther.com> wrote:

> Hi when I try to run "mkinitcpio -p linux-libre" I get:
[...]
> [...] ==> ERROR: invalid kernel specified:
> `/boot/vmlinuz-linux-libre'  
We started looking into it on IRC some weeks ago.
It would be easier for people to help you if you give such information.

I'll do it here again to make it less messy to read.

> $ pacman -Q -l mkinitcpio | awk '{print $2}' | grep -v '/$' | \
> xargs grep "invalid kernel specified:"
> /usr/bin/mkinitcpio:    error "invalid kernel specified: \`%s'" "$1"
So here we found the error message.

We then look at the function outputting that error message:
> resolve_kernver() {
>     [...]
>     kver "$kernel" && return
> 
>     error "invalid kernel specified: \`%s'" "$1"
> 
>     return 1
> }
So here if kver "$kernel" is successful, it returns without error.
Else it will print the error message we see, and return an error code.

Then we must look at why kver is doing that:
> $ pacman -Q -l mkinitcpio | awk '{print $2}' | grep -v '/$' | \
> xargs grep "^kver()"
> /usr/lib/initcpio/functions:kver() {

What kver seems very hackish:
> kver() {
>     # this is intentionally very loose. only ensure that we're
>     # dealing with some sort of string that starts with something
>     # resembling dotted decimal notation. remember that there's no
>     # requirement for CONFIG_LOCALVERSION to be set.
>     local kver re='^[[:digit:]]+(\.[[:digit:]]+)+'
> 
>     # scrape the version out of the kernel image. locate the offset
>     # to the version string by reading 2 bytes out of image at at
>     # address 0x20E. this leads us to a string of, at most, 128 bytes.
>     # read the first word from this string as the kernel version.
>     local offset=$(hexdump -s 526 -n 2 -e '"%0d"' "$1")
>     [[ $offset = +([0-9]) ]] || return 1
> 
>     read kver _ < \
>         <(dd if="$1" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null)
> 
>     [[ $kver =~ $re ]] || return 1
> 
>     printf '%s' "$kver"
> }
It will get the kernel version from the image binary with dd!

On x86_64 we have:
> $ file /boot/vmlinuz-linux-libre 
> /boot/vmlinuz-linux-libre: Linux kernel x86 boot executable bzImage, version 4.19.2-gnu-1 (builduser at parabola) #1 SMP PREEMPT Thu Nov 15 21:43:03 UTC 2018, RO-rootFS, swap_dev 0x5, Normal VGA

On i686 we have:
> $ file /boot/vmlinuz-linux-libre
> /boot/vmlinuz-linux-libre: Linux kernel x86 boot executable bzImage, version 4.19.2-gnu-1 (builduser at parabola) #1 SMP PREEMPT Thu Nov 15 21:40:26 UTC 2018, RO-rootFS, swap_dev 0x4, Normal VGA

And on armv7h we have:
> $ file /boot/vmlinuz-linux-libre
> /boot/vmlinuz-linux-libre: Linux kernel ARM boot executable zImage (little-endian)

However you have something very different on ppc64le:
> $ file /boot/vmlinuz-linux-libre
> /boot/vmlinuz-linux-libre: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, 
> BuildID[sha1]=e46dcfc7b63e2215489877ce6e00902f8760fa01, not stripped

So you don't have several choices here:
- Add support for more image formats. Here elf is easier to work with
  as you might be able to extract the version from its symbol table,
  assuming that the symbol table doesn't get stripped somehow.
- If possible build a zImage (make zImage) and additionally detect the
  image format and error if it's not in the right format (zImage) with
  a better error message than the "==> ERROR: invalid kernel specified:
  `/boot/vmlinuz-linux-libre`.
  Maybe instead tell the user that the kernel has to be in zImage
  format. Something like:
> /boot/vmlinuz-linux-libre has an invalid kernel image format (ELF).
> Supported formats: zImage
  or if the format is unknown:
> /boot/vmlinuz-linux-libre has an unknown kernel image format.
> Supported formats: zImage

Denis.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.parabola.nu/pipermail/dev/attachments/20181127/ce7f8824/attachment.sig>


More information about the Dev mailing list