Skip to content

Commit

Permalink
feat: add sd-stub and sd-boot
Browse files Browse the repository at this point in the history
Add `sd-stub` and `sd-boot`.

Signed-off-by: Noel Georgi <git@frezbo.dev>
  • Loading branch information
frezbo committed May 9, 2023
1 parent 30a7ac2 commit c5d3bf1
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/renovate.json
Expand Up @@ -80,7 +80,8 @@
{
"matchPackageNames": [
"git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git",
"benhoyt/inih"
"benhoyt/inih",
"systemd/systemd"
],
"versioning": "regex:^(?<major>\\d+)\\.?(?<minor>\\d+)?\\.?(?<patch>\\d+)?$"
},
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -60,6 +60,8 @@ TARGETS = \
openssl \
raspberrypi-firmware \
runc \
sd-boot \
sd-stub \
socat \
syslinux \
u-boot \
Expand Down
7 changes: 6 additions & 1 deletion Pkgfile
Expand Up @@ -3,7 +3,7 @@
format: v1alpha2

vars:
TOOLS_IMAGE: ghcr.io/siderolabs/tools:v1.5.0-alpha.0-2-g47b0fd3
TOOLS_IMAGE: ghcr.io/siderolabs/tools:v1.5.0-alpha.0-3-g81b09a5

# renovate: datasource=github-releases depName=containernetworking/plugins
cni_version: v1.2.0
Expand Down Expand Up @@ -162,6 +162,11 @@ vars:
syslinux_sha256: 26d3986d2bea109d5dc0e4f8c4822a459276cf021125e8c9f23c3cca5d8c850e
syslinux_sha512: dd2b2916962b9e93bc1e714182e3ca2a727a229b8afabe913050bcfdd43ee2af51ee3acf79121d8c20caf434583efaa7f3196871e0e07c04d82191323a50fe31

# renovate: datasource=github-releases depName=systemd/systemd
systemd_version: 253
systemd_sha256: acbd86d42ebc2b443722cb469ad215a140f504689c7a9133ecf91b235275a491
systemd_sha512: 3bbc431a292ab590b70d3b490a528f71d30ccf478ddfa66d1c210f40c260ef49ac30651c19f2d073acf38d68398a4a6fbf95391f0e3ea0333d94b9d4e81d514f

# renovate: datasource=github-tags depName=ARM-software/arm-trusted-firmware
arm_trusted_firmware_version: v2.8.0
arm_trusted_firmware_sha256: 60fad60eeb6840097f8e64f16093c06ddb2ef269c7a22affed02beaa6cefe466
Expand Down
40 changes: 40 additions & 0 deletions sd-boot/patches/musl.patch
@@ -0,0 +1,40 @@
From a4ff7772acf1d983921833aa20ccd7c4d5e59a1c Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex@linutronix.de>
Date: Mon, 6 Mar 2023 15:24:49 +0100
Subject: [PATCH] src/boot/efi/efi-string.c: define wchar_t from __WCHAR_TYPE__

systemd-boot relies on wchar_t being 16 bit, and breaks at build time otherwise.

To set wchar_t to 16 bit it is passing -fshort-wchar to gcc; this has the
desired effect on glibc (which sets wchar_t from __WCHAR_TYPE__) but not on
musl (which hardcodes it to 32 bit).

This patch ensures wchar_t is set from the compiler flags on all systems; note
that systemd-boot is not actually using functions from musl or other libc, just their headers.

Meanwhile upstream has refactored the code to not rely on libc headers at all;
however this will not be backported to v253 and we need a different fix.

