Added kernel-extra.config for customization

This commit is contained in:
2026-03-21 02:26:13 +08:00
parent 9c97871f97
commit a7236ed3b0
9 changed files with 177 additions and 20 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
dev/
out/
.swp

View File

@@ -6,6 +6,35 @@ https://docs.mono.si/gateway-development-kit/getting-started
## Build
```
make itb # for out/board.itb
make release # WORK IN PROGRESS
```
## Architecture
- A/B deployment
- Read-only OS
## Upgrade process
Rough idea
```
./configure
# - join cluster config
make release
# Copy the new image to the upgrade-scheduler
kubectl cp -n kube-system upgrade-scheduler:/tmp/upgrade.img
# Upgrade scheduler reads the file that issue a self-reboot
reboot
# uboot to boot into partition B
```
```yaml
PENDING
```
## tftp (network is required)
@@ -18,6 +47,7 @@ usb start
usb tree
fatls usb 0:1 # For fat
ext4ls usb 0:1 # For ext4
fatload usb 0 0x80000000 board.itb
setenv bootargs "console=ttyS0,115200 earlycon=uart8250,mmio,0x21c0500 root=/dev/ram0 rootwait rw"
bootm 0x80000000

View File

@@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
file \
flex \
git \
kmod \
libelf-dev \
libssl-dev \
make \

View File

