diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-02-06 13:22:04 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-02-06 13:22:04 +0100 |
commit | a9ef380662da3efa382017ff8423f1a894b31bfd (patch) | |
tree | 26c160523c050945502408148faae6508712033b | |
parent | ae327cc50fd9d3e59e9f60088243adfc69cb312e (diff) |
dynamic linking application starts
-rw-r--r-- | .gitignore | 7 | ||||
-rw-r--r-- | base.mk | 34 | ||||
-rw-r--r-- | makefile | 75 | ||||
-rw-r--r-- | rootfs/etc/network/interfaces | 4 | ||||
-rw-r--r-- | rootfs/etc/passwd | 1 | ||||
-rw-r--r-- | rootfs/etc/profile | 3 | ||||
-rw-r--r-- | rootfs/etc/shadow | 1 | ||||
-rw-r--r-- | software.mk | 19 | ||||
-rw-r--r-- | software/helloworld/.gitignore | 1 | ||||
-rw-r--r-- | software/helloworld/main.c | 12 | ||||
-rw-r--r-- | software/helloworld/makefile | 11 | ||||
-rw-r--r-- | state.mk | 18 | ||||
-rwxr-xr-x | util/mkrootfs | 14 |
13 files changed, 131 insertions, 69 deletions
@@ -2,3 +2,10 @@ state/* !state/gen mnt uboot.env + +# BEGIN UPDATE FROM `make __software_files` +rootfs/bin/helloworld +rootfs/lib/libc.so.6 +rootfs/lib/ld-linux-armhf.so.3 +# END UPDATE FROM `make __software_files` + @@ -0,0 +1,34 @@ +# NOTE: MLO MUST be copied first +BOOTLOADER_FILES += bootloader/MLO +BOOTLOADER_FILES += bootloader/u-boot.img +BOOTLOADER_FILES += bootloader/u-boot.dtb +bootloader/.config: state/submodules state/container_img + $(CTRIZE) $(MAKE) -C bootloader am335x_evm_config +$(BOOTLOADER_FILES)&: bootloader/.config state/container_img + $(CTRIZE) $(MAKE) -C bootloader + +BOOTLOADER_FILES += uboot.env +uboot.env: uboot.txt + $(CTRIZE) bootloader/tools/mkenvimage -p 0x00 -s 0x20000 -o $@ $< + +KERNEL_FILES += kernel/arch/$(ARCH)/boot/dts/am335x-boneblack.dtb +KERNEL_FILES += kernel/arch/$(ARCH)/boot/zImage +kernel/.config: state/submodules state/container_img + $(CTRIZE) $(MAKE) -C kernel bb.org_defconfig +$(KERNEL_FILES)&: kernel/.config state/container_img + $(CTRIZE) $(MAKE) -C kernel zImage am335x-boneblack.dtb + +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/rootfs: busybox/busybox state/container_img + $(CTRIZE) $(MAKE) -C busybox install + +FILES_PART_BOOT += $(BOOTLOADER_FILES) +FILES_PART_BOOT += $(KERNEL_FILES) +FILES_PART_ROOTFS += $(shell find rootfs) +FILES_PART_ROOTFS += busybox/rootfs + @@ -25,86 +25,37 @@ $(eval $(shell state/gen)) include ./env export -.PHONY: all -all: load_boot load_rootfs +.PHONY: FORCE -.PHONY: sd_format sd_partition -sd_format: state/sdcard_fmt -sd_partition: state/sdcard_part +all: FORCE load_boot load_rootfs -state/container_img: Containerfile - $(CTR) build --tag $(CTR_IMG_TAG) . - touch $@ +include state.mk +include base.mk +include software.mk -state/submodules: - git submodule update --init - touch $@ +build_kernel: FORCE $(KERNEL_FILES) +build_bootloader: FORCE $(BOOTLOADER_FILES) +build_software: FORCE $(SOFTWARE_FILES) -state/sdcard_part: - $(AS_ROOT) util/part $(SDCARD_DISK) - touch $@ - -state/sdcard_fmt: state/sdcard_part - $(eval $(shell state/gen)) - $(AS_ROOT) mkfs.vfat -a -F 16 -n BOOT $(SDCARD_PART_BOOT) - $(AS_ROOT) mkfs.ext4 -F -L ROOTFS $(SDCARD_PART_ROOTFS) - touch $@ - -bootloader/.config: state/submodules state/container_img - $(CTRIZE) $(MAKE) -C bootloader am335x_evm_config -build_bootloader: bootloader/.config state/container_img - $(CTRIZE) $(MAKE) -C bootloader -uboot.env: uboot.txt - $(CTRIZE) bootloader/tools/mkenvimage -p 0x00 -s 0x20000 -o $@ $< -# NOTE: MLO MUST be copied first -BOOTLOADER_FILES += bootloader/MLO -BOOTLOADER_FILES += bootloader/u-boot.img -BOOTLOADER_FILES += bootloader/u-boot.dtb -BOOTLOADER_FILES += uboot.env -$(BOOTLOADER_FILES): build_bootloader - -kernel/.config: state/submodules state/container_img - $(CTRIZE) $(MAKE) -C kernel bb.org_defconfig -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) -.PHONY: load_boot load_rootfs -load_boot: $(FILES_PART_BOOT) state/sdcard_fmt +load_boot: FORCE $(FILES_PART_BOOT) state/sdcard_fmt mkdir -p mnt/boot $(AS_ROOT) mount $(SDCARD_PART_BOOT) mnt/boot $(AS_ROOT) cp $(FILES_PART_BOOT) mnt/boot $(AS_ROOT) sync $(AS_ROOT) umount mnt/boot -FILES_PART_ROOTFS += $(shell find rootfs) -FILES_PART_ROOTFS += busybox/rootfs -load_rootfs: $(FILES_PART_ROOTFS) state/sdcard_fmt +load_rootfs: FORCE $(FILES_PART_ROOTFS) state/sdcard_fmt mkdir -p mnt/rootfs $(AS_ROOT) mount $(SDCARD_PART_ROOTFS) mnt/rootfs $(AS_ROOT) util/mkrootfs mnt/rootfs $(AS_ROOT) sync $(AS_ROOT) umount mnt/rootfs -.PHONY: status -status: +status: FORCE @echo 'ENVIRONMENT' @state/gen | grep ':=' | sed -e 's/^\$$(eval / /' -e 's/)$$//' @echo 'TARGETS' @ls state | awk '$$0 == "gen" { next } { print }' | sed 's/^/ /' +__software_files: FORCE + @echo $(SOFTWARE_FILES) | tr ' ' '\n' diff --git a/rootfs/etc/network/interfaces b/rootfs/etc/network/interfaces new file mode 100644 index 0000000..6da47b0 --- /dev/null +++ b/rootfs/etc/network/interfaces @@ -0,0 +1,4 @@ +# interfaces(5) configuration +auto eth0 +iface eth0 inet dhcp + diff --git a/rootfs/etc/passwd b/rootfs/etc/passwd new file mode 100644 index 0000000..fd6236d --- /dev/null +++ b/rootfs/etc/passwd @@ -0,0 +1 @@ +root:x:0:0::/root:/bin/sh diff --git a/rootfs/etc/profile b/rootfs/etc/profile index 557b21a..8e38c52 100644 --- a/rootfs/etc/profile +++ b/rootfs/etc/profile @@ -1,5 +1,6 @@ # /etc/profile umask 022 -export PATH="$PATH:/usr/bin" cd "$HOME" +export PATH="$PATH:/usr/bin" +export LD_LIBRARY_PATH="/lib" diff --git a/rootfs/etc/shadow b/rootfs/etc/shadow new file mode 100644 index 0000000..18acc30 --- /dev/null +++ b/rootfs/etc/shadow @@ -0,0 +1 @@ +root:x:0:root diff --git a/software.mk b/software.mk new file mode 100644 index 0000000..1635f04 --- /dev/null +++ b/software.mk @@ -0,0 +1,19 @@ +software/helloworld/helloworld: state/container_img + $(CTRIZE) $(MAKE) -C software/helloworld +rootfs/bin/helloworld: software/helloworld/helloworld + mkdir -p $(dir $@) + cp $^ $@ +SOFTWARE_FILES += rootfs/bin/helloworld + +SHARED_LIBS += rootfs/lib/libc.so.6 +SHARED_LIBS += rootfs/lib/ld-linux-armhf.so.3 +$(SHARED_LIBS)&: state/container_img + mkdir -p rootfs/lib + $(CTRIZE) cp $(SHARED_LIBS:rootfs/lib/%=/usr/arm-linux-gnueabihf/lib/%) rootfs/lib +SOFTWARE_FILES += $(SHARED_LIBS) + +rootfs/usr/share/udhcpc/default.script: busybox/examples/udhcp/simple.script state/submodules + cp $< $@ + chmod +x $@ +SOFTWARE_FILES += rootfs/usr/share/udhcpc/default.script + diff --git a/software/helloworld/.gitignore b/software/helloworld/.gitignore new file mode 100644 index 0000000..31e0fce --- /dev/null +++ b/software/helloworld/.gitignore @@ -0,0 +1 @@ +helloworld diff --git a/software/helloworld/main.c b/software/helloworld/main.c new file mode 100644 index 0000000..126a97a --- /dev/null +++ b/software/helloworld/main.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#include <sys/random.h> + +int main(void) { + int x; + + getrandom(&x, sizeof(typeof(x)), 0); + printf("Random number from the kernel: %d\n", x); + + return 0; +} + diff --git a/software/helloworld/makefile b/software/helloworld/makefile new file mode 100644 index 0000000..0cd6c19 --- /dev/null +++ b/software/helloworld/makefile @@ -0,0 +1,11 @@ +CC = $(CROSS_COMPILE)gcc + +LFLAGS += -lc + +helloworld: main.c + $(CC) $^ $(CFLAGS) $(LFLAGS) -o $@ + +.PHONY: clean +clean: + $(RM) helloworld + diff --git a/state.mk b/state.mk new file mode 100644 index 0000000..394b78e --- /dev/null +++ b/state.mk @@ -0,0 +1,18 @@ +state/container_img: Containerfile + $(CTR) build --tag $(CTR_IMG_TAG) . + touch $@ + +state/submodules: + git submodule update --init + touch $@ + +state/sdcard_part: + $(AS_ROOT) util/part $(SDCARD_DISK) + touch $@ + +state/sdcard_fmt: state/sdcard_part + $(eval $(shell state/gen)) + $(AS_ROOT) mkfs.vfat -a -F 16 -n BOOT $(SDCARD_PART_BOOT) + $(AS_ROOT) mkfs.ext4 -F -L ROOTFS $(SDCARD_PART_ROOTFS) + touch $@ + diff --git a/util/mkrootfs b/util/mkrootfs index 91eff68..ae1f489 100755 --- a/util/mkrootfs +++ b/util/mkrootfs @@ -1,6 +1,7 @@ #!/bin/sh OLDPWD="$PWD" cd "$(dirname "$0")" +BUSYBOX_SRC="$(realpath ../busybox)" BUSYBOX_FS="$(realpath ../busybox/rootfs)" OVERLAY_FS="$(realpath ../rootfs)" cd "$OLDPWD" @@ -9,7 +10,13 @@ cd "$OLDPWD" cd "$1" # scaffold folders -for dir in bin dev etc home lib mnt opt proc root run sbin srv sys tmp usr var ; do +for dir in \ + bin dev etc home lib proc root sbin srv sys tmp usr var \ + var/log var/run \ + etc/network/if-down.d etc/network/if-post-down.d \ + etc/network/if-pre-up.d etc/network/if-up.d \ + usr/share/udhcpc +do mkdir -p "$dir" done @@ -28,10 +35,5 @@ cp $CPFLAGS "$OVERLAY_FS/." . # setuid busybox chmod a=xrs,u+w bin/busybox -# create a root user -! [ -e etc/passwd ] && echo "root:x:0:0::/root:/bin/sh" > etc/passwd -! [ -e etc/shadow ] && echo "root:!:0:0:99999:0:::" > etc/shadow -! [ -e etc/group ] && echo "root:x:0:root" > etc/shadow - # exit safely (continue makefile) exit 0 |