penguin/monok8s

k8s image for Mono Gateway Dev Kit

commit a7236ed3b06aceb9ba74fb96ac6e80a0b8ad435ab1ef96c132c9a41c7f9d27a0

author斟酌 鵬兄 <tgckpg@gmail.com>
date2026-03-20T18:26:13Z
subjectAdded kernel-extra.config for customization
commit a7236ed3b06aceb9ba74fb96ac6e80a0b8ad435ab1ef96c132c9a41c7f9d27a0
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2026-03-20T18:26:13Z

    Added kernel-extra.config for customization
---
 .gitignore                     |   1 +
 README.md                      |  30 ++++++++++++
 docker/build-base.Dockerfile   |   1 +
 docker/fit-build.Dockerfile    |  14 +++++-
 docker/kernel-build.Dockerfile |  10 +++-
 initramfs/init                 |  27 +++++------
 initramfs/selective-mods.sh    | 107 +++++++++++++++++++++++++++++++++++++++++
 kernel-extra.config            |   3 ++
 makefile                       |   4 +-
 9 files changed, 177 insertions(+), 20 deletions(-)

diff --git a/.gitignore b/.gitignore
index 8c0964c..f723986 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 dev/
 out/
+.swp
diff --git a/README.md b/README.md
index a1e7acd..cc90094 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/docker/build-base.Dockerfile b/docker/build-base.Dockerfile
index 1aba290..e9d1fb9 100644
--- a/docker/build-base.Dockerfile
+++ b/docker/build-base.Dockerfile
@@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
     file \
     flex \
     git \
+    kmod \
     libelf-dev \
     libssl-dev \
     make \
diff --git a/docker/fit-build.Dockerfile b/docker/fit-build.Dockerfile
index e5f831b..681e237 100644
--- a/docker/fit-build.Dockerfile
+++ b/docker/fit-build.Dockerfile
@@ -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
@@ -21,7 +28,7 @@ RUN tar -xf busybox.tar.gz && mv "busybox-${BUSYBOX_VERSION}" busybox
 
 WORKDIR /build/busybox
 
-RUN make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} defconfig \
+RUN make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} defconfig\ 
  && sed -i 's/^# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config
 RUN make CROSS_COMPILE=${CROSS_COMPILE} -j"$(nproc)"
 RUN make CROSS_COMPILE=${CROSS_COMPILE} CONFIG_PREFIX=/out/initramfs install
@@ -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
diff --git a/docker/kernel-build.Dockerfile b/docker/kernel-build.Dockerfile
index c281237..8119c4b 100644
--- a/docker/kernel-build.Dockerfile
+++ b/docker/kernel-build.Dockerfile
@@ -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/ \;
diff --git a/initramfs/init b/initramfs/init
index f0ba2f1..0a2924d 100755
--- a/initramfs/init
+++ b/initramfs/init
@@ -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
diff --git a/initramfs/selective-mods.sh b/initramfs/selective-mods.sh
new file mode 100755
index 0000000..4e8294b
--- /dev/null
+++ b/initramfs/selective-mods.sh
@@ -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
diff --git a/kernel-extra.config b/kernel-extra.config
new file mode 100644
index 0000000..c571753
--- /dev/null
+++ b/kernel-extra.config
@@ -0,0 +1,3 @@
+CONFIG_HWMON=y
+CONFIG_I2C=y
+CONFIG_SENSORS_EMC2305=y
diff --git a/makefile b/makefile
index 1c77107..912a880 100644
--- a/makefile
+++ b/makefile
@@ -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) \