@@ -1,5 +1,12 @@
ARG TAG=dev
ARG DOCKER_IMAGE_ROOT=monok8s
FROM --platform=linux/amd64 ${DOCKER_IMAGE_ROOT}/kernel-build:${TAG} AS kernel
# Selective mods
RUN mkdir /out/selected-mods
COPY initramfs/selective-mods.sh /
RUN /selective-mods.sh /out/rootfs/lib/modules/$(ls /out/rootfs/lib/modules/) /out/selected-mods
FROM --platform=linux/amd64 ${DOCKER_IMAGE_ROOT}/build-base:${TAG} AS build
ARG BUSYBOX_VERSION
@@ -30,5 +37,8 @@ WORKDIR /out/initramfs
COPY initramfs/init init
RUN chmod +x init
RUN mkdir -p bin sbin etc proc sys dev usr/bin usr/sbin
RUN mkdir -p bin sbin etc proc sys dev lib usr/bin usr/sbin
COPY --from=kernel /out/selected-mods/* ./lib/
RUN find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz

View File

@@ -26,9 +26,13 @@ RUN tar -xf nxplinux.tar.gz \
WORKDIR /build/nxplinux
COPY kernel-extra.config /tmp/kernel-extra.config
# NXP tree: use the LSDK defconfig target
RUN make ARCH="${ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" defconfig lsdk.config
RUN make ARCH="${ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" -j"$(nproc)"
RUN make ARCH="${ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" defconfig lsdk.config \
&& ./scripts/kconfig/merge_config.sh -m .config /tmp/kernel-extra.config \
&& make ARCH="${ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" olddefconfig \
&& make ARCH="${ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" -j"$(nproc)"
# artifact collection
RUN mkdir -p /out/kernel /out/rootfs \
@@ -37,6 +41,8 @@ RUN mkdir -p /out/kernel /out/rootfs \
&& cp -av System.map .config /out/kernel/ \
&& make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} modules_install INSTALL_MOD_PATH=/out/rootfs
RUN depmod -b /out/rootfs $(ls /out/rootfs/lib/modules/)
ARG DTB_TARGET
RUN find /out/kernel -name "${DTB_TARGET}" -exec cp {} /out/ \;

View File

@@ -1,20 +1,19 @@
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs devtmpfs /dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys
cat <<!
# Optional but nice
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
_ _ _ __ __ _
| | | (_) | \/ | | |
| |__| |_ | \ / | ___ _ __ ___ | |
| __ | | | |\/| |/ _ \| '_ \ / _ \| |
| | | | |_ | | | | (_) | | | | (_) |_|
|_| |_|_( ) |_| |_|\___/|_| |_|\___/(_)
|/
echo "Booting kernel took $(cut -d' ' -f1 /proc/uptime) seconds."
echo "Dropping to shell on ttyS0..."
Booting kernel took $(cut -d' ' -f1 /proc/uptime) seconds.
while true; do
setsid cttyhack /bin/sh
echo "Shell exited. Starting another one..."
done
!
exec /bin/sh
EOF
exec poweroff -f

107
initramfs/selective-mods.sh Executable file
View File

@@ -0,0 +1,107 @@
#!/usr/bin/env bash
set -euo pipefail
# Stage a subset of kernel modules into a target rootfs/initramfs tree.
#
# Example:
# ./stage-initramfs-modules.sh \
# /out/rootfs/lib/modules/6.18.2 \
# /out/initramfs
#
# Result:
# /out/initramfs/lib/modules/6.18.2/...
#
# Notes:
# - This copies selected directories and modules.* metadata.
# - It does NOT run depmod for you unless you uncomment that section.
# - Best run after kernel modules have already been installed into the source tree.
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <source-lib-modules-version-dir> <dest-root>"
echo "Example: $0 /out/rootfs/lib/modules/6.18.2 /out/initramfs"
exit 1
fi
SRC_MODDIR="$1" # e.g. /out/rootfs/lib/modules/6.18.2
DEST_ROOT="$2" # e.g. /out/initramfs
if [[ ! -d "$SRC_MODDIR" ]]; then
echo "Source module dir does not exist: $SRC_MODDIR" >&2
exit 1
fi
KVER="$(basename "$SRC_MODDIR")"
DEST_MODDIR="$DEST_ROOT/lib/modules/$KVER"
mkdir -p "$DEST_MODDIR"
echo "==> Source: $SRC_MODDIR"
echo "==> Dest: $DEST_MODDIR"
echo
# Relative paths under /lib/modules/<version>
PATHS=(
# Metadata files used by modprobe/depmod.
"modules.builtin"
"modules.builtin.modinfo"
"modules.order"
"modules.dep"
"modules.dep.bin"
"modules.alias"
"modules.alias.bin"
"modules.symbols"
"modules.symbols.bin"
"modules.softdep"
# Core module dirs we may need.
"kernel/drivers/pwm"
"kernel/drivers/hwmon"
"kernel/drivers/thermal"
# Optional
# "kernel/drivers/i2c"
# "kernel/drivers/gpio"
# "kernel/drivers/base"
# "kernel/drivers/power"
# "kernel/drivers/platform"
)
copy_one() {
local rel="$1"
local src="$SRC_MODDIR/$rel"
local dst="$DEST_MODDIR/$rel"
if [[ -d "$src" ]]; then
echo "[DIR ] $rel"
mkdir -p "$(dirname "$dst")"
cp -a "$src" "$dst"
elif [[ -f "$src" ]]; then
echo "[FILE] $rel"
mkdir -p "$(dirname "$dst")"
cp -a "$src" "$dst"
else
echo "[MISS] $rel"
fi
}
for rel in "${PATHS[@]}"; do
copy_one "$rel"
done
echo
echo "==> Done staging selected modules."
# Optional: show what got copied
echo
echo "==> Staged files summary:"
find "$DEST_MODDIR" -type f | sed "s#^$DEST_ROOT/##" | sort
# Optional: if depmod exists INSIDE the build environment and you want to
# regenerate metadata for the destination tree, uncomment this block.
#
# if command -v depmod >/dev/null 2>&1; then
# echo
# echo "==> Running depmod for destination tree..."
# depmod -b "$DEST_ROOT" "$KVER"
# fi

3
kernel-extra.config Normal file
View File

@@ -0,0 +1,3 @@
CONFIG_HWMON=y
CONFIG_I2C=y
CONFIG_SENSORS_EMC2305=y

View File

@@ -20,7 +20,7 @@ kernel-build: build-base
--build-arg DTB_TARGET=$(DTB_TARGET) \
-t $(DOCKER_IMAGE_ROOT)/kernel-build:$(TAG) .
fit-build: build-base
fit-build: kernel-build
docker build \
-f docker/fit-build.Dockerfile \
--build-arg DOCKER_IMAGE_ROOT=$(DOCKER_IMAGE_ROOT) \
@@ -30,7 +30,7 @@ fit-build: build-base
--build-arg BUSYBOX_VERSION=$(BUSYBOX_VERSION) \
-t $(DOCKER_IMAGE_ROOT)/fit-build:$(TAG) .
itb: fit-build kernel-build
itb: fit-build
docker build \
-f docker/itb.Dockerfile \
--build-arg DOCKER_IMAGE_ROOT=$(DOCKER_IMAGE_ROOT) \