Currently we can't put the Librem 5 in the stable branch of postmarketOS, which builds against a stable release of Alpine. The stable releases of Alpine don't have the testing subdir of their aports.
It's also not trivial to fork newlib-arm-none-eabi, as this in turn depends on gcc-arm-none-eabi from Alpine testing, which is part of gcc-cross-embedded and depends on gcc-arm-none-eabi itself.
In order to not block the v20.05 beta release, I'll delete u-boot-librem5 from that branch for now.
Can't we simply use gcc-armv7 from postmarketOS together with the pmb:cross-native APKBUILD option to build u-boot-librem5 and avoid the dependency altogether?
I don't know, I've asked on the purism librem5 matrix channel.
The librem5 package in pmos would not be able to use the u-boot from Alpine
as-is. This package does more than just build u-boot, it puts u-boot + other
things u-boot requires into an image file that can be flashed to the device.
When the librem5 can use upstream u-boot, that functionality will either need to
continue on in some similar package to this one, or get merge into the librem5
device package in aports.
Can't we simply use gcc-armv7 from postmarketOS together with the pmb:cross-native APKBUILD option to build u-boot-librem5 and avoid the dependency altogether?
FYI I had a lot of problem getting this all to work in a single package initially, there are two binaries produced by this package, one needs to be aarch64 and the other needs to be armhf. They are meant to run on different cores/cpus on the device (aarch64 for main cpu, armhf for the m4 cortex cpu). Does the 'pmb:cross-native' thing support this use case?
I would split this package into 2 packages, 1 for building the m4 firmware (called m4-librem5, and must be armhf), and 1 (called u-boot-librem5) for building uboot/ATF and creating the final image that includes uboot/ATF/m4 firmwares.
It would allow me to use gcc-armv7 for the 1st package m4-librem5, and gcc-aarch64 (whatever it's called) for the 2nd u-boot-librem5 package.
# Maintainer: Clayton Craft <clayton@craftyguy.net>pkgname=m4-librem5pkgver=0.1pkgrel=0_m4version="a017421c340a69f2392086da93841244f78a03c5"pkgdesc="Cortex M4 firmware for the Purism Librem5 phone"url="http://www.denx.de/wiki/U-Boot/"arch="armhf"license="GPL-2.0-or-later"makedepends="$depends_dev musl-dev binutils"options="!check !tracedeps"source=" m4-${_m4version}.tar.gz::https://source.puri.sm/Librem5/Cortex_M4/-/archive/${_m4version}/Cortex_M4-${_m4version}.tar.gz "builddir="$srcdir"/Cortex_M4-${_m4version}build() { make CC=gcc OBJCOPY=objcopy}package() { install -D -m644 "$builddir"/m4.bin \ "$pkgdir/usr/share/firmware/librem5/m4.bin"}sha512sums="035a4358ddf586c829da7fa2fb0d9d1df913c0c454f2d0e57ff0c6794552e49950fb6373f9aaf72e0e4c78ab411496aabbc60bf66cd76e35053f7a2d77911735 m4-a017421c340a69f2392086da93841244f78a03c5.tar.gz"
I'm overriding CC and OBJCOPY on the commandline because in the Makefile they are set to some cross compiler. building this with pmb:cross-native doesn't help, it still fails for the same reason.
@ollieparanoid I'm also confused/unsure about what 'arch' this APKBUILD should specify. This is a package that needs to build an armhf binary, but it needs to be installed on an aarch64 system. So maybe 'arch=aarch64' in the APKBUILD and use cross compilers, but that's exactly what I had before.
The other option is accept that the librem5 "won't work" on Alpine 3.12 since there's no compiler available to build the m4 firmware. It looks like 'edge' has the cross compiler now so 3.13 should be fine, right?
make CC=armv7-alpine-linux-musleabihf-gcc OBJCOPY=armv7-alpine-linux-musleabihf-objcopy
(Caveat: it's possible to override CFLAGS, but not LDFLAGS with the Makefile, as the LDFLAGS specified in the Makefile will override whatever is set as environment var.)
I've tried all kinds of combinations of setting -L, --sysroot, LIBRARY_PATH to get gcc to find /usr/armv7-alpine-linux-musleabihf/lib/libgcc_s.so, but without success. With strace I'm seeing, that gcc considers /usr/armv7-alpine-linux-musleabihf/lib/ - but I don't get why it does not find libgcc_so.so in there.
Does anybody have an idea or wants to take a shot at it?
# Maintainer: Clayton Craft <clayton@craftyguy.net>pkgname=m4-librem5pkgver=0_git20190116pkgrel=0_commit="a017421c340a69f2392086da93841244f78a03c5"pkgdesc="Cortex M4 firmware for the Purism Librem5 phone"url="https://source.puri.sm/Librem5/Cortex_M4"arch="aarch64"license="GPL-2.0-or-later"makedepends="gcc-armv7 binutils-armv7 musl-dev-armv7"options="!check !tracedeps pmb:cross-native"source=" m4-${_commit}.tar.gz::https://source.puri.sm/Librem5/Cortex_M4/-/archive/${_commit}/Cortex_M4-${_commit}.tar.gz "builddir="$srcdir/Cortex_M4-$_commit"build(){ make \CC=armv7-alpine-linux-musleabihf-gcc \OBJCOPY=armv7-alpine-linux-musleabihf-objcopy}package(){install-D-m644"$builddir"/m4.bin \"$pkgdir/usr/share/firmware/librem5/m4.bin"}sha512sums="035a4358ddf586c829da7fa2fb0d9d1df913c0c454f2d0e57ff0c6794552e49950fb6373f9aaf72e0e4c78ab411496aabbc60bf66cd76e35053f7a2d77911735 m4-a017421c340a69f2392086da93841244f78a03c5.tar.gz"
I discovered that this builds if I remove -n from the LDFLAGS, but I'm not sure if if the resulting binary is usable, or if this is even desired. The manpage for ld says:
-n Turn off page alignment of sections, and disable linking against shared libraries. If the output format supports Unix style magic numbers, mark the output as "NMAGIC".
I guess we could test it, without having any damage (since it's just written to the SD card, if it does not work, just flash it again with the working one, right?).
It's weird that this firmware thing requires linking against shared libraries in the first place.
It's weird that this firmware thing requires linking against shared libraries in the first place.
I agree. But I'm not going to pretend I know much about how this works,
especially if it's linked against a shared library that probably won't be
available at runtime since the binary, and only the binary, is embedded in the
image. I'll ask the Purism folks too, maybe they have some ideas.
The other option is accept that the librem5 "won't work" on Alpine 3.12 since there's no compiler available to build the m4 firmware. It looks like 'edge' has the cross compiler now so 3.13 should be fine, right?
gcc-arm-none-eabi is in Alpine testing currently. If you can convince the maintainer to move it to community before 3.13 is released, then it will be available in 3.13, otherwise not.
It's also not trivial to fork newlib-arm-none-eabi, as this in turn depends on gcc-arm-none-eabi from Alpine testing, which is part of gcc-cross-embedded and depends on gcc-arm-none-eabi itself.
crust needed gcc-or1k-elf and binutils-or1k-elf, so the following packages were already added to v20.05:
gcc-cross-embedded
gcc-cross-embedded-stage1
binutils-cross-embedded
newlib-stage1
Maybe it's now feasible to package the armhf cross compiling related bits too.
The super lazy method would be repackaging the apks from edge (like we do for cross/musl-*). But we can probably do it more elegantly.
To move this forward, one could look into getting it building on v20.05 again (in a testing branch, without pushing the packages to v20.05 branch); we would then need to fork the same packages to v21.03. As mentioned above, several packages were forked for crust already, it should be doable.
I started a WIP branch on v20.05, but compiling gcc fails when configuring libgcc with this super generic task, which leads me to believe the compiler didn't actually build or something?
I've unrolled several loops that would fill subpackages and makedepends, so pmbootstrap can parse it
Using pmb:cross-native, so u-boot actually gets built in the x86_64 chroot
Can you test if this u-boot version works? You could either test it now if you find the time. Or we do it on the v21.03 branch, as soon as it is ready there. I'll try to branch it today, or if that does not work out, early next week.
(To make it easier to maintain this in the future, we could put the gcc-cross-embedded related packages into a subdirectory.)
@ollieparanoid thanks for getting it to this point! Yeah I can test it out soon, it might be a day or so before I get to it through, so if you need to branch before then we could add the L5 in the first service pack for the new stable branch.
all patches from the branch adjusted and pushed to v21.03, except for the pmb:cross-native patch. this one should go through master, hence: !1988 (closed)