Fishwaldo / sophgo-sg200x-debian

Debian Image for SG200x based boards such as Milk Duo256/DuoS and Sipeed LicheeRVNano
98 stars 24 forks source link

build error #4

Closed flyingcys closed 6 months ago

flyingcys commented 6 months ago

I reported an error by running the script

$ ./build_docker.sh [+] Building 0.1s (9/9) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.40kB 0.0s => [internal] load metadata for docker.io/library/debian:sid 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build context 0.0s => => transferring context: 1.49kB 0.0s => [builder 1/2] FROM docker.io/library/debian:sid 0.0s => CACHED [builder 2/2] RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install -y --no-install-recommends 0.0s => CACHED [build_image 1/2] WORKDIR /builder 0.0s => CACHED [build_image 2/2] ADD scripts/ /builder/ 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:9125cbb44f59b0c7ab4cf66587e965ab12b015192bfe6cb74fb2492b007d04db 0.0s => => naming to docker.io/library/builder

$ ./build_image.sh Board: duos Image Addons: "usb-gadget" "aic8800-firmware" "ethernet-leds" "usb-switch" Packages: ca-certificates debian-archive-keyring dosfstools binutils file tree sudo bash-completion u-boot-menu openssh-server network-manager dnsmasq-base libpam-systemd ppp libengine-pkcs11-openssl iptables systemd-timesyncd vim usbutils parted exfatprogs systemd-sysv i2c-tools net-tools ethtool avahi-utils sudo gnupg rsync gpiod duo-pinmux wireless-regdb wpasupplicant cvi-pinmux-cv181x

Preparing Image for duos