Upstream-Status: Inappropriate [fixed differently in trunk according to https://github.com/systemd/systemd/pull/26689]
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
src/boot/efi/efi-string.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c
index 22923d60f6..22a8d1ef71 100644
--- a/src/boot/efi/efi-string.c
+++ b/src/boot/efi/efi-string.c
@@ -2,7 +2,13 @@

#include <stdbool.h>
#include <stdint.h>
+
+#if SD_BOOT
+typedef __WCHAR_TYPE__ wchar_t;
+#define __DEFINED_wchar_t
+#else
#include <wchar.h>
+#endif

#include "efi-string.h"
49 changes: 49 additions & 0 deletions sd-boot/pkg.yaml
@@ -0,0 +1,49 @@
name: sd-boot
variant: scratch
shell: /toolchain/bin/bash
dependencies:
- stage: base
steps:
- sources:
- url: https://github.com/systemd/systemd/archive/refs/tags/v{{ .systemd_version }}.tar.gz
destination: systemd.tar.gz
sha256: "{{ .systemd_sha256 }}"
sha512: "{{ .systemd_sha512 }}"
env:
LD_LIBRARY_PATH: /toolchain/lib
prepare:
- |
tar -xzf systemd.tar.gz --strip-components=1
ln -s /toolchain/bin/echo /toolchain/bin/getent
mkdir -p /usr/bin
ln -sf /toolchain/bin/env /usr/bin/env
ln -sf /toolchain/bin/python3 /toolchain/bin/python
pip3 install jinja2 ninja
patch -p1 < /pkg/patches/musl.patch
meson setup build \
--buildtype=release \
-Dmode=release \
-Dsbat-distro=talos \
-Dsbat-distro-summary="Talos Linux" \
-Dsbat-distro-url=https://github.com/siderolabs/pkgs/issues \
-Dman=false \
-Defi=true \
-Dgnu-efi=true \
-Defi-libdir=/toolchain/lib \
-Defi-includedir=/toolchain/include/efi \
-Dtests=false
build:
- |
ninja -j $(nproc) -C build systemd-boot
install:
- |
mkdir -p /rootfs
cp build/src/boot/efi/*.efi /rootfs
finalize:
- from: /rootfs
to: /
40 changes: 40 additions & 0 deletions sd-stub/patches/musl.patch
@@ -0,0 +1,40 @@
From a4ff7772acf1d983921833aa20ccd7c4d5e59a1c Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex@linutronix.de>
Date: Mon, 6 Mar 2023 15:24:49 +0100
Subject: [PATCH] src/boot/efi/efi-string.c: define wchar_t from __WCHAR_TYPE__

systemd-boot relies on wchar_t being 16 bit, and breaks at build time otherwise.

To set wchar_t to 16 bit it is passing -fshort-wchar to gcc; this has the
desired effect on glibc (which sets wchar_t from __WCHAR_TYPE__) but not on
musl (which hardcodes it to 32 bit).

This patch ensures wchar_t is set from the compiler flags on all systems; note
that systemd-boot is not actually using functions from musl or other libc, just their headers.

Meanwhile upstream has refactored the code to not rely on libc headers at all;
however this will not be backported to v253 and we need a different fix.

Upstream-Status: Inappropriate [fixed differently in trunk according to https://github.com/systemd/systemd/pull/26689]
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
src/boot/efi/efi-string.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c
index 22923d60f6..22a8d1ef71 100644
--- a/src/boot/efi/efi-string.c
+++ b/src/boot/efi/efi-string.c
@@ -2,7 +2,13 @@

#include <stdbool.h>
#include <stdint.h>
+
+#if SD_BOOT
+typedef __WCHAR_TYPE__ wchar_t;
+#define __DEFINED_wchar_t
+#else
#include <wchar.h>
+#endif

#include "efi-string.h"
49 changes: 49 additions & 0 deletions sd-stub/pkg.yaml
@@ -0,0 +1,49 @@
name: sd-stub
variant: scratch
shell: /toolchain/bin/bash
dependencies:
- stage: base
steps:
- sources:
- url: https://github.com/systemd/systemd/archive/refs/tags/v{{ .systemd_version }}.tar.gz
destination: systemd.tar.gz
sha256: "{{ .systemd_sha256 }}"
sha512: "{{ .systemd_sha512 }}"
env:
LD_LIBRARY_PATH: /toolchain/lib
prepare:
- |
tar -xzf systemd.tar.gz --strip-components=1
ln -s /toolchain/bin/echo /toolchain/bin/getent
mkdir -p /usr/bin
ln -sf /toolchain/bin/env /usr/bin/env
ln -sf /toolchain/bin/python3 /toolchain/bin/python
pip3 install jinja2 ninja
patch -p1 < /pkg/patches/musl.patch
meson setup build \
--buildtype=release \
-Dmode=release \
-Dsbat-distro=talos \
-Dsbat-distro-summary="Talos Linux" \
-Dsbat-distro-url=https://github.com/siderolabs/pkgs/issues \
-Dman=false \
-Defi=true \
-Dgnu-efi=true \
-Defi-libdir=/toolchain/lib \
-Defi-includedir=/toolchain/include/efi \
-Dtests=false
build:
- |
ninja -j $(nproc) -C build systemd-stub
install:
- |
mkdir -p /rootfs
cp build/src/boot/efi/*.efi.stub /rootfs
finalize:
- from: /rootfs
to: /

0 comments on commit c5d3bf1

Please sign in to comment.