Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and test

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: test-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
images:
runs-on: ubuntu-26.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
arch: [aarch64, x86_64]
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: Install test dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential flex bison bc perl pkg-config libelf-dev libssl-dev \
curl ca-certificates tar xz-utils bzip2 gzip cpio python3 \
qemu-system-x86 qemu-system-arm virtiofsd openssh-client sshpass
- name: Enable vsock transport
run: |
sudo modprobe vhost_vsock
sudo udevadm settle
sudo chmod a+rw /dev/vhost-vsock
python3 -c 'import os; os.close(os.open("/dev/vhost-vsock", os.O_RDWR))'
- name: Restore toolchain and kernel build
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
${{ matrix.arch }}-linux-musl-*/
build-${{ matrix.arch }}/linux-kernel/
key: kernel-${{ runner.os }}-26.04-${{ matrix.arch }}-${{ hashFiles('puipui-linux-tool', 'kconfig/*.config', 'tests/toolchains.sha256') }}
- name: Build and test image
run: bash tests/run.sh "${{ matrix.arch }}"
- name: Upload diagnostics
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: test-logs-${{ matrix.arch }}
path: build-tests/
- name: Upload tested images
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: puipui-images-${{ matrix.arch }}
path: puipui_linux_*.tar.gz
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This document provides comprehensive information about the PUI PUI Linux codebas

### Current Version
- Tool Version: 1.0.3
- Kernel Version: 6.11.5
- Kernel Version: 7.2.9
- BusyBox Version: 1.36.1
- Dropbear Version: 2024.86
- Socat Version: 1.8.0.1
Expand Down Expand Up @@ -153,7 +153,7 @@ These are gitignored along with downloaded source tarballs.
**Kernel Configuration Management:**
- Configs stored as defconfig format in `kconfig/{arch}.config`
- Use `./puipui-linux-tool -u` to update configs
- Process: `listnewconfig` → `oldconfig` → `savedefconfig`
- Process: `olddefconfig` → `savedefconfig` (both target toolchains; failures stop the command)
- Always use `olddefconfig` for non-interactive updates

### 2. Initramfs & Init System
Expand Down Expand Up @@ -387,7 +387,7 @@ git push -u origin <branch-name>

### Update to New Kernel Version

1. Edit `puipui-linux-tool`: change `kernver=6.11.5` to new version
1. Edit `puipui-linux-tool`: change `kernver=7.2.9` to new version
2. Run `./puipui-linux-tool` - it will download new kernel
3. May need to update configs: `./puipui-linux-tool -u`
4. Test both architectures
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Since file size is very small in totally, I can do testing on the any CI with do

## Kernel

The kernel is pinned to Linux **7.2.9** (stable). Both architectures use
minimal configs in `kconfig/`; new kernel options take their upstream defaults.

What's supported:

- Internet
Expand All @@ -35,16 +38,28 @@ You can use it with other linux distributions.

### Build all

Build on Linux with GCC/binutils, make, flex, bison, bc, Perl, pkg-config,
libelf development headers, curl, tar, xz, bzip2, gzip and cpio installed.
The script downloads the target musl toolchains separately from the host tools.

```
$ ./puipui-linux-tool
```

### Update Kernel config

Set `kernver` in `puipui-linux-tool`, then run:

```
$ ./puipui-linux-tool -u
```

This downloads the kernel source and missing toolchains, runs `olddefconfig`
and `savedefconfig` for both architectures, and saves the minimal configs.
An existing `build-{arch}/linux-kernel/.config` is preserved as the input;
otherwise the checked-in config is used. Errors stop the command.
Review the config diff, then build and boot both architectures.

## Hack

