diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6945cee86..ff2ceb8b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -99,8 +99,18 @@ jobs: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 sudo update-alternatives --set cc /usr/bin/gcc + # Adding the i386 architecture above makes apt remove 206 amd64 + # packages, pkgconf among them. Without pkg-config, Makefile.common + # does not find libelf, HAVE_LIBELF stays undefined, and the binary + # cannot load any firmware. + sudo apt-get install -y pkg-config - name: CI-Build run: | + # libelf-dev:i386 puts libelf.pc under /usr/lib/i386-linux-gnu, + # where pkg-config does not look by default. Without this, + # HAVE_LIBELF stays undefined and the 32 bit binary answers + # "ELF format is not supported by this build" for every firmware. + export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig make V=1 RELEASE=1 mkdir simavr_installed make install RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..814650a6d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,664 @@ +name: Release binaries + +# build.yml and this file have different jobs. build.yml checks out +# buserror/simavr and asks whether upstream still builds everywhere. This one +# builds THIS repository -- the commit that triggered the run -- and ships what +# comes out. That is what makes a release reproducible: the state is the tag in +# this fork, not a moving ref into somebody else's repository. It also means our +# own files, check-floor.sh above all, are simply there. +# +# Started by hand, it builds all eight and attaches nothing: the upload at the +# end only happens when a release triggered the run. + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + build-win64: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - uses: actions/checkout@v6 + - name: Set up MSYS2 (UCRT64) + uses: msys2/setup-msys2@v2 + with: + msystem: UCRT64 + update: true + install: > + base-devel + mingw-w64-ucrt-x86_64-gcc + mingw-w64-ucrt-x86_64-make + mingw-w64-ucrt-x86_64-libelf + mingw-w64-ucrt-x86_64-pkgconf + mingw-w64-ucrt-x86_64-avr-toolchain + - name: Build + run: | + make build-simavr build-tests + mkdir simavr_installed + make install-simavr DESTDIR=$(pwd)/simavr_installed/ + mv simavr_installed/bin/simavr simavr_installed/bin/simavr.exe + file simavr_installed/bin/* + ldd simavr_installed/bin/simavr.exe + - name: Tests + run: | + cd tests + make run_tests + - name: Bundle what the user would otherwise need + run: | + # No rpath on Windows, but the loader looks in the directory of the + # exe first, so the MSYS2 DLLs go there. Without them the archive only + # runs on a machine that has MSYS2 installed. + for d in $(ldd simavr_installed/bin/simavr.exe | awk '/ucrt64/ {print $3}'); do + cp -v "$d" simavr_installed/bin/ + done + ldd simavr_installed/bin/simavr.exe + - name: does it actually simulate? + # Loads an ELF file and runs it -- which --list-cores does not, and which + # is what libelf is there for. The firmware ends by itself: returning from + # main lands in avr-libc's cli + rjmp .-2, and simavr treats that as a + # reason to quit gracefully. A zero status is therefore the whole + # assertion; the timeout only catches a build that spins. + run: timeout 60 simavr_installed/bin/simavr.exe -m atmega328p -f 16000000 ci/smoke-atmega328p.elf + - name: what it demands of the system + # UCRT64 links the Universal CRT on purpose, and that is a Windows 10 + # floor -- hence --ucrt-ok, which lets the check report it instead of + # failing on it. + run: ./check-floor.sh simavr_installed/bin/simavr.exe 10.0 --ucrt-ok + - name: Pack + run: tar -czf simavr-windows_amd64.tar.gz -C simavr_installed . + - uses: actions/upload-artifact@v6 + with: + name: windows_amd64 + path: simavr-windows_amd64.tar.gz + + build-win32: + # The old Java Arduino IDE picks the 32-bit package when it downloads a + # tool, no matter what the machine underneath could run, so this archive is + # what every 1.8.x user ends up with -- not a courtesy for old hardware. + # MSYS2 has no 32-bit counterpart to UCRT64: MINGW32 is its only i686 + # environment, so the runtime here is the old msvcrt.dll whether we want it + # or not. That costs little, because mingw-w64 replaces its weakest part + # (stdio) with its own and simavr asks little else of it. The mingw32 + # repository is no longer actively rebuilt -- its libelf is from 2023 -- + # but it is still served and has everything this job needs. + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - uses: actions/checkout@v6 + - name: Set up MSYS2 (MINGW32) + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW32 + update: true + install: > + base-devel + mingw-w64-i686-gcc + mingw-w64-i686-make + mingw-w64-i686-pkgconf + - name: libelf, which the mingw32 repository no longer carries + # MSYS2 has stopped building 32-bit packages, and libelf is one of the + # casualties: pacman answers "target not found" for + # mingw-w64-i686-libelf, while the last build -- 0.8.13-7 from January + # 2023 -- still sits on the mirror. Installing that file directly is + # enough; the package has no dependencies, it is a header and a library, + # and libelf itself has not changed since 2013. If the mirror ever drops + # the file, the fallback is to build libelf from source here, or to + # cross-compile the whole 32-bit client on Ubuntu the way avr-gdb does. + run: | + pacman -U --noconfirm https://mirror.msys2.org/mingw/mingw32/mingw-w64-i686-libelf-0.8.13-7-any.pkg.tar.zst + # The build decides by pkg-config whether it can read ELF files at + # all, so this has to answer -- otherwise simavr would come out + # without HAVE_LIBELF and only the smoke test would notice. + pkg-config --modversion libelf + - name: Build + # No build-tests and no run_tests here: both need an avr-gcc, and + # mingw32 has no avr-toolchain package to rely on. The smoke test below + # uses the firmware committed in ci/ and needs no toolchain at all. + run: | + make build-simavr + mkdir simavr_installed + make install-simavr DESTDIR=$(pwd)/simavr_installed/ + mv simavr_installed/bin/simavr simavr_installed/bin/simavr.exe + file simavr_installed/bin/* + ldd simavr_installed/bin/simavr.exe + - name: Bundle what the user would otherwise need + run: | + # As in the 64-bit job, only the prefix differs: MINGW32 keeps its + # DLLs in /mingw32 rather than /ucrt64. + for d in $(ldd simavr_installed/bin/simavr.exe | awk '/mingw32/ {print $3}'); do + cp -v "$d" simavr_installed/bin/ + done + ldd simavr_installed/bin/simavr.exe + - name: does it actually simulate? + # Same assertion as everywhere else: loading an ELF file is what libelf + # is there for, and the firmware ends by itself, so a zero status says + # the build works. The timeout only catches a build that spins. + run: timeout 60 simavr_installed/bin/simavr.exe -m atmega328p -f 16000000 ci/smoke-atmega328p.elf + - name: what it demands of the system + # Deliberately without --ucrt-ok: a MINGW32 build has no business + # importing the UCRT, and if it does, that is a finding rather than + # something to wave through. If this step fails on kernelbase.dll + # instead, the floor is Windows 7 and the number above is what has to + # change, not the check. + run: ./check-floor.sh simavr_installed/bin/simavr.exe 6.0 + - name: Pack + run: tar -czf simavr-windows_x86.tar.gz -C simavr_installed . + - uses: actions/upload-artifact@v6 + with: + name: windows_x86 + path: simavr-windows_x86.tar.gz + + build-lin64: + # Not ubuntu-latest. The glibc of the build machine becomes the floor for + # every user, and 24.04 would make that 2.39; 22.04 has 2.35. + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v6 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential make gcc-avr avr-libc libelf-dev patchelf + - name: Build + run: | + make build-simavr build-tests V=1 RELEASE=1 + mkdir simavr_installed + make install-simavr RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ + file simavr_installed/bin/* + patchelf --remove-needed ./libsimavr.so.1 simavr_installed/bin/simavr || true + patchelf --add-needed libsimavr.so.1 simavr_installed/bin/simavr + patchelf --set-rpath '$ORIGIN/../lib/' simavr_installed/bin/simavr + ldd simavr_installed/bin/* + simavr_installed/bin/simavr --list-cores || true + - name: Tests + run: | + cd tests + make run_tests + - name: Bundle what the user would otherwise need + run: | + # Where does libelf come from? A count under " T elf_" means it is + # linked into this library statically, one under " U elf_" means it is + # expected from outside -- and then it belongs in NEEDED as well. + nm -D --defined-only simavr_installed/lib/libsimavr.so.1 | grep -c " T elf_" || true + nm -D -u simavr_installed/lib/libsimavr.so.1 | grep -c " U elf_" || true + # Copy the libraries the user would otherwise have to install himself, next + # to libsimavr. libGL deliberately stays out: that one has to come from the + # user's graphics driver, not from us. + mkdir -p simavr_installed/lib + ldd simavr_installed/bin/simavr | awk '{print $1, $3}' | while read -r name path; do + case "$name" in + libelf.so*|libdwarf.so*|libz.so*|libglut.so*) [ -f "$path" ] && cp -Lv "$path" simavr_installed/lib/ ;; + esac + done + # A RUNPATH applies only to the object that carries it, not to what that object + # loads in turn. The one on the executable therefore does not help libsimavr + # find libelf, so every library gets its own. + find simavr_installed/lib -maxdepth 1 -type f -name '*.so*' -exec patchelf --set-rpath '$ORIGIN' {} \; + ldd simavr_installed/bin/simavr + for f in simavr_installed/lib/*.so*; do echo "-- $f"; ldd "$f"; done + ls -l simavr_installed/lib/ + - name: does it actually simulate? + # Loads an ELF file and runs it -- which --list-cores does not, and which + # is what libelf is there for. The firmware ends by itself: returning from + # main lands in avr-libc's cli + rjmp .-2, and simavr treats that as a + # reason to quit gracefully. A zero status is therefore the whole + # assertion; the timeout only catches a build that spins. + run: | + SMOKE="-m atmega328p -f 16000000 ci/smoke-atmega328p.elf" + if command -v timeout >/dev/null; then + timeout 60 simavr_installed/bin/simavr $SMOKE + else + simavr_installed/bin/simavr $SMOKE + fi + - name: what it demands of the system + # Both of them: libsimavr.so.1 ships as well and has glibc references of + # its own, so the floor is the higher of the two. + run: | + # Der Boden des Archivs ist das Maximum über alles, was darin liegt -- + # also auch über die gebündelten libelf und libz, die wir bisher nicht + # gemessen haben. Symlinks überspringt find, ihr Ziel kommt ohnehin dran. + # Nicht nach Namen und Rechten auswählen, sondern nach Inhalt: in lib/ + # liegt auch libsimavr.a, und ein ar-Archiv hat keine glibc-Ansprüche. + # Gemeint sind alle ELF-Objekte im Archiv, also fragen wir danach. + find simavr_installed/bin simavr_installed/lib -maxdepth 1 -type f -print0 | sort -z | + while IFS= read -r -d '' f; do + case "$(file -b "$f")" in + ELF*) ./check-floor.sh "$f" 2.34 ;; + *) echo "übersprungen (kein ELF): $f" ;; + esac + done + - name: Pack + run: tar -czf simavr-linux_x86_64.tar.gz -C simavr_installed . + - uses: actions/upload-artifact@v6 + with: + name: linux_x86_64 + path: simavr-linux_x86_64.tar.gz + + build-lin32: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v6 + - name: Install dependencies + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update + sudo apt-get install -y libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386 gcc-9:i386 binutils:i386 cpp-9:i386 libelf-dev:i386 gcc-avr avr-libc patchelf + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 10 + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 + sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 + sudo update-alternatives --set cc /usr/bin/gcc + # Der i386-Umbau oben entfernt 206 amd64-Pakete, pkgconf darunter. + # Ohne pkg-config findet Makefile.common libelf nicht, HAVE_LIBELF + # bleibt undefiniert, und das Binary kann keine Firmware laden. + sudo apt-get install -y pkg-config + - name: Build + run: | + # Makefile.common finds libelf through pkg-config, and libelf-dev:i386 + # puts its .pc file where the amd64 pkg-config does not look. Without + # this line HAVE_LIBELF stays undefined and sim_elf.c becomes the stub + # that answers "ELF format is not supported by this build" -- a simavr + # that cannot load firmware. That is what the smoke test caught. + export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig + pkg-config --cflags --libs libelf + make build-simavr V=1 RELEASE=1 + mkdir simavr_installed + make install-simavr RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ + file simavr_installed/bin/* + patchelf --remove-needed ./libsimavr.so.1 simavr_installed/bin/simavr || true + patchelf --add-needed libsimavr.so.1 simavr_installed/bin/simavr + patchelf --set-rpath '$ORIGIN/../lib/' simavr_installed/bin/simavr + ldd simavr_installed/bin/* + simavr_installed/bin/simavr --list-cores || true + - name: Bundle what the user would otherwise need + run: | + # Where does libelf come from? A count under " T elf_" means it is + # linked into this library statically, one under " U elf_" means it is + # expected from outside -- and then it belongs in NEEDED as well. + nm -D --defined-only simavr_installed/lib/libsimavr.so.1 | grep -c " T elf_" || true + nm -D -u simavr_installed/lib/libsimavr.so.1 | grep -c " U elf_" || true + # Copy the libraries the user would otherwise have to install himself, next + # to libsimavr. libGL deliberately stays out: that one has to come from the + # user's graphics driver, not from us. + mkdir -p simavr_installed/lib + ldd simavr_installed/bin/simavr | awk '{print $1, $3}' | while read -r name path; do + case "$name" in + libelf.so*|libdwarf.so*|libz.so*|libglut.so*) [ -f "$path" ] && cp -Lv "$path" simavr_installed/lib/ ;; + esac + done + # A RUNPATH applies only to the object that carries it, not to what that object + # loads in turn. The one on the executable therefore does not help libsimavr + # find libelf, so every library gets its own. + find simavr_installed/lib -maxdepth 1 -type f -name '*.so*' -exec patchelf --set-rpath '$ORIGIN' {} \; + ldd simavr_installed/bin/simavr + for f in simavr_installed/lib/*.so*; do echo "-- $f"; ldd "$f"; done + ls -l simavr_installed/lib/ + - name: does it actually simulate? + # Loads an ELF file and runs it -- which --list-cores does not, and which + # is what libelf is there for. The firmware ends by itself: returning from + # main lands in avr-libc's cli + rjmp .-2, and simavr treats that as a + # reason to quit gracefully. A zero status is therefore the whole + # assertion; the timeout only catches a build that spins. + run: | + SMOKE="-m atmega328p -f 16000000 ci/smoke-atmega328p.elf" + if command -v timeout >/dev/null; then + timeout 60 simavr_installed/bin/simavr $SMOKE + else + simavr_installed/bin/simavr $SMOKE + fi + - name: what it demands of the system + run: | + # Der Boden des Archivs ist das Maximum über alles, was darin liegt -- + # also auch über die gebündelten libelf und libz, die wir bisher nicht + # gemessen haben. Symlinks überspringt find, ihr Ziel kommt ohnehin dran. + # Nicht nach Namen und Rechten auswählen, sondern nach Inhalt: in lib/ + # liegt auch libsimavr.a, und ein ar-Archiv hat keine glibc-Ansprüche. + # Gemeint sind alle ELF-Objekte im Archiv, also fragen wir danach. + find simavr_installed/bin simavr_installed/lib -maxdepth 1 -type f -print0 | sort -z | + while IFS= read -r -d '' f; do + case "$(file -b "$f")" in + ELF*) ./check-floor.sh "$f" 2.34 ;; + *) echo "übersprungen (kein ELF): $f" ;; + esac + done + - name: Pack + run: tar -czf simavr-linux_i686.tar.gz -C simavr_installed . + - uses: actions/upload-artifact@v6 + with: + name: linux_i686 + path: simavr-linux_i686.tar.gz + + # The three arm jobs run emulated on a Raspberry Pi OS image. The image is + # pinned to a date, not to :latest -- otherwise the floor wanders with every + # image update and a release is not reproducible. 2023-05-03 is bullseye, + # glibc 2.31, and it stays that way. The names are the ones download_image.sh + # of the action accepts; guessing them has cost us a run before. + build-armv7l: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v6 + - uses: pguyot/arm-runner-action@v2 + with: + cpu: cortex-a7 + base_image: raspios_lite:2023-05-03 + copy_artifact_path: simavr-linux_armv7l.tar.gz + image_additional_mb: 1024 + commands: | + apt-get update + apt-get install -y build-essential make gcc-avr avr-libc libelf-dev patchelf file + make build-simavr build-tests V=1 RELEASE=1 + mkdir simavr_installed + make -j4 install-simavr RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ + file simavr_installed/bin/* + patchelf --remove-needed ./libsimavr.so.1 simavr_installed/bin/simavr || true + patchelf --add-needed libsimavr.so.1 simavr_installed/bin/simavr + patchelf --set-rpath '$ORIGIN/../lib/' simavr_installed/bin/simavr + ldd simavr_installed/bin/* + simavr_installed/bin/simavr --list-cores || true + # Copy the libraries the user would otherwise have to install himself, next + # to libsimavr. libGL deliberately stays out: that one has to come from the + # user's graphics driver, not from us. + mkdir -p simavr_installed/lib + ldd simavr_installed/bin/simavr | awk '{print $1, $3}' | while read -r name path; do + case "$name" in + libelf.so*|libdwarf.so*|libz.so*|libglut.so*) [ -f "$path" ] && cp -Lv "$path" simavr_installed/lib/ ;; + esac + done + # A RUNPATH applies only to the object that carries it, not to what that object + # loads in turn. The one on the executable therefore does not help libsimavr + # find libelf, so every library gets its own. + find simavr_installed/lib -maxdepth 1 -type f -name '*.so*' -exec patchelf --set-rpath '$ORIGIN' {} \; + ldd simavr_installed/bin/simavr + for f in simavr_installed/lib/*.so*; do echo "-- $f"; ldd "$f"; done + ls -l simavr_installed/lib/ + # Der Rauchtest muss hier drinnen laufen: auf dem Host + # ist dieses Binary nicht ausführbar. + timeout 300 simavr_installed/bin/simavr -m atmega328p -f 16000000 ci/smoke-atmega328p.elf + tar -czf simavr-linux_armv7l.tar.gz -C simavr_installed . + cd tests + make run_tests + - name: what it demands of the system + # On the host, not in the image: readelf reads ELF directly and does not + # care which architecture it is looking at. + run: | + mkdir -p unpacked + tar xzf simavr-linux_armv7l.tar.gz -C unpacked + # Nicht nach Namen und Rechten auswählen, sondern nach Inhalt: in lib/ + # liegt auch libsimavr.a, und ein ar-Archiv hat keine glibc-Ansprüche. + # Gemeint sind alle ELF-Objekte im Archiv, also fragen wir danach. + find unpacked/bin unpacked/lib -maxdepth 1 -type f -print0 | sort -z | + while IFS= read -r -d '' f; do + case "$(file -b "$f")" in + ELF*) ./check-floor.sh "$f" 2.28 ;; + *) echo "übersprungen (kein ELF): $f" ;; + esac + done + - uses: actions/upload-artifact@v6 + with: + name: linux_armv7l + path: simavr-linux_armv7l.tar.gz + + build-armv6l: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v6 + - uses: pguyot/arm-runner-action@v2 + with: + cpu: arm1176 + base_image: raspios_lite:2023-05-03 + copy_artifact_path: simavr-linux_armv6l.tar.gz + image_additional_mb: 1024 + commands: | + apt-get update + apt-get install -y build-essential make gcc-avr avr-libc libelf-dev patchelf file + make build-simavr build-tests V=1 RELEASE=1 + mkdir simavr_installed + make install-simavr RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ + file simavr_installed/bin/* + patchelf --remove-needed ./libsimavr.so.1 simavr_installed/bin/simavr || true + patchelf --add-needed libsimavr.so.1 simavr_installed/bin/simavr + patchelf --set-rpath '$ORIGIN/../lib/' simavr_installed/bin/simavr + ldd simavr_installed/bin/* + simavr_installed/bin/simavr --list-cores || true + # Copy the libraries the user would otherwise have to install himself, next + # to libsimavr. libGL deliberately stays out: that one has to come from the + # user's graphics driver, not from us. + mkdir -p simavr_installed/lib + ldd simavr_installed/bin/simavr | awk '{print $1, $3}' | while read -r name path; do + case "$name" in + libelf.so*|libdwarf.so*|libz.so*|libglut.so*) [ -f "$path" ] && cp -Lv "$path" simavr_installed/lib/ ;; + esac + done + # A RUNPATH applies only to the object that carries it, not to what that object + # loads in turn. The one on the executable therefore does not help libsimavr + # find libelf, so every library gets its own. + find simavr_installed/lib -maxdepth 1 -type f -name '*.so*' -exec patchelf --set-rpath '$ORIGIN' {} \; + ldd simavr_installed/bin/simavr + for f in simavr_installed/lib/*.so*; do echo "-- $f"; ldd "$f"; done + ls -l simavr_installed/lib/ + # Der Rauchtest muss hier drinnen laufen: auf dem Host + # ist dieses Binary nicht ausführbar. + timeout 300 simavr_installed/bin/simavr -m atmega328p -f 16000000 ci/smoke-atmega328p.elf + tar -czf simavr-linux_armv6l.tar.gz -C simavr_installed . + cd tests + make run_tests + - name: what it demands of the system + # --armv6-hardfloat is the assertion that keeps the Pi 1 and the Zero in: + # an armv7 build would run everywhere else and fail there, silently. + run: | + mkdir -p unpacked + tar xzf simavr-linux_armv6l.tar.gz -C unpacked + # wie oben: alles, was im Archiv liegt, nicht nur zwei Dateien + # Nicht nach Namen und Rechten auswählen, sondern nach Inhalt: in lib/ + # liegt auch libsimavr.a, und ein ar-Archiv hat keine glibc-Ansprüche. + # Gemeint sind alle ELF-Objekte im Archiv, also fragen wir danach. + find unpacked/bin unpacked/lib -maxdepth 1 -type f -print0 | sort -z | + while IFS= read -r -d '' f; do + case "$(file -b "$f")" in + ELF*) ./check-floor.sh "$f" 2.28 ;; + *) echo "übersprungen (kein ELF): $f" ;; + esac + done + ./check-floor.sh unpacked/bin/simavr 2.28 --armv6-hardfloat + - uses: actions/upload-artifact@v6 + with: + name: linux_armv6l + path: simavr-linux_armv6l.tar.gz + + build-aarch64: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v6 + - uses: pguyot/arm-runner-action@v2 + with: + cpu: cortex-a53 + base_image: raspios_lite_arm64:2023-05-03 + copy_artifact_path: simavr-linux_aarch64.tar.gz + image_additional_mb: 1024 + commands: | + apt-get update + apt-get install -y build-essential make gcc-avr avr-libc libelf-dev patchelf file + make build-simavr build-tests V=1 RELEASE=1 + mkdir simavr_installed + make -j4 install-simavr RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ + file simavr_installed/bin/* + patchelf --remove-needed ./libsimavr.so.1 simavr_installed/bin/simavr || true + patchelf --add-needed libsimavr.so.1 simavr_installed/bin/simavr + patchelf --set-rpath '$ORIGIN/../lib/' simavr_installed/bin/simavr + ldd simavr_installed/bin/* + simavr_installed/bin/simavr --list-cores || true + # Copy the libraries the user would otherwise have to install himself, next + # to libsimavr. libGL deliberately stays out: that one has to come from the + # user's graphics driver, not from us. + mkdir -p simavr_installed/lib + ldd simavr_installed/bin/simavr | awk '{print $1, $3}' | while read -r name path; do + case "$name" in + libelf.so*|libdwarf.so*|libz.so*|libglut.so*) [ -f "$path" ] && cp -Lv "$path" simavr_installed/lib/ ;; + esac + done + # A RUNPATH applies only to the object that carries it, not to what that object + # loads in turn. The one on the executable therefore does not help libsimavr + # find libelf, so every library gets its own. + find simavr_installed/lib -maxdepth 1 -type f -name '*.so*' -exec patchelf --set-rpath '$ORIGIN' {} \; + ldd simavr_installed/bin/simavr + for f in simavr_installed/lib/*.so*; do echo "-- $f"; ldd "$f"; done + ls -l simavr_installed/lib/ + # Der Rauchtest muss hier drinnen laufen: auf dem Host + # ist dieses Binary nicht ausführbar. + timeout 300 simavr_installed/bin/simavr -m atmega328p -f 16000000 ci/smoke-atmega328p.elf + tar -czf simavr-linux_aarch64.tar.gz -C simavr_installed . + cd tests + make run_tests + - name: what it demands of the system + run: | + mkdir -p unpacked + tar xzf simavr-linux_aarch64.tar.gz -C unpacked + # Nicht nach Namen und Rechten auswählen, sondern nach Inhalt: in lib/ + # liegt auch libsimavr.a, und ein ar-Archiv hat keine glibc-Ansprüche. + # Gemeint sind alle ELF-Objekte im Archiv, also fragen wir danach. + find unpacked/bin unpacked/lib -maxdepth 1 -type f -print0 | sort -z | + while IFS= read -r -d '' f; do + case "$(file -b "$f")" in + ELF*) ./check-floor.sh "$f" 2.17 ;; + *) echo "übersprungen (kein ELF): $f" ;; + esac + done + - uses: actions/upload-artifact@v6 + with: + name: linux_aarch64 + path: simavr-linux_aarch64.tar.gz + + build-darwin-x64: + # macos-latest is arm64; the Intel runner carries the -intel suffix. + runs-on: macos-15-intel + env: + # Without this clang targets the build machine, and on macos-15 the binary + # then refuses to start on anything older than macOS 15. Set for the whole + # job, because libsimavr and the executable have to agree. + MACOSX_DEPLOYMENT_TARGET: "10.15" + steps: + - uses: actions/checkout@v6 + - name: Install dependencies + run: | + HOMEBREW_NO_INSTALL_FROM_API=1 brew install make libelf patchelf + HOMEBREW_NO_INSTALL_FROM_API=1 brew tap osx-cross/avr + - name: Build + run: | + avr-gcc --version || true + clang --version + export CFLAGS="-DGL_SILENCE_DEPRECATION" + make -j4 build-simavr V=1 RELEASE=1 + mkdir simavr_installed + make -j4 install-simavr RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ + file simavr_installed/bin/* + otool -L simavr_installed/bin/* + simavr_installed/bin/simavr --list-cores || true + - name: does it actually simulate? + # Loads an ELF file and runs it -- which --list-cores does not, and which + # is what libelf is there for. The firmware ends by itself: returning from + # main lands in avr-libc's cli + rjmp .-2, and simavr treats that as a + # reason to quit gracefully. A zero status is therefore the whole + # assertion; the timeout only catches a build that spins. + run: | + SMOKE="-m atmega328p -f 16000000 ci/smoke-atmega328p.elf" + if command -v timeout >/dev/null; then + timeout 60 simavr_installed/bin/simavr $SMOKE + else + simavr_installed/bin/simavr $SMOKE + fi + - name: what it demands of the system + # Nothing is bundled on macOS and nothing needs to be: libelf and + # libsimavr are linked statically there, the binary names only + # libSystem. The check asserts exactly that, so the day a Homebrew path + # appears in otool -L, this step says so instead of shipping it. + run: ./check-floor.sh simavr_installed/bin/simavr 10.15 + - name: Pack + run: tar -czf simavr-darwin_x86_64.tar.gz -C simavr_installed . + - uses: actions/upload-artifact@v6 + with: + name: darwin_x86_64 + path: simavr-darwin_x86_64.tar.gz + + build-darwin-arm64: + runs-on: macos-15 + env: + MACOSX_DEPLOYMENT_TARGET: "11.0" + steps: + - uses: actions/checkout@v6 + - name: Install dependencies + run: | + HOMEBREW_NO_INSTALL_FROM_API=1 brew install make libelf patchelf + brew trust osx-cross/avr + HOMEBREW_NO_INSTALL_FROM_API=1 brew tap osx-cross/avr + HOMEBREW_NO_INSTALL_FROM_API=1 brew install avr-gcc@9 avr-binutils + - name: Build + run: | + export PATH="/usr/local/opt/avr-gcc@9/bin:$PATH" + avr-gcc --version || true + clang --version + export CFLAGS="-DGL_SILENCE_DEPRECATION" + make build-simavr build-tests V=1 RELEASE=1 + mkdir simavr_installed + make -j4 install-simavr RELEASE=1 DESTDIR=$(pwd)/simavr_installed/ + file simavr_installed/bin/* + otool -L simavr_installed/bin/* + simavr_installed/bin/simavr --list-cores || true + - name: Tests + run: | + cd tests + make run_tests + - name: does it actually simulate? + # Loads an ELF file and runs it -- which --list-cores does not, and which + # is what libelf is there for. The firmware ends by itself: returning from + # main lands in avr-libc's cli + rjmp .-2, and simavr treats that as a + # reason to quit gracefully. A zero status is therefore the whole + # assertion; the timeout only catches a build that spins. + run: | + SMOKE="-m atmega328p -f 16000000 ci/smoke-atmega328p.elf" + if command -v timeout >/dev/null; then + timeout 60 simavr_installed/bin/simavr $SMOKE + else + simavr_installed/bin/simavr $SMOKE + fi + - name: what it demands of the system + run: ./check-floor.sh simavr_installed/bin/simavr 11.0 + - name: Pack + run: tar -czf simavr-darwin_arm64.tar.gz -C simavr_installed . + - uses: actions/upload-artifact@v6 + with: + name: darwin_arm64 + path: simavr-darwin_arm64.tar.gz + + make-release: + needs: + - build-win64 + - build-win32 + - build-lin64 + - build-lin32 + - build-armv7l + - build-armv6l + - build-aarch64 + - build-darwin-x64 + - build-darwin-arm64 + runs-on: ubuntu-22.04 + permissions: + contents: write # the upload below writes to the release + steps: + - name: Collect the archives + uses: actions/download-artifact@v6 + with: + path: assets + merge-multiple: true + - name: What there is + run: ls -la assets/ + - name: Asset upload + # Only on a real release. Started by hand, everything above still runs + # and nothing is published -- that is the dry run. + if: ${{ github.event.release.tag_name != '' }} + uses: softprops/action-gh-release@v2 + with: + files: assets/* diff --git a/.gitignore b/.gitignore index 5495538cf..e218a2a1d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,8 @@ perf.data .bash_history compile_commands.json .cache + +# Die Firmware für den Rauchtest in der CI gehört ins Repository, anders als +# jedes andere .elf hier. Ohne diese Ausnahme nimmt git add sie nicht mit -- +# stillschweigend, was eine Weile kostet. +!ci/*.elf diff --git a/README.md b/README.md index c0360d4d9..aae7870d7 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,15 @@ Extras: graphically as “waveforms” with tools like _gtkwave_ (see below). * You can even source your own VCD files (for example from your logic analyzer) and feed them into your simulation. * There are a few examples of real life firmwares running on simavr, including OpenGL rendering of the display… -* There is support for _Arduino_, but no IDE integration +* There is some support for _Arduino_ + +## Integration: + +- Simavr is the default debugging tool for supported AVR MCUs in [*PlatformIO*](https://platformio.org). If you select a debug build without specifying the tool, simavr will be started. +- There is basic support to use simavr inside the [*Arduino IDE 2*](https://docs.arduino.cc/software/ide-v2/tutorials/getting-started/ide-v2-downloading-and-installing/) as part of the debugging solution [PyAvrOCD](https://pyavrocd.io). Simply install a [debug-enabled Arduino board package](https://pyavrocd.io/supporting-packages/) and choose the programmer `simavr`. If you now start the debugger, the simulator will be started. There is some basic support for assembly-level debugging and the `PERIPHERAL` pane provides access to the I/O registers. +- The [*Arduino Maker Workshop*](https://github.com/thelastoutpostworkshop/arduino-maker-workshop) VS Code extension integrates simavr as well, again via PyAvrOCD. Due to using a recent version of Cortex-Debug, instruction-level debugging, memory inspection, and peripheral register display, are all supported. +- Simavr is one of many simulators integrated into [PICSimLab](https://github.com/lcgamboa/picsimlab), a realtime emulator of diverse development boards with MPLABX/avr-gdb debugger integration. +- [Simutron](https://sourceforge.net/projects/simutron/) is a GUI for simavr. However, the project does not appear to be active. Documentation And Further Information ------------------------------------- diff --git a/check-floor.sh b/check-floor.sh new file mode 100755 index 000000000..d32b26bb7 --- /dev/null +++ b/check-floor.sh @@ -0,0 +1,156 @@ +#!/bin/bash +# +# Copied from the avr-gdb repository, where it started; keep the two in step by +# hand. The one difference is --ucrt-ok below. +# +# Reports what a finished client demands of the system it will run on, and fails +# if it demands more than it was allowed to. One script for all three platforms, +# because the question is the same everywhere and only the place to read the +# answer differs: +# +# ELF the highest glibc version referenced readelf -V +# Mach-O the deployment target vtool -show-build +# PE the DLLs and functions it imports objdump -p +# +# Linux is the only one of the three with no way to declare that floor in the +# build; it falls out of the distribution one builds on. Hence this script: what +# cannot be stated has to be measured. +# +# Reading works across architectures -- readelf parses ELF directly instead of +# going through a target backend -- so an armhf client can be checked on an x86 +# machine, which is what the arm job does. +# +# Usage: +# ./check-floor.sh [--armv6-hardfloat] +# +# ./check-floor.sh tool/avr-gdb 2.35 +# ./check-floor.sh tool/avr-gdb 2.31 --armv6-hardfloat +# ./check-floor.sh tool/avr-gdb 11.0 +# ./check-floor.sh tool/avr-gdb.exe 6.0 +# ./check-floor.sh bin/simavr.exe 10.0 --ucrt-ok + +set -eu + +BIN=${1:?usage: check-floor.sh [--armv6-hardfloat] [--ucrt-ok]} +FLOOR=${2:?usage: check-floor.sh [--armv6-hardfloat] [--ucrt-ok]} +FLAGS=" ${*:3} " + +has() { case "$FLAGS" in *" $1 "*) return 0 ;; *) return 1 ;; esac; } + +fail() { echo "::error::$*" >&2; echo "FAILED: $*" >&2; exit 1; } + +test -f "$BIN" || fail "no such file: $BIN" +echo "=== $BIN" +file "$BIN" +KIND=$(file -b "$BIN") + +case "$KIND" in + *ELF*) + echo "--- libraries it needs at start ---" + readelf -d "$BIN" | grep NEEDED || echo "(none -- statically linked)" + readelf -l "$BIN" | grep -i interpreter || echo "(no interpreter)" + + echo "--- glibc ---" + MAX=$(readelf -V "$BIN" | grep -o 'GLIBC_2\.[0-9]*' | sort -uV | tail -1 || true) + echo "highest glibc requirement: ${MAX:-none}" + [ -n "$MAX" ] || fail "no GLIBC_ references at all -- statically linked glibc? \ +that is not portable: NSS and gconv load modules with dlopen at run time and \ +then need the glibc it was linked against" + HAVE=${MAX#GLIBC_2.} + WANT=${FLOOR#2.} + [ "$HAVE" -le "$WANT" ] || fail "requires $MAX, allowed at most GLIBC_$FLOOR" + + if has --armv6-hardfloat; then + echo "--- ARM ABI ---" + readelf -A "$BIN" | grep -E 'Tag_CPU_arch|Tag_FP_arch|Tag_ABI_VFP_args' || true + readelf -A "$BIN" | grep -q 'Tag_CPU_arch: v6' \ + || fail "not armv6 -- this drops the Pi 1 and Zero" + readelf -A "$BIN" | grep -q 'Tag_ABI_VFP_args: VFP registers' \ + || fail "not hard-float -- this does not run on Raspberry Pi OS" + fi + ;; + + *Mach-O*) + echo "--- libraries it needs at start ---" + otool -L "$BIN" + echo "--- outside the system? ---" + # Everything the binary names has to be a system library or relative to the + # binary itself. A Homebrew path means the archive only runs on a machine + # that has that formula installed at that prefix. + FOREIGN=$(otool -L "$BIN" | tail -n +2 | awk '{print $1}' \ + | grep -vE '^(/usr/lib/|/System/|@rpath/|@executable_path/|@loader_path/)' || true) + if [ -n "$FOREIGN" ]; then + fail "references libraries outside the system: $(echo $FOREIGN) -- those would have to be bundled" + fi + echo "(nothing but system libraries and relative paths)" + + echo "--- deployment target ---" + otool -l "$BIN" | grep -A4 LC_BUILD_VERSION || true + MINOS=$(vtool -show-build "$BIN" 2>/dev/null | awk '/minos/ {print $2; exit}' || true) + echo "minos: ${MINOS:-unknown}" + [ -n "$MINOS" ] || fail "could not read a deployment target from $BIN" + case "$MINOS" in + "$FLOOR"|"$FLOOR".*) ;; + *) fail "asked for macOS $FLOOR, binary says $MINOS -- is \ +MACOSX_DEPLOYMENT_TARGET set for the whole build, not just for gdb?" ;; + esac + ;; + + *PE*|*MS\ Windows*) + OD=objdump + command -v x86_64-w64-mingw32-objdump >/dev/null && OD=x86_64-w64-mingw32-objdump + + echo "--- subsystem version in the header (informational only) ---" + "$OD" -p "$BIN" | grep -iE 'Major(OSystem|Subsystem)Version|Minor(OSystem|Subsystem)Version' \ + || echo "(could not read the PE header with $OD)" + # This number is not the floor, however much it looks like one. It is a + # default the linker stamps, and the default differs per target: our two + # clients are built from the same sources with the same _WIN32_WINNT, and + # the 32-bit one says 4.0 while the 64-bit one says 5.2 -- which is simply + # the oldest Windows that ever had the respective architecture. The loader + # only refuses a binary whose number is HIGHER than the running Windows, so + # a low stamp can never make a program portable; it just fails to say + # anything. Comparing it against a floor would therefore pass every time. + # + # What does decide the floor is the import table: a function that Windows 7 + # introduced makes the client refuse to start on Vista, no matter what any + # header field claims. So that is what we look at. + + echo "--- DLLs it needs at start ---" + "$OD" -p "$BIN" | awk '/DLL Name:/ {print " " $3}' | sort -u + + # Two DLL names are floors in themselves: + # api-ms-win-* the UCRT -- Windows 10, or a redistributable before it + # kernelbase.dll Windows 7 + # mingw-w64 normally links the old msvcrt.dll, which every Windows has. + DLLS=$("$OD" -p "$BIN" | awk '/DLL Name:/ {print tolower($3)}' | sort -u) + case "$DLLS" in + *api-ms-win-crt*) + has --ucrt-ok || fail "imports the UCRT (api-ms-win-crt-*) -- that is a \ +Windows 10 floor unless the user installs a redistributable" + echo "(imports the UCRT, as a MSYS2 UCRT64 build does: Windows 10)" ;; + esac + case "$DLLS" in + *kernelbase.dll*) fail "imports kernelbase.dll -- that DLL arrived with \ +Windows 7, so the client cannot start on Vista" ;; + esac + + # And a look at the other end: do we actually use anything newer than XP? + # Purely informational -- finding nothing would not prove the client runs on + # XP, only that these particular names are absent. But finding something + # confirms that _WIN32_WINNT=0x0600 is a real requirement and not a habit. + echo "--- functions that are Vista or newer (informational) ---" + "$OD" -p "$BIN" \ + | grep -oE '\b(GetTickCount64|InitializeConditionVariable|SleepConditionVariableCS|InitializeSRWLock|AcquireSRWLockExclusive|CreateSymbolicLinkW|GetFinalPathNameByHandleW|InetNtopW|CancelIoEx|GetThreadId)\b' \ + | sort -u | sed 's/^/ /' || echo " (none of the names we look for)" + + echo "OK: nothing in the import table of $BIN demands more than Windows $FLOOR" + exit 0 + ;; + + *) + fail "do not know how to read $BIN: $KIND" + ;; +esac + +echo "OK: $BIN stays within $FLOOR" diff --git a/ci/smoke-atmega328p.elf b/ci/smoke-atmega328p.elf new file mode 100644 index 000000000..f5c927508 Binary files /dev/null and b/ci/smoke-atmega328p.elf differ diff --git a/ci/smoke.c b/ci/smoke.c new file mode 100644 index 000000000..1801dd9db --- /dev/null +++ b/ci/smoke.c @@ -0,0 +1,39 @@ +/* + * The firmware the release workflow runs simavr on, as a smoke test: it proves + * that the binary loads an ELF file (which is what libelf is for) and that the + * core executes instructions. --list-cores touches neither. + * + * It ends by itself. Returning from main leaves avr-libc's exit handler, which + * is `cli` followed by `rjmp .-2`, and simavr recognises that as "rjmp .-2 with + * interrupts off" and quits gracefully with status 0 (see gracefully_quit() in + * simavr/sim/sim_avr.c). So the test needs no timeout to come to an end, and the + * exit status is the whole assertion. + * + * Compiled with -g: a gdb session against simavr should be able to show a + * source line and read a variable, and without debug info it cannot. + * + * Deliberately without simavr's own headers: the firmware should not have to be + * rebuilt when those change. + * + * avr-gcc -mmcu=atmega328p -Og -g -o smoke-atmega328p.elf smoke.c + */ +#include +#include + +int main(void) +{ + volatile uint16_t sum = 0; + + /* a little arithmetic, a little SRAM, a little I/O -- enough that the + * core has to do something other than jump */ + for (uint8_t i = 1; i <= 10; i++) + sum += i; + + DDRB |= _BV(PB5); + if (sum == 55) + PORTB |= _BV(PB5); + else + PORTB &= (uint8_t)~_BV(PB5); + + return 0; +} diff --git a/requirements.md b/requirements.md new file mode 100644 index 000000000..923e00913 --- /dev/null +++ b/requirements.md @@ -0,0 +1,60 @@ +# What the release archives require + +Every archive attached to a release is built on the oldest system we are willing +to support for that platform, and what it ends up demanding is measured after +the build rather than assumed. The numbers below come from `check-floor.sh`, +which the release workflow runs over every ELF object in the archive, not just +over the executable: a bundled library can demand more than the program does, +and the floor of an archive is the maximum over everything in it. + +| Archive | Requires | Found on | +| ------- | -------- | -------- | +| `simavr-linux_x86_64.tar.gz` | GLIBC 2.34 | Ubuntu 22.04, Debian 12, RHEL 9 and later | +| `simavr-linux_i686.tar.gz` | GLIBC 2.34 | Ubuntu 22.04, Debian 12 and later | +| `simavr-linux_aarch64.tar.gz` | GLIBC 2.17 | RHEL 7, Raspberry Pi OS bullseye and later | +| `simavr-linux_armv6l.tar.gz` | GLIBC 2.28, ARMv6, hard float | Raspberry Pi OS buster and later, Pi 1 and Zero included | +| `simavr-linux_armv7l.tar.gz` | GLIBC 2.28, ARMv7, hard float | Debian 10, Raspberry Pi OS buster and later | +| `simavr-darwin_x86_64.tar.gz` | macOS 10.15 | Intel Macs | +| `simavr-darwin_arm64.tar.gz` | macOS 11.0 | Apple Silicon | +| `simavr-windows_amd64.tar.gz` | Windows 10 | 64 bit only | + +GLIBC is backward compatible, so a newer system runs these binaries as well. The +arm archives ask for less than the system they were built on (Raspberry Pi OS +bullseye, GLIBC 2.31) because the code only references older symbols. + +## Nothing else has to be installed + +Each archive carries what it needs. On Linux that means `libsimavr`, and beside +it `libelf` and `libz`, found through an RPATH of `$ORIGIN`; only the C library +itself comes from the system. On macOS `libelf` and `libsimavr` are linked +statically and the binary names nothing but `/usr/lib/libSystem.B.dylib`. On +Windows the Universal CRT comes from the operating system, which is what makes +Windows 10 the floor, and any other DLL sits next to `simavr.exe`. + +The graphical parts of simavr are not in these archives. `make install-simavr` +installs the simulator and its library, not `libsimavrparts`, so no archive +depends on OpenGL, GLUT or X11 and the simulator runs on a machine without a +display. + +## What is not included + +There is no DWARF support: `libdwarf` changes its API between releases, and the +version on the oldest system we build on is older than the sources expect. The +`info io_registers` command of simavr therefore does not work in these builds. +Everything a debugger needs is read by the debugger itself from the firmware's +ELF file, so a normal GDB session is unaffected. + +The binaries are not stripped. They carry their debug information, which makes +the archives a few hundred kilobytes larger and a crash report useful. + +## Checking it yourself + +``` +./check-floor.sh bin/simavr 2.34 # ELF: highest GLIBC version referenced +./check-floor.sh bin/simavr 11.0 # Mach-O: deployment target +./check-floor.sh bin/simavr.exe 10.0 --ucrt-ok # PE: the DLLs it imports +``` + +The script fails when a binary demands more than the version given, which is how +the release workflow notices the day a rebuilt archive would quietly raise its +own floor.