katyo / zephyr-rtos.nix

Battle-tested nix env for Zephyr RTOS developers
12 stars 0 forks source link

Fail to run QEMU #1

Closed otavio closed 10 months ago

otavio commented 10 months ago

Using the following flake:

{
  inputs = {
    nixpkgs.url = "nixpkgs/23.05";
    flake-utils.url = "github:numtide/flake-utils";

    zephyr-rtos = {
      url = "github:katyo/zephyr-rtos.nix";
      flake = false;
    };
  };

  outputs = { self, ... }@inputs: inputs.flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
    let
      pkgs = import inputs.nixpkgs { inherit system; };
      zephyr-rtos = {
        shell = { toolchains, inputs }: import "${self.inputs.zephyr-rtos}/shell.nix" {
          inherit toolchains inputs;

          pkgs = import "${self.inputs.zephyr-rtos}/packages.nix" { inherit pkgs; };
        };
      };
    in
    {
      devShells.default = zephyr-rtos.shell {
        toolchains = [ "arm-zephyr-eabi" "x86_64-zephyr-elf" ];
        inputs = with pkgs; [
          addlicense
        ];
      };
    });
}

When running QEMU it fails with:

-- west build: running target run
[0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: qemu32,+nx,+pae
/nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-i386: /nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/lib/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/libresolv.so.2)
/nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-i386: /nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/lib/libc.so.6: version `GLIBC_2.34' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/libresolv.so.2)
/nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-i386: /nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/lib/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/libdl.so.2)
/nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-i386: /nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/lib/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/librt.so.1)
FAILED: zephyr/CMakeFiles/run_qemu .../build/zephyr/CMakeFiles/run_qemu
cd .../build && /nix/store/smk2z7gmwik5p90w0c0z7b0ilgg39c6s-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-i386 -m 4 -cpu qemu32,+nx,+pae -machine q35 -device isa-debug-exit,iobase=0xf4,iosize=0x04 -no-reboot -nographic -no-acpi -net none -pidfile qemu.pid -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -icount shift=5,align=off,sleep=off -rtc clock=vm -kernel .../build/zephyr/zephyr.elf
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /nix/store/fic9avx8yabwb3ib8m49ld3kq9fkwwwd-cmake-3.25.3/bin/cmake --build .../build --target run
otavio commented 10 months ago

Similar error happens for native_posix:

% west build -b native_posix app
[1/1] Linking C executable zephyr/zephyr.elf
FAILED: zephyr/zephyr.elf zephyr/zephyr_pre0.map zephyr/zephyr.map zephyr/zephyr.stat zephyr/zephyr.exe .../build/zephyr/zephyr_pre0.map .../build/zephyr/zephyr.map .../build/zephyr/zephyr.stat .../build/zephyr/zephyr.exe
: && ccache /nix/store/s386mlg3183v0dv7flbfgrn9sx08bv8q-gcc-wrapper-12.2.0/bin/gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr.elf  zephyr/CMakeFiles/offsets.dir/./arch/posix/core/offsets/offsets.c.obj  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=.../build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/arch/posix/core/libarch__posix__core.a  zephyr/soc/soc/posix/inf_clock/libsoc__posix__inf_clock.a  zephyr/boards/posix/native_posix/libboards__posix__native_posix.a  zephyr/drivers/adc/libdrivers__adc.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/counter/libdrivers__counter.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/led/libdrivers__led.a  zephyr/drivers/timer/libdrivers__timer.a  zephyr/drivers/watchdog/libdrivers__watchdog.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L.../build/zephyr  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -Wl,-no-pie  -m32  -ldl  -pthread  -lm && cd .../build/zephyr && /nix/store/fic9avx8yabwb3ib8m49ld3kq9fkwwwd-cmake-3.25.3/bin/cmake -E true && cd .../build/zephyr && /nix/store/fic9avx8yabwb3ib8m49ld3kq9fkwwwd-cmake-3.25.3/bin/cmake -E copy zephyr_pre0.map zephyr.map && /nix/store/s386mlg3183v0dv7flbfgrn9sx08bv8q-gcc-wrapper-12.2.0/bin/readelf -e zephyr.elf > zephyr.stat && /nix/store/fic9avx8yabwb3ib8m49ld3kq9fkwwwd-cmake-3.25.3/bin/cmake -E copy zephyr.elf zephyr.exe && /nix/store/95cxzy2hpizr23343b8bskl4yacf4b3l-python3-3.10.11/bin/python3.10 /home/otavio/src/customers/freedom/smart-charger/zephyr/scripts/build/check_init_priorities.py --build-dir .../build/zephyr/.. --edt-pickle .../build/zephyr/edt.pickle
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libdl.so when searching for -ldl
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libm.so when searching for -lm
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libpthread.so when searching for -lpthread
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libc.so when searching for -lc
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: app/libapp.a(charger.c.obj): in function `charger_init':
.../app/src/charger.c:84: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: .../app/src/charger.c:85: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: app/libapp.a(charger.c.obj): in function `transit':
.../app/src/charger.c:103: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: .../app/src/charger.c:111: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: .../app/src/charger.c:119: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: app/libapp.a(charger.c.obj):.../app/src/charger.c:127: more undefined references to `__device_dts_ord_18' follow
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /nix/store/fic9avx8yabwb3ib8m49ld3kq9fkwwwd-cmake-3.25.3/bin/cmake --build .../build
katyo commented 10 months ago