This tool is used musl cross compiler. On arm64 environment the tool will be downloaded those pre build toolchains from https://github.com/Code-Hex/musl-cross-make-arm64
5 changes: 0 additions & 5 deletions kconfig/aarch64.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ CONFIG_EXPERT=y
# CONFIG_SOCIONEXT_SYNQUACER_PREITS is not set
# CONFIG_ARM64_TAGGED_ADDR_ABI is not set
# CONFIG_ARM64_HW_AFDBM is not set
# CONFIG_ARM64_PAN is not set
# CONFIG_ARM64_RAS_EXTN is not set
# CONFIG_ARM64_CNP is not set
# CONFIG_ARM64_PTR_AUTH is not set
Expand All @@ -65,7 +64,6 @@ CONFIG_COMPAT_32BIT_TIME=y
# CONFIG_SLAB_MERGE_DEFAULT is not set
# CONFIG_COMPAT_BRK is not set
# CONFIG_COMPACTION is not set
# CONFIG_MIGRATION is not set
CONFIG_NET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
Expand Down Expand Up @@ -98,7 +96,6 @@ CONFIG_VIRTIO_NET=y
# CONFIG_NET_VENDOR_ADAPTEC is not set
# CONFIG_NET_VENDOR_AGERE is not set
# CONFIG_NET_VENDOR_ALACRITECH is not set
# CONFIG_NET_VENDOR_ALTEON is not set
# CONFIG_NET_VENDOR_AMAZON is not set
# CONFIG_NET_VENDOR_AMD is not set
# CONFIG_NET_VENDOR_AQUANTIA is not set
Expand Down Expand Up @@ -128,11 +125,9 @@ CONFIG_VIRTIO_NET=y
# CONFIG_NET_VENDOR_MYRI is not set
# CONFIG_NET_VENDOR_NI is not set
# CONFIG_NET_VENDOR_NATSEMI is not set
# CONFIG_NET_VENDOR_NETERION is not set
# CONFIG_NET_VENDOR_NETRONOME is not set
# CONFIG_NET_VENDOR_NVIDIA is not set
# CONFIG_NET_VENDOR_OKI is not set
# CONFIG_NET_VENDOR_PACKET_ENGINES is not set
# CONFIG_NET_VENDOR_PENSANDO is not set
# CONFIG_NET_VENDOR_QLOGIC is not set
# CONFIG_NET_VENDOR_BROCADE is not set
Expand Down
3 changes: 1 addition & 2 deletions kconfig/x86_64.config
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ CONFIG_INPUT_EVDEV=y
# CONFIG_LEGACY_TIOCSTI is not set
# CONFIG_LDISC_AUTOLOAD is not set
CONFIG_SERIAL_8250=y
# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
# CONFIG_SERIAL_8250_PNP is not set
CONFIG_SERIAL_8250_CONSOLE=y
# CONFIG_SERIAL_8250_PCI is not set
# CONFIG_SERIAL_8250_EXAR is not set
CONFIG_SERIAL_8250_NR_UARTS=16
CONFIG_SERIAL_8250_EXTENDED=y
CONFIG_SERIAL_8250_MANY_PORTS=y
CONFIG_SERIAL_8250_SHARE_IRQ=y
CONFIG_SERIAL_8250_RSA=y
CONFIG_SERIAL_8250_MANY_PORTS=y
# CONFIG_SERIAL_8250_LPSS is not set
# CONFIG_SERIAL_8250_MID is not set
# CONFIG_SERIAL_8250_PERICOM is not set
Expand Down
80 changes: 46 additions & 34 deletions puipui-linux-tool
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# This script builds puipui linux kernel and it's initramfs.
#
# Options:
# -a Build only the specified architecture (aarch64 or x86_64).
# -u Only updates linux kernel config files. it does not build kernel or initramfs.
#---help---

Expand All @@ -15,7 +16,7 @@ version=1.0.3