rm: cannot remove '/build//usb-gadget-stamp': No such file or directory rm: cannot remove '/build//aic8800-firmware-stamp': No such file or directory rm: cannot remove '/build//ethernet-leds-stamp': No such file or directory rm: cannot remove '/build//usb-switch-stamp': No such file or directory make: [Makefile:194: /build//image-prepare-stamp] Error 1 (ignored) Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). OK I: automatically chosen mode: root W: binfmt_misc not found in /proc/mounts -- not mounted? update-binfmts: warning: qemu-riscv64 not in database of installed binary formats. update-binfmts: exiting due to previous errors W: qemu-riscv64 is not a supported binfmt name E: riscv64 can neither be executed natively nor via qemu user emulation with binfmt_misc make: *** [Makefile:198: /build//image-prepare-stamp] Error 2

I get the same error when running through docker

$ docker run --privileged -it --rm -v ./configs/:/configs -v ./image:/output -v ./scripts/:/builder builder /bin/bash root@09de6810c9e1:/builder# ls Dockerfile Makefile addons deb genimage.cfg python setup_rootfs.sh root@09de6810c9e1:/builder# make BOARD=duos image Board: duos Image Addons: "usb-gadget" "aic8800-firmware" "ethernet-leds" "usb-switch" Packages: ca-certificates debian-archive-keyring dosfstools binutils file tree sudo bash-completion u-boot-menu openssh-server network-manager dnsmasq-base libpam-systemd ppp libengine-pkcs11-openssl iptables systemd-timesyncd vim usbutils parted exfatprogs systemd-sysv i2c-tools net-tools ethtool avahi-utils sudo gnupg rsync gpiod duo-pinmux wireless-regdb wpasupplicant cvi-pinmux-cv181x

Preparing Image for duos

rm: cannot remove '/build//usb-gadget-stamp': No such file or directory rm: cannot remove '/build//aic8800-firmware-stamp': No such file or directory rm: cannot remove '/build//ethernet-leds-stamp': No such file or directory rm: cannot remove '/build//usb-switch-stamp': No such file or directory make: [Makefile:194: /build//image-prepare-stamp] Error 1 (ignored) Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). OK I: automatically chosen mode: root W: binfmt_misc not found in /proc/mounts -- not mounted? update-binfmts: warning: qemu-riscv64 not in database of installed binary formats. update-binfmts: exiting due to previous errors W: qemu-riscv64 is not a supported binfmt name E: riscv64 can neither be executed natively nor via qemu user emulation with binfmt_misc make: *** [Makefile:198: /build//image-prepare-stamp] Error 2

Fishwaldo commented 6 months ago

W: binfmt_misc not found in /proc/mounts -- not mounted? the machine you are building on does not have binfmt support enabled in the kernel (or the module is not loaded)

thats required for final stage of building the image.

Fishwaldo commented 6 months ago

This should be in your /proc/mounts if support is available

binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
Sfinx commented 5 months ago

Same here:

podman run --privileged -it --rm -v ./configs/:/configs -v ./image:/output ghcr.io/fishwaldo/sophgo-sg200x-debian:master make BOARD=duos image

WARN[0000] Failed to decode the keys ["storage.options.override_kernel_check"] from "/etc/containers/storage.conf". 
WARN[0000] Failed to decode the keys ["storage.options.ostree_repo"] from "/home/xyz/.config/containers/storage.conf". 
WARN[0000] Failed to decode the keys ["storage.options.override_kernel_check"] from "/etc/containers/storage.conf". 
WARN[0000] Failed to decode the keys ["storage.options.ostree_repo"] from "/home/xyz/.config/containers/storage.conf". 
Trying to pull ghcr.io/fishwaldo/sophgo-sg200x-debian:master...
Getting image source signatures
Copying blob a79fdf356ad4 done  
Copying blob e0b3d09a7eeb done  
Copying blob 7198be8cec75 done  
Copying blob 0c42f1d49800 done  
Copying config 2160c3826a done  
Writing manifest to image destination
Storing signatures
Board: duos
Image Addons: "usb-gadget" "aic8800-firmware" "ethernet-leds" "usb-switch" "hciattach-service"
Packages: ca-certificates debian-archive-keyring dosfstools binutils file tree sudo bash-completion u-boot-menu openssh-server network-manager dnsmasq-base libpam-systemd ppp libengine-pkcs11-openssl iptables systemd-timesyncd vim usbutils parted exfatprogs systemd-sysv i2c-tools net-tools ethtool avahi-utils sudo gnupg rsync gpiod u-boot-tools libubootenv-tool duo-pinmux wireless-regdb wpasupplicant cvi-pinmux-cv181x bluez

Preparing Image for duos

rm: cannot remove '/build//usb-gadget-stamp': No such file or directory
rm: cannot remove '/build//aic8800-firmware-stamp': No such file or directory
rm: cannot remove '/build//ethernet-leds-stamp': No such file or directory
rm: cannot remove '/build//usb-switch-stamp': No such file or directory
rm: cannot remove '/build//hciattach-service-stamp': No such file or directory
make: [Makefile:197: /build//image-prepare-stamp] Error 1 (ignored)
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
I: automatically chosen mode: root
W: binfmt_misc not found in /proc/mounts -- not mounted?
update-binfmts: warning: qemu-riscv64 not in database of installed binary formats.
update-binfmts: exiting due to previous errors
W: qemu-riscv64 is not a supported binfmt name
E: riscv64 can neither be executed natively nor via qemu user emulation with binfmt_misc
make: *** [Makefile:201: /build//image-prepare-stamp] Error 2

The Ubuntu 22.04 system were this is running definitely has the riscv64 binfmt support

update-binfmts --display qemu-riscv64
qemu-riscv64 (enabled):
     package = qemu-user-static
        type = magic
      offset = 0
       magic = \x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00
        mask = \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
 interpreter = /usr/libexec/qemu-binfmt/riscv64-binfmt-P
    detector = 
grep binfmt_misc /proc/mounts 

systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=2941 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
cat > hello.c << EOF

#include <stdio.h>
int main(void) { return printf("Hello world!\n"); }
EOF

riscv64-linux-gnu-gcc-12 -static  -o hello hello.c

file hello
hello: ELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), statically linked, BuildID[sha1]=4a53730097cb076a556e46bcb42e6201b0f45871, for GNU/Linux 4.15.0, not stripped

./hello 
Hello world!

Seems like something is wrong inside container

Fishwaldo commented 5 months ago

In future please open a new issue.

The image is working for me and the GitHub Actions. Can you start the image with /bin/sh instead of 'make BOARD....' and check /proc/mounts inside the image instead.

Sfinx commented 5 months ago

It is mounted inside:

podman run --privileged -it --rm -v ./configs/:/configs -v ./image:/output ghcr.io/fishwaldo/sophgo-sg200x-debian:master bash
WARN[0000] Failed to decode the keys ["storage.options.override_kernel_check"] from "/etc/containers/storage.conf". 
WARN[0000] Failed to decode the keys ["storage.options.ostree_repo"] from "/home/xyz/.config/containers/storage.conf". 
root@0e50bea04563:/builder# grep binfmt /proc/mounts 
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
root@0e50bea04563:/builder# make BOARD=duos image
Board: duos
Image Addons: "usb-gadget" "aic8800-firmware" "ethernet-leds" "usb-switch" "hciattach-service"
Packages: ca-certificates debian-archive-keyring dosfstools binutils file tree sudo bash-completion u-boot-menu openssh-server network-manager dnsmasq-base libpam-systemd ppp libengine-pkcs11-openssl iptables systemd-timesyncd vim usbutils parted exfatprogs systemd-sysv i2c-tools net-tools ethtool avahi-utils sudo gnupg rsync gpiod u-boot-tools libubootenv-tool duo-pinmux wireless-regdb wpasupplicant cvi-pinmux-cv181x bluez

Preparing Image for duos

rm: cannot remove '/build//usb-gadget-stamp': No such file or directory
rm: cannot remove '/build//aic8800-firmware-stamp': No such file or directory
rm: cannot remove '/build//ethernet-leds-stamp': No such file or directory
rm: cannot remove '/build//usb-switch-stamp': No such file or directory
rm: cannot remove '/build//hciattach-service-stamp': No such file or directory
make: [Makefile:197: /build//image-prepare-stamp] Error 1 (ignored)
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
I: automatically chosen mode: root
update-binfmts: warning: qemu-riscv64 not in database of installed binary formats.
update-binfmts: exiting due to previous errors
W: qemu-riscv64 is not a supported binfmt name
E: riscv64 can neither be executed natively nor via qemu user emulation with binfmt_misc
make: *** [Makefile:201: /build//image-prepare-stamp] Error 2
root@0e50bea04563:/builder# 
Sfinx commented 5 months ago

I guess this is the reason:

root@0e50bea04563:/builder# ls -l /proc/sys/fs/binfmt_misc/
total 0
-rw-r--r-- 1 root root 0 May 27 07:18 python3.11
--w------- 1 root root 0 May 27 07:18 register
-rw-r--r-- 1 root root 0 May 27 07:18 status
root@0e50bea04563:/builder# 

There no entries for qemu-* inside container. But the host system has them

Fishwaldo commented 5 months ago

Mmdebootstrap sets up the qemu emulation so in a shell you won't see an entry for it till it's run.

But you could try a 'make BOARD=...' command from the shell in the container and after it fails, see if anything changes afterwards?

Or try your compile test in the image?

It's strange, as the GitHub actions is using Ubuntu 22.04 to build the images so potentially something with your setup? Any errors in logs or some extra security hardening (apparmor/selinux policy?)

image

Sfinx commented 5 months ago

Sure, first I've did - started container with bash and manually (with make BOARD=...) checked that error is coming from mmdebootstrap. The only difference from stock Ubuntu 22.04 is that I'm using self compiled qemu 9.x which is installed in /opt/qemu as the stock 22.04 qemu is ancient for me. Ok, will wait untill 24.04 update will be released and return to this again

Fishwaldo commented 5 months ago

The only difference from stock Ubuntu 22.04 is that I'm using self compiled qemu 9.x which is installed in /opt/qemu as the stock 22.04 qemu is ancient for me

That might be it? On the Host, it points to /opt/qemu but that doesn't exist inside the container

what happens if you make a symlink in the container from the /opt/qemu path to the "real" qemu in the image (/usr/bin/qemu-riscv64-static)

Sfinx commented 5 months ago

I guess that container is using its own qemu binaries:

root@514b808d5bd8:/builder# which qemu-riscv64-static 
/usr/bin/qemu-riscv64-static
root@514b808d5bd8:/builder# ls -l /usr/bin/qemu-riscv64-static
-rwxr-xr-x 1 root root 11583688 May 20 13:14 /usr/bin/qemu-riscv64-static
root@514b808d5bd8:/builder# 

I've tried to run container with "-v /opt/qemu:/opt/qemu" with no success too.

UQuark commented 5 months ago

For anyone experiencing this issue, check that binfmt_misc is present in /proc/mounts and run docker run --privileged --rm tonistiigi/binfmt --install all