@otavio Qemu support needs to be fixed but native_posix already supported.

This works fine for me:

$ west build -p auto -b native_posix zephyr/samples/hello_world
-- west build: making build dir /home/kayo/devel/nix/zephyr-rtos.nix/z1/build pristine
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/kayo/devel/nix/zephyr-rtos.nix/z1/zephyr/samples/hello_world
-- CMake version: 3.25.3
-- Found Python3: /nix/store/bc45k1n0pkrdkr3xa6w84w1xhkl1kkyp-python3-3.10.12/bin/python3.10 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: /home/kayo/.cache/zephyr
-- Zephyr version: 3.4.99 (/home/kayo/devel/nix/zephyr-rtos.nix/z1/zephyr)
-- Found west (found suitable version "1.0.0", minimum required is "0.14.0")
-- Board: native_posix
-- Found host-tools: zephyr 0.16.1 (/nix/store/mr7rkr1ivfq39rhkp9i7mgjppk5n45jx-zephyr-sdk-0.16.1/zephyr-sdk)
-- Found toolchain: host (gcc/ld)
-- Found Dtc: /nix/store/mr7rkr1ivfq39rhkp9i7mgjppk5n45jx-zephyr-sdk-0.16.1/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6")
-- Found BOARD.dts: /home/kayo/devel/nix/zephyr-rtos.nix/z1/zephyr/boards/posix/native_posix/native_posix.dts
-- Generated zephyr.dts: /home/kayo/devel/nix/zephyr-rtos.nix/z1/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /home/kayo/devel/nix/zephyr-rtos.nix/z1/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: /home/kayo/devel/nix/zephyr-rtos.nix/z1/build/zephyr/dts.cmake
Parsing /home/kayo/devel/nix/zephyr-rtos.nix/z1/zephyr/Kconfig
Loaded configuration '/home/kayo/devel/nix/zephyr-rtos.nix/z1/zephyr/boards/posix/native_posix/native_posix_defconfig'
Merged configuration '/home/kayo/devel/nix/zephyr-rtos.nix/z1/zephyr/samples/hello_world/prj.conf'
Configuration saved to '/home/kayo/devel/nix/zephyr-rtos.nix/z1/build/zephyr/.config'
Kconfig header saved to '/home/kayo/devel/nix/zephyr-rtos.nix/z1/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: /nix/store/nk76jlw6la3rd4a5zxhfhcsbj8g36cq6-gcc-wrapper-12.2.0/bin/ld.bfd (found version "2.40")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /nix/store/nk76jlw6la3rd4a5zxhfhcsbj8g36cq6-gcc-wrapper-12.2.0/bin/gcc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kayo/devel/nix/zephyr-rtos.nix/z1/build
-- west build: building application
[1/90] Preparing syscall dependency handling