srcdir="$PWD"
target_arch="aarch64 x86_64"
kernver=6.18.3
kernver=7.2.9
busyboxver=1.36.1
dropbearver=2024.86
socatver=1.8.0.1
Expand All @@ -34,7 +35,7 @@ usage() {
fetch() {
local url="$1"
local archive=${url##*/}
(cd $srcdir && curl -OL $url)
(cd "$srcdir" && curl -fOL "$url")
tar -xvf "$srcdir"/"$archive" -C "$srcdir"
}

Expand Down Expand Up @@ -66,7 +67,7 @@ _artifact() {

_cross_compile_target() {
local arch="$1"
echo $arch-linux-musl-
echo "$srcdir/$(_musl_path "$arch")/bin/$arch-linux-musl-"
}

_musl_path() {
Expand All @@ -85,14 +86,21 @@ setup_musl_path() {
local musl_abs_path="$srcdir/$musl_path"
local musl_prefix="$arch-linux-musl-"
local machine_arch="$(uname -m)"
if [ "aarch64" == $machine_arch ]; then
fetch "https://github.com/Code-Hex/musl-cross-make-arm64/releases/download/v0.0.4/${musl_path}.tar.gz"
tar xvf "$musl_abs_path.tar.gz"
else
fetch "https://musl.cc/${musl_path}.tgz"
tar xvf "$musl_abs_path.tgz"
ln -s $musl_abs_path/bin/{strip,"${musl_prefix}strip"}
if ! [ -d "$musl_abs_path" ]; then
msg "Download $musl_path"
if [ "aarch64" == $machine_arch ]; then
fetch "https://github.com/Code-Hex/musl-cross-make-arm64/releases/download/v0.0.4/${musl_path}.tar.gz"
else
fetch "https://musl.cc/${musl_path}.tgz"
fi
fi
# Native toolchains ship binutils without the target prefix.
local tool
for tool in ar as ld nm objcopy objdump ranlib readelf strip; do
if ! [ -e "$musl_abs_path/bin/${musl_prefix}${tool}" ]; then
ln -s "$tool" "$musl_abs_path/bin/${musl_prefix}${tool}"
fi
done
}

_prepareconfig() {
Expand All @@ -101,7 +109,6 @@ _prepareconfig() {
local _builddir=$(_builddir $_arch linux-kernel)
mkdir -p "$_builddir"

local PATH="$srcdir/$(_musl_path $_arch)/bin:$PATH"
cp "$srcdir"/$_config "$_builddir"/.config
msg "Configuring $name kernel ($_arch)"
make -C "$srcdir"/linux-$kernver \
Expand All @@ -128,11 +135,10 @@ build_kern() {
else echo "Unknown TARGET $_arch"; exit 1;
fi

local PATH="$srcdir/$(_musl_path $_arch)/bin:$PATH"
cd $(_builddir $_arch linux-kernel)
make CROSS_COMPILE=$(_cross_compile_target $_arch) \
ARCH="$(_kernelarch $_arch)" \
AWK="${AWK:-mawk}" \
AWK="${AWK:-awk}" \
KBUILD_BUILD_VERSION="$version-PUI PUI!" \
KBUILD_BUILD_HOST="molbuilder" \
KBUILD_BUILD_USER="codehex" \
Expand Down Expand Up @@ -182,7 +188,6 @@ build_initramfs() {

cp "$srcdir"/busybox_config/config "$_builddir"/.config

local PATH="$srcdir/$(_musl_path $_arch)/bin:$PATH"
make -C "$srcdir"/busybox-$busyboxver \
CROSS_COMPILE=$(_cross_compile_target $_arch) \
O="$_builddir" \
Expand Down Expand Up @@ -220,7 +225,6 @@ install_dropbear() {
local _arch="$1"
local _fsdir="$2"

local PATH="$srcdir/$(_musl_path $_arch)/bin:$PATH"
local _target=$(_cross_compile_target $_arch)
local CC="${_target}cc"
local AR="${_target}ar"
Expand All @@ -230,7 +234,9 @@ install_dropbear() {
local _dropbear_src="$srcdir"/"dropbear-${dropbearver}"

mkdir -p "$_builddir"
(cd $_dropbear_src && ./configure --build=$_arch -prefix=$_fsdir --disable-zlib --enable-static --disable-loginfunc --disable-wtmp)
(cd $_dropbear_src && CC="$CC" AR="$AR" RANLIB="$RANLIB" STRIP="$STRIP" \
./configure --build="$(gcc -dumpmachine)" --host="$_arch-linux-musl" \
--prefix="$_fsdir" --disable-zlib --enable-static --disable-loginfunc --disable-wtmp)

cd $_builddir
make -C $_dropbear_src \
Expand All @@ -242,7 +248,6 @@ install_socat() {
local _arch="$1"
local _fsdir="$2"

local PATH="$srcdir/$(_musl_path $_arch)/bin:$PATH"
local _target=$(_cross_compile_target $_arch)
local CC="${_target}cc"
local AR="${_target}ar"
Expand All @@ -257,8 +262,10 @@ install_socat() {
# https://git.alpinelinux.org/aports/commit/main/socat/APKBUILD?id=5edc9195355ced3db991c1a7cda5648d52019b11
(
cd $_socat_src && \
CC="$CC" AR="$AR" RANLIB="$RANLIB" STRIP="$STRIP" \
CFLAGS="-static -Os -s" ./configure \
--build=$_arch \
--build="$(gcc -dumpmachine)" \
--host="$_arch-linux-musl" \
--prefix=$_fsdir \
--disable-man \
--disable-openssl \
Expand Down Expand Up @@ -291,34 +298,49 @@ updateconfigs() {
local _config=$(_kconfig $_arch.config)
local _builddir=$(_builddir $_arch linux-kernel)
mkdir -p "$_builddir"
local actions="listnewconfig oldconfig"
if ! [ -f "$_builddir"/.config ]; then
cp "$srcdir"/$_config "$_builddir"/.config
actions="olddefconfig"
env | grep ^CONFIG_ >> "$_builddir"/.config || true
fi
make -j1 -C "$srcdir"/linux-$kernver \
CROSS_COMPILE=$(_cross_compile_target $_arch) \
O="$_builddir" \
ARCH="$(_kernelarch $_arch)" \
$actions savedefconfig
olddefconfig savedefconfig

cp "$_builddir"/defconfig "$srcdir"/$_config
done
}



while getopts ':uhv' OPTION; do
update_only=false
while getopts ':a:uhv' OPTION; do
case "$OPTION" in
u) updateconfigs || true; exit 0;;
a)
case "$OPTARG" in
aarch64|x86_64) target_arch="$OPTARG";;
*) echo "Unsupported architecture: $OPTARG" >&2; exit 1;;
esac;;
u) update_only=true;;
h) usage; exit 0;;
v) echo "puipui-linux-tool $version"; exit 0;;
*) usage >&2; exit 1;;
esac
done

if ! [ -d linux-"$kernver" ]; then
msg "Download linux kernel $kernver"
fetch "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${kernver}.tar.xz"
fetch "https://cdn.kernel.org/pub/linux/kernel/v${kernver%%.*}.x/linux-${kernver}.tar.xz"
fi

for _arch in $target_arch; do
setup_musl_path "$_arch"
done

if $update_only; then
updateconfigs
exit 0
fi

if ! [ -d busybox-"$busyboxver" ]; then
Expand All @@ -336,16 +358,6 @@ if ! [ -d socat-"$socatver" ]; then
fetch "http://www.dest-unreach.org/socat/download/socat-${socatver}.tar.gz"
fi

if ! [ -d $(_musl_path "aarch64") ]; then
msg "Download aarch64-linux-musl"
setup_musl_path "aarch64"
fi

if ! [ -d $(_musl_path "x86_64") ]; then
msg "Download x86_64-linux-musl"
setup_musl_path "x86_64"
fi

build_kern
download_curl
build_initramfs
Expand Down
Loading