aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-02-05 19:13:08 +0100
committerlonkaars <loek@pipeframe.xyz>2024-02-05 19:13:08 +0100
commitb854e8abb7e1ff0b43c9f99e9b641895e4d6c148 (patch)
treeab8061666835221d155cfb259559752353c8a2e9
parent2a218ea1205c8dd547b742931290058def5de85f (diff)
WIP busybox
-rw-r--r--.gitmodules5
-rw-r--r--Containerfile3
m---------busybox0
-rw-r--r--makefile22
-rw-r--r--rootfs/etc/fstab1
-rw-r--r--rootfs/etc/hostname1
-rw-r--r--rootfs/etc/hosts1
-rwxr-xr-xrootfs/etc/init.d/rcS2
-rw-r--r--rootfs/etc/inittab9
-rw-r--r--rootfs/etc/passwd0
-rw-r--r--rootfs/etc/profile4
-rw-r--r--rootfs/etc/shadow0
-rwxr-xr-xstate/gen35
-rw-r--r--uboot.txt2
-rwxr-xr-xutil/mkrootfs40
15 files changed, 107 insertions, 18 deletions
diff --git a/.gitmodules b/.gitmodules
index 0419da6..2585820 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -8,3 +8,8 @@
url = https://github.com/beagleboard/linux
branch = v6.1.69-ti-r22
shallow = true
+[submodule "busybox"]
+ path = busybox
+ url = https://git.busybox.net/busybox
+ branch = 1_36_stable
+ shallow = true
diff --git a/Containerfile b/Containerfile
index 0fbe251..2213b19 100644
--- a/Containerfile
+++ b/Containerfile
@@ -17,6 +17,9 @@ run xbps-install -Sy cpio
run xbps-install -Sy xz
run xbps-install -Sy lz4
+# # temp:
+# run xbps-install -Sy ncurses-devel
+
# container directory on which the working directory on host is mounted
workdir /workdir
diff --git a/busybox b/busybox
new file mode 160000
+Subproject 5dc9ece3b9e87af0dcb01449821ac827391ac11
diff --git a/makefile b/makefile
index d6fe483..5a9886a 100644
--- a/makefile
+++ b/makefile
@@ -26,7 +26,7 @@ include ./env
export
.PHONY: all
-all:
+all: load_boot load_rootfs
.PHONY: sd_format sd_partition
sd_format: state/sdcard_fmt
@@ -52,7 +52,6 @@ state/sdcard_fmt: state/sdcard_part
bootloader/.config: state/submodules state/container_img
$(CTRIZE) $(MAKE) -C bootloader am335x_evm_config
-.PHONY: build_bootloader
build_bootloader: bootloader/.config state/container_img
$(CTRIZE) $(MAKE) -C bootloader
uboot.env: uboot.txt
@@ -66,13 +65,22 @@ $(BOOTLOADER_FILES): build_bootloader
kernel/.config: state/submodules state/container_img
$(CTRIZE) $(MAKE) -C kernel bb.org_defconfig
-.PHONY: build_kernel
build_kernel: kernel/.config state/container_img
$(CTRIZE) $(MAKE) -C kernel zImage am335x-boneblack.dtb
KERNEL_FILES += kernel/arch/$(ARCH)/boot/dts/am335x-boneblack.dtb
KERNEL_FILES += kernel/arch/$(ARCH)/boot/zImage
$(KERNEL_FILES): build_kernel
+busybox/.config: state/submodules state/container_img
+ $(CTRIZE) $(MAKE) -C busybox defconfig
+ sed -i 's/^[# ]*CONFIG_STATIC\>.*$$/CONFIG_STATIC=y/' $@
+ sed -i 's/^[# ]*CONFIG_PREFIX\>.*$$/CONFIG_PREFIX=".\/rootfs"/' $@
+busybox/busybox: busybox/.config state/container_img
+ $(CTRIZE) $(MAKE) -C busybox
+busybox/_install: busybox/busybox state/container_img
+ $(CTRIZE) $(MAKE) -C busybox install
+build_busybox: busybox/busybox
+
# NOTE: ordering is important!
FILES_PART_BOOT += $(BOOTLOADER_FILES)
FILES_PART_BOOT += $(KERNEL_FILES)
@@ -84,12 +92,12 @@ load_boot: $(FILES_PART_BOOT) state/sdcard_fmt
$(AS_ROOT) sync
$(AS_ROOT) umount mnt/boot
-# TODO
-# FILES_PART_ROOTFS += ....
-load_rootfs: state/sdcard_fmt
+FILES_PART_ROOTFS += $(shell find rootfs)
+FILES_PART_ROOTFS += busybox/rootfs
+load_rootfs: $(FILES_PART_ROOTFS) state/sdcard_fmt
mkdir -p mnt/rootfs
$(AS_ROOT) mount $(SDCARD_PART_ROOTFS) mnt/rootfs
- $(AS_ROOT) cp $(FILES_PART_ROOTFS) mnt/boot
+ $(AS_ROOT) util/mkrootfs mnt/rootfs
$(AS_ROOT) sync
$(AS_ROOT) umount mnt/rootfs
diff --git a/rootfs/etc/fstab b/rootfs/etc/fstab
new file mode 100644
index 0000000..e84b78a
--- /dev/null
+++ b/rootfs/etc/fstab
@@ -0,0 +1 @@
+proc /proc proc defaults 0 0
diff --git a/rootfs/etc/hostname b/rootfs/etc/hostname
new file mode 100644
index 0000000..cf7c0fc
--- /dev/null
+++ b/rootfs/etc/hostname
@@ -0,0 +1 @@
+gaming
diff --git a/rootfs/etc/hosts b/rootfs/etc/hosts
new file mode 100644
index 0000000..2601d5c
--- /dev/null
+++ b/rootfs/etc/hosts
@@ -0,0 +1 @@
+127.0.0.1 localhost gaming
diff --git a/rootfs/etc/init.d/rcS b/rootfs/etc/init.d/rcS
new file mode 100755
index 0000000..fc699e4
--- /dev/null
+++ b/rootfs/etc/init.d/rcS
@@ -0,0 +1,2 @@
+#!/bin/sh
+/bin/mount -a
diff --git a/rootfs/etc/inittab b/rootfs/etc/inittab
new file mode 100644
index 0000000..5f4a5fa
--- /dev/null
+++ b/rootfs/etc/inittab
@@ -0,0 +1,9 @@
+# /etc/inittab init(8)
+
+::sysinit:/etc/init.d/rcS
+::shutdown:/bin/umount -a -r
+::restart:/sbin/init
+
+# this could be really unsafe in production
+::respawn:/sbin/getty -L ttyS0 115200 vt100
+ttyS0::respawn:-/bin/login -f root
diff --git a/rootfs/etc/passwd b/rootfs/etc/passwd
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/rootfs/etc/passwd
diff --git a/rootfs/etc/profile b/rootfs/etc/profile
new file mode 100644
index 0000000..3c2be89
--- /dev/null
+++ b/rootfs/etc/profile
@@ -0,0 +1,4 @@
+# /etc/profile
+umask 022
+export PATH="$PATH:/usr/bin"
+
diff --git a/rootfs/etc/shadow b/rootfs/etc/shadow
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/rootfs/etc/shadow
diff --git a/state/gen b/state/gen
index e14e337..ddaf9d1 100755
--- a/state/gen
+++ b/state/gen
@@ -2,26 +2,39 @@
# create files in the same directory as this script
cd "$(dirname "$0")"
+set_state () {
+ filename="$1"
+ condition="$2"
+ if [ "$condition" -eq 0 ] ; then
+ # echo "$filename = TRUE" >&2
+ if ! [ -e "$filename" ] ; then
+ touch "$filename"
+ fi
+ else
+ # echo "$filename = FALSE" >&2
+ rm -f "$filename"
+ fi
+}
+
# container image (initialized here, updated in makefile)
$CTR image exists "$CTR_IMG_TAG" 1> /dev/null 2> /dev/null
-if [ $? -eq 0 ] ; then
- ! [ -e container_img ] && touch container_img
-else
- rm -f container_img
-fi
+set_state container_img $?
# check if all the submodules are initialized
-touch submodules
+SUBMODULES_OK=0
MODULES="$(git config \
--file "$(git rev-parse --show-toplevel)/.gitmodules" \
--name-only --get-regexp path |\
sed -e 's/^submodule\./modules\//' -e 's/\.path$/\/HEAD/')"
for git_module in $MODULES ; do
git rev-parse "$git_module" 1> /dev/null 2> /dev/null && continue
- rm -f submodules
+ echo "$git_module is the culprit" >&2
+ SUBMODULES_OK=1
done
+set_state submodules $SUBMODULES_OK
-rm -f sdcard_part sdcard_fmt
+SDCARD_PART_OK=1
+SDCARD_FMT_OK=1
# if no explicit SDCARD_DISK is set, guess which device is the sd card by
# checking if it is removable AND has a size of approx. 8GB
if [ -z "$SDCARD_DISK" ] ; then
@@ -46,7 +59,7 @@ if [ -n "$SDCARD_DISK" ] ; then
$3 == "part" { parts += 1 }
NR == 1 { if ($4 != "dos") exit(1) }
NR == 2 { if ($2 != 64 * 2^20) exit(1) }
- END { if (parts != 2) exit(1) }' && touch sdcard_part
+ END { if (parts != 2) exit(1) }' && SDCARD_PART_OK=0
if [ $? -eq 0 ] ; then
SDCARD_PART_BOOT="$(echo "$PARTS" | awk 'NR == 2 { print $1 }')"
@@ -62,10 +75,12 @@ if [ -n "$SDCARD_DISK" ] ; then
NR == 3 {
if ($5 != "ext4") exit(1)
if ($6 != "ROOTFS") exit(1)
- }' && touch sdcard_fmt
+ }' && SDCARD_FMT_OK=0
fi
fi
fi
+set_state sdcard_part $SDCARD_PART_OK
+set_state sdcard_fmt $SDCARD_FMT_OK
cat << EOF
\$(eval SDCARD_DISK := $SDCARD_DISK)
diff --git a/uboot.txt b/uboot.txt
index 44f6d3c..370ae50 100644
--- a/uboot.txt
+++ b/uboot.txt
@@ -2,7 +2,7 @@
bootdelay=0
# kernel arguments
-bootargs=console=ttyS0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait
+bootargs=console=ttyS0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext4 init=/sbin/init rootwait
# boot command (three commands separated by semicolons):
# 1. load zImage format kernel at address 0x80008000
diff --git a/util/mkrootfs b/util/mkrootfs
new file mode 100755
index 0000000..5818fdb
--- /dev/null
+++ b/util/mkrootfs
@@ -0,0 +1,40 @@
+#!/bin/sh
+OLDPWD="$PWD"
+cd "$(dirname "$0")"
+BUSYBOX_FS="$(realpath ../busybox/rootfs)"
+OVERLAY_FS="$(realpath ../rootfs)"
+cd "$OLDPWD"
+
+# change into the (mounted) target rootfs folder
+cd "$1"
+
+# scaffold folders
+for dir in bin dev etc home lib mnt opt proc root run sbin srv sys tmp usr var ; do
+ mkdir -p "$dir"
+done
+
+# create special devices
+! [ -c dev/mem ] && mknod dev/mem c 1 1
+! [ -c dev/null ] && mknod dev/null c 1 3
+! [ -c dev/random ] && mknod dev/random c 1 8
+! [ -c dev/urandom ] && mknod dev/urandom c 1 9
+! [ -c dev/zero ] && mknod dev/zero c 1 5
+
+# copy busybox files and overlay files
+CPFLAGS='--no-dereference --recursive --preserve=mode,timestamps,links --no-preserve=owner'
+cp $CPFLAGS "$BUSYBOX_FS/." .
+cp $CPFLAGS "$OVERLAY_FS/." .
+
+# setuid busybox
+chmod a=xrs,u+w bin/busybox
+
+# # create /etc/passwd
+# if ! [ -e etc/passwd ] ; then
+# # TODO: add root to a group
+# echo "root:x:0:0::/root:/bin/sh" > etc/passwd
+# fi
+# # and /etc/shadow
+# if ! [ -e etc/shadow ] ; then
+# echo "root:$(mkpasswd alpine):::::::" > etc/shadow
+# fi
+#