[2/90] Generating include/generated/version.h
-- Zephyr version: 3.4.99 (/home/kayo/devel/nix/zephyr-rtos.nix/z1/zephyr), build: zephyr-v3.4.0-3243-g0c5571004074
[90/90] Linking C executable zephyr/zephyr.elf
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/yrzxyl3mwnriayakj75cgjn2phzha3hz-glibc-multi-2.37-8/lib/libdl.so при поиске -ldl
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/yrzxyl3mwnriayakj75cgjn2phzha3hz-glibc-multi-2.37-8/lib/libm.so при поиске -lm
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/igvcr741p37wask1l0wshsps1jq9flrc-gcc-12.2.0-lib/lib64/libgcc_s.so.1 при поиске libgcc_s.so.1
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/igvcr741p37wask1l0wshsps1jq9flrc-gcc-12.2.0-lib/lib64/libgcc_s.so.1 при поиске libgcc_s.so.1
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/yrzxyl3mwnriayakj75cgjn2phzha3hz-glibc-multi-2.37-8/lib/libpthread.so при поиске -lpthread
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/yrzxyl3mwnriayakj75cgjn2phzha3hz-glibc-multi-2.37-8/lib/libc.so при поиске -lc
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/igvcr741p37wask1l0wshsps1jq9flrc-gcc-12.2.0-lib/lib64/libgcc_s.so.1 при поиске libgcc_s.so.1
/nix/store/zkjq96ik8cbv6ijh1lylnkk2bni9qvas-binutils-2.40/bin/ld.bfd: пропускается несовместимый /nix/store/igvcr741p37wask1l0wshsps1jq9flrc-gcc-12.2.0-lib/lib64/libgcc_s.so.1 при поиске libgcc_s.so.1
(.venv)

$ west build -t run
-- west build: running target run
[0/1] cd /home/kayo/devel/nix/zephyr-rtos.nix/z1/build && /home/kayo/devel/nix/zephyr-rtos.nix/z1/build/zephyr/zephyr.exe
*** Booting Zephyr OS build zephyr-v3.4.0-3243-g0c5571004074 ***
Hello World! native_posix

^C
Stopped at 6.990s
ninja: build stopped: interrupted by user.
(.venv)

Looks like you have problems with your application:

/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: app/libapp.a(charger.c.obj): in function `charger_init':
.../app/src/charger.c:84: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: .../app/src/charger.c:85: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: app/libapp.a(charger.c.obj): in function `transit':
.../app/src/charger.c:103: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: .../app/src/charger.c:111: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: .../app/src/charger.c:119: undefined reference to `__device_dts_ord_18'
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: app/libapp.a(charger.c.obj):.../app/src/charger.c:127: more undefined references to `__device_dts_ord_18' follow

Seems you have missing some device driver.

katyo commented 10 months ago

@otavio I have fixed qemu support. Please try it again.

otavio commented 10 months ago

QEMU support is functioning perfectly, but native_posix is still experiencing issues. I am utilizing nixpkgs 23.05 within the flake, while my host is running on unstable.

otavio commented 10 months ago

I stand corrected, it did indeed work. Please see the evidence.

[1/90] Preparing syscall dependency handling
[2/90] Generating include/generated/version.h
-- Zephyr version: 3.4.99 (/home/otavio/src/customers/freedom/smart-charger/zephyr), build: zephyr-v3.4.0-3229-g0df085bb36f4
[90/90] Linking C executable zephyr/zephyr.elf
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libdl.so when searching for -ldl
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libm.so when searching for -lm
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libpthread.so when searching for -lpthread
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/rrp5h6hmrzn6xx4mmq1lzrrqij548gjk-glibc-multi-2.37-8/lib/libc.so when searching for -lc
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/nix/store/22p5nv7fbxhm06mfkwwnibv1nsz06x4b-binutils-2.40/bin/ld.bfd: skipping incompatible /nix/store/jjpzav990cgngqsr2awlngr3hw6mlxnl-gcc-12.2.0-lib/lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
west build -p auto -b native_posix zephyr/samples/hello_world  10.75s user 2.66s system 349% cpu 3.834 total
-- west build: running target run
[0/1] cd .../build && .../build/zephyr/zephyr.exe
*** Booting Zephyr OS build zephyr-v3.4.0-3229-g0df085bb36f4 ***
Hello World! native_posix