Skip to content

Commit d933e5f

Browse files
authored
Merge pull request #208 from smartobjectoriented/144-support-musl
Support of musl C library
2 parents ba9ed10 + ca517bd commit d933e5f

1,356 files changed

Lines changed: 3363 additions & 58820 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ on:
55
branches:
66
- main
77
pull_request:
8-
branches:
9-
- main
8+
branches: ["main"]
109

1110
jobs:
1211
build-so3:
@@ -25,15 +24,15 @@ jobs:
2524

2625
- name: Build
2726
run: |
28-
docker run --rm -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:main bash -c "cd so3 && make ${{ matrix.CONFIG }} && make -j`nproc`"
27+
docker run --rm -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:latest bash -c "cd so3 && make ${{ matrix.CONFIG }} && make -j`nproc`"
2928
3029
build-usr:
3130
runs-on: ubuntu-latest
3231
strategy:
3332
fail-fast: false
3433
matrix:
35-
CMAKE_TOOLCHAIN_FILE: ['aarch64_toolchain.cmake',
36-
'arm_toolchain.cmake']
34+
CMAKE_TOOLCHAIN_FILE: ['aarch64-linux-musl.cmake',
35+
'arm-linux-musl.cmake']
3736
BUILD_TYPE: ['Debug', 'Release']
3837
steps:
3938
- name: Checkout repository
@@ -43,4 +42,4 @@ jobs:
4342

4443
- name: Build
4544
run: |
46-
docker run --rm -t -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:main bash -c "mkdir usr/build && cd usr/build && cmake --no-warn-unused-cli -DCMAKE_C_FLAGS='-Werror' -Wno-dev -DCMAKE_BUILD_TYPE=${{ matrix.BUILD_TYPE }} -DCMAKE_TOOLCHAIN_FILE=../${{matrix.CMAKE_TOOLCHAIN_FILE }} .. && make -j`nproc`"
45+
docker run --rm -t -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:latest bash -c "mkdir usr/build && cd usr/build && cmake --no-warn-unused-cli -DCMAKE_C_FLAGS='-Werror' -Wno-dev -DCMAKE_BUILD_TYPE=${{ matrix.BUILD_TYPE }} -DCMAKE_TOOLCHAIN_FILE=../${{matrix.CMAKE_TOOLCHAIN_FILE }} .. && make -j`nproc`"

.github/workflows/docker.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,64 @@ name: Docker Image CI
22

33
on:
44
push:
5-
branches: ["main"]
5+
paths:
6+
- 'docker/Dockerfile.*'
7+
- 'toolchains/*'
68
workflow_dispatch:
79

810
env:
911
REGISTRY: ghcr.io
1012

1113
jobs:
14+
build-toolchains:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
19+
permissions:
20+
contents: read
21+
packages: write
22+
steps:
23+
- name: Checkout Repository
24+
uses: actions/checkout@v4
25+
with:
26+
submodules: 'true'
27+
28+
- name: Log in to the Container registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract metadata for Docker
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ghcr.io/smartobjectoriented/so3-toolchains
40+
tags: |
41+
type=raw,value=latest
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v3
45+
46+
- name: Build and push
47+
id: build_toolchains
48+
uses: docker/build-push-action@v5
49+
with:
50+
context: .
51+
file: ./docker/Dockerfile.toolchains
52+
push: true
53+
platforms: linux/amd64
54+
tags: ${{ steps.meta.outputs.tags }}
55+
labels: ${{ steps.meta.outputs.labels }}
56+
annotations: ${{ steps.meta.outputs.annotations }}
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max
59+
1260
build-image:
1361
runs-on: ubuntu-latest
62+
needs: ['build-toolchains']
1463
strategy:
1564
fail-fast: false
1665
matrix:
@@ -47,6 +96,8 @@ jobs:
4796
uses: docker/metadata-action@v5
4897
with:
4998
images: ${{ matrix.image }}
99+
tags: |
100+
type=raw,value=latest
50101
51102
- name: Set up Docker Buildx
52103
uses: docker/setup-buildx-action@v3

doc/source/user_guide.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ SO3 root directory (main subdirs)::
6767
Build of the environment
6868
************************
6969

70-
About the toolchain
71-
===================
70+
kernel toolchain
71+
================
7272

7373
We use the ``arm-none-eabi`` toolchain which has no dependencies on a libc.
7474

@@ -78,6 +78,24 @@ The following package can be installed:
7878
7979
apt install gcc-arm-none-eabi
8080
81+
usr-space toolchain
82+
===================
83+
84+
The usr-space uses MUSL as libc. The Musl toolchains can be generated with
85+
``toolchains/build-toolchain.sh`` script.
86+
87+
.. code-block:: bash
88+
89+
$ ./build-toolchain.sh
90+
91+
By default, it generates ``aarch64-linux-musl`` and ``arm-linux-musleabihf``
92+
folder in the ``toolchains`` directory
93+
94+
.. note::
95+
96+
The output directory (by default ``toolchains`` floder) can be changed by setting
97+
the ``OUTPUT_PATH`` variable in the ``build-toolchain.sh`` script
98+
8199
Quick setup & early test
82100
========================
83101

docker/Dockerfile.env

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
FROM ubuntu:22.04
1+
FROM ghcr.io/smartobjectoriented/so3-toolchains
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV TZ=UTC
25

36
RUN dpkg --add-architecture i386
47
RUN apt update
5-
RUN apt install libc6:i386 libncurses5:i386 libstdc++6:i386 -y
8+
RUN apt install libc6:i386 libncurses6:i386 libstdc++6:i386 -y
69
RUN apt install lib32z1-dev -y
710
RUN apt install zlib1g:i386 -y
811
RUN apt install pkg-config libgtk2.0-dev bridge-utils -y
@@ -13,35 +16,22 @@ RUN apt install fdisk -y
1316
RUN apt install libncurses-dev -y
1417
RUN apt install flex bison -y
1518

16-
RUN apt install gcc-arm-none-eabi -y
1719
RUN apt install wget unzip -y
1820
RUN apt install python3-venv -y
1921
RUN apt install ninja-build -y
2022
RUN apt install git -y
2123
RUN apt install cmake -y
2224
RUN apt install python3-pip -y
2325

24-
RUN pip3 install pcpp
25-
26-
# Download aarch64-none-linux-gnu toolchain
27-
RUN wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz
28-
RUN tar -xvf gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz
29-
RUN rm gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz
30-
31-
ENV PATH="$PATH:/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin"
32-
33-
# Download aarch64-none-elf toolchain
34-
RUN wget https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz
35-
RUN tar -xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz
36-
RUN rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz
37-
38-
ENV PATH="$PATH:/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf/bin"
26+
RUN pip install --break-system-packages pcpp
3927

4028
# Get current so3 so we can build qemu
4129
RUN wget https://github.com/smartobjectoriented/so3/archive/refs/heads/main.zip
4230
RUN unzip main.zip
4331
RUN rm main.zip
4432
RUN mv so3-* generated
33+
34+
# Build qemu
4535
RUN cd /generated/qemu && ./fetch.sh && ./configure --target-list=arm-softmmu,aarch64-softmmu --disable-attr --disable-werror --disable-docs
4636
ENV PATH="$PATH:/generated/qemu/build"
4737
# Remove everything except qemu

docker/Dockerfile.lvperf_32b

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
FROM alpine:latest AS baseimage
1+
FROM ghcr.io/smartobjectoriented/so3-toolchains:latest AS baseimage
22

33
FROM baseimage AS builder
44

5-
RUN apk update; \
6-
apk add --no-cache make cmake gcc-arm-none-eabi \
7-
g++-arm-none-eabi qemu-system-arm \
8-
bison flex libc-dev libressl-dev dtc
5+
RUN apt update && \
6+
apt install -y build-essential cmake qemu-system-arm gcc-arm-none-eabi \
7+
bison flex libssl-dev device-tree-compiler qemu-system-arm && \
8+
apt clean && \
9+
rm -rf /var/lib/apt/lists/*
910

1011
WORKDIR /so3
1112

@@ -29,10 +30,12 @@ RUN cd u-boot;\
2930

3031
FROM baseimage AS runner
3132

32-
RUN apk update; \
33-
apk add --no-cache make cmake gcc-arm-none-eabi \
34-
g++-arm-none-eabi qemu-system-arm \
35-
util-linux dtc u-boot-tools dosfstools python3 py3-pip
33+
RUN apt-get update && \
34+
apt install -y make cmake gcc-arm-none-eabi qemu-system-arm \
35+
util-linux device-tree-compiler u-boot-tools dosfstools python3 \
36+
python3-pip && \
37+
apt clean && \
38+
rm -rf /var/lib/apt/lists/*
3639

3740
RUN pip install --break-system-packages pcpp
3841

docker/Dockerfile.lvperf_64b

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
FROM alpine:latest AS baseimage
1+
FROM ghcr.io/smartobjectoriented/so3-toolchains:latest AS baseimage
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV TZ=UTC
25

36
FROM baseimage AS builder
47

5-
RUN apk update; \
6-
apk add --no-cache make cmake gcc-aarch64-none-elf \
7-
qemu-system-aarch64 \
8-
bison flex libc-dev libressl-dev dtc
8+
RUN apt update && \
9+
apt install -y build-essential cmake qemu-system-arm \
10+
bison flex libssl-dev device-tree-compiler && \
11+
apt clean && \
12+
rm -rf /var/lib/apt/lists/*
913

1014
WORKDIR /so3
1115

@@ -29,10 +33,19 @@ RUN cd u-boot;\
2933

3034
FROM baseimage AS runner
3135

32-
RUN apk update; \
33-
apk add --no-cache make cmake gcc-aarch64-none-elf \
34-
g++-aarch64-none-elf qemu-system-aarch64 \
35-
util-linux dtc u-boot-tools dosfstools python3 py3-pip
36+
RUN apt update && apt install -y --no-install-recommends \
37+
build-essential \
38+
cmake \
39+
qemu-system-arm \
40+
util-linux \
41+
device-tree-compiler \
42+
u-boot-tools \
43+
dosfstools \
44+
python3 \
45+
python3-pip \
46+
bash patch git && \
47+
apt clean && \
48+
rm -rf /var/lib/apt/lists/*
3649

3750
RUN pip install --break-system-packages pcpp
3851

@@ -66,10 +79,6 @@ RUN echo "#!/bin/sh" > install_dependencies.sh && chmod +x install_dependencies.
6679
RUN rm -rf /var/cache/apk/*
6780
RUN rm -rf /usr/share/man /usr/share/doc /usr/share/info /var/cache/apk/*
6881

69-
# This env varialbe is read from the usr/build.sh script in order to set a custom aarch64 toolchain
70-
# This may be removed if so3 is fully migrated to the aarch64-none-elf toolchain
71-
# Right now aarch64-none-linux-gnu is still used by default
72-
ENV USR_BUILD_TOOLCHAIN_FILE=aarch64_none_toolchain.cmake
7382
ENV QEMU_ARCH=aarch64
7483
ENV PLATFORM=virt64
7584

docker/Dockerfile.toolchains

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Create a Docker image which prepare the toolchains needed by SO3 env.
2+
#
3+
# Copyright (c) 2025 REDS Institute, HEIG-VD
4+
#
5+
# Set 'aarch64-none-elf' toolchain & build arm & aarch64 musl toolchains
6+
#
7+
# Note: 'arm-none-eabi-' is installed for package manager in the others docker images
8+
9+
FROM ubuntu:24.04 AS toolchains-utils
10+
11+
RUN apt-get update && apt-get install -y gcc-arm-none-eabi gcc-11 g++-11 git make \
12+
patch sudo xz-utils wget && \
13+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 10 && \
14+
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 10 && \
15+
apt clean && \
16+
rm -rf /var/lib/apt/lists/*
17+
18+
# Download aarch64-none-elf toolchain
19+
RUN wget https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz
20+
RUN tar -xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz
21+
RUN rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz
22+
23+
ENV PATH="$PATH:/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf/bin"
24+
25+
COPY toolchains /toolchains
26+
RUN /toolchains/build-toolchain.sh && rm -rf /toolchains/musl-cross-make
27+
28+
ENV PATH=$PATH:/toolchains/aarch64-linux-musl/bin
29+
ENV PATH=$PATH:/toolchains/arm-linux-musleabihf/bin

so3/Kbuild

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22
# Kbuild for top-level directory of the kernel
33
# This file takes care of the following:
44

5-
# Generate asm-offsets.h
5+
# Generate syscall_table.h.in and syscall_number.h
6+
7+
syscall-files = include/generated/syscall_table.h.in
8+
syscall-files += include/generated/syscall_number.h
9+
syscall-script = scripts/syscall_gen.sh
10+
syscall-src = syscall.tbl arch/$(SRCARCH)/syscall.h.in
11+
12+
quiet_cmd_syscall_gen = GEN $@
13+
cmd_syscall_gen = $(syscall-script) $(syscall-src) $(syscall-files)
14+
15+
$(syscall-files) &: $(syscall-script) $(syscall-src) Kbuild FORCE
16+
$(call if_changed,syscall_gen)
17+
18+
always := $(syscall-files)
19+
targets := $(syscall-files)
20+
21+
# Generate asm-offsets.h
622
#
723

824
offsets-file := include/generated/asm-offsets.h
925

10-
always := $(offsets-file)
11-
targets := $(offsets-file)
26+
always += $(offsets-file)
27+
targets += $(offsets-file)
1228
targets += arch/$(SRCARCH)/asm-offsets.s
13-
29+
1430
# Default sed regexp - multiline due to syntax constraints
1531
define sed-y
1632
"/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"
@@ -34,10 +50,9 @@ define cmd_offsets
3450
endef
3551

3652
# We use internal kbuild rules to avoid the "is up to date" message from make
37-
arch/$(SRCARCH)/asm-offsets.s: $(srctree)/arch/$(SRCARCH)/asm-offsets.c FORCE
53+
arch/$(SRCARCH)/asm-offsets.s: $(srctree)/arch/$(SRCARCH)/asm-offsets.c include/generated/syscall_number.h FORCE
3854
$(Q)mkdir -p $(dir $@)
3955
$(call if_changed_dep,cc_s_c)
4056

4157
$(offsets-file): arch/$(SRCARCH)/asm-offsets.s Kbuild
4258
$(call cmd,offsets)
43-

so3/arch/arm32/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
obj-y += head.o
33
obj-y += setup.o exception.o context.o fault.o
44
obj-y += cache_v7_asm.o cache_v7.o cache-cp15.o
5-
obj-y += thread.o ptrace.o
5+
obj-y += thread.o
66
obj-y += vfp.o
77
obj-y += backtrace.o backtrace_asm.o
88
obj-y += smccc-call.o
9+
obj-y += syscalls.o
10+
obj-y += kuser_helper.o
911

1012
obj-y += lib/
1113

so3/arch/arm32/asm-offsets.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ int main(void)
7878
DEFINE(OFFSET_PSR, offsetof(cpu_regs_t, psr));
7979
DEFINE(OFFSET_SP_USR, offsetof(cpu_regs_t, sp_usr));
8080
DEFINE(OFFSET_LR_USR, offsetof(cpu_regs_t, lr_usr));
81+
DEFINE(OFFSET_TLS_USR, offsetof(cpu_regs_t, tls_usr));
8182

8283
BLANK();
8384

0 commit comments

Comments
 (0)