From 2b2cb626b527606436b6d7903407b7dbf66d9671 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 2 Feb 2024 21:52:11 +0100 Subject: WIP more unneeded automation of setup --- .gitmodules | 4 ++-- bootloader | 1 + makefile | 65 +++++++++++++++++++++++++++++++++---------------------------- state/gen | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ u-boot | 1 - 5 files changed, 103 insertions(+), 33 deletions(-) create mode 160000 bootloader create mode 100755 state/gen delete mode 160000 u-boot diff --git a/.gitmodules b/.gitmodules index b17d981..b2f8062 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ -[submodule "u-boot"] - path = u-boot +[submodule "bootloader"] + path = bootloader url = https://source.denx.de/u-boot/u-boot.git shallow = true [submodule "kernel"] diff --git a/bootloader b/bootloader new file mode 160000 index 0000000..050a9b9 --- /dev/null +++ b/bootloader @@ -0,0 +1 @@ +Subproject commit 050a9b981d6a835133521b599be3ae189ce70f41 diff --git a/makefile b/makefile index 6b4ce78..da94b65 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,3 @@ -# read environment variables from ./env -include ./env -export - # use sudo (non interactively) when running as regular user ifneq ($(shell id -u),0) AS_ROOT := sudo -n @@ -20,42 +16,51 @@ CTRIZE := $(CTR) run --rm --interactive --tty CTRIZE += --volume .:/workdir:rw CTRIZE += --env-file ./env CTRIZE += $(CTR_IMG_TAG) +export + +# create files that represent otherwise PHONY targets +$(shell state/gen) +-include state/auto.mk + +# read environment variables from ./env +include ./env +export .PHONY: all -all: os_bootloader +all: $(BOOTLOADER_FILES) -.PHONY: container_img -container_img: Containerfile +state/container_img: Containerfile $(CTR) build --tag $(CTR_IMG_TAG) . + touch $@ -# this list holds the .git files in each submodule folder (add -# $(SUBMODULE_INIT) as prerequisite to require the submodules to exist) -SUBMODULE_INIT += ./u-boot/.git -SUBMODULE_INIT += ./kernel/.git -$(SUBMODULE_INIT): +state/submodules: $(GIT) submodule init $(GIT) submodule update + touch $@ -.PHONY: os_bootloader -os_bootloader: $(SUBMODULE_INIT) - $(CTRIZE) $(MAKE) -$(MAKEFLAGS) -C u-boot am335x_evm_config - $(CTRIZE) $(MAKE) -$(MAKEFLAGS) -C u-boot +BOOTLOADER_FILES += bootloader/MLO +BOOTLOADER_FILES += bootloader/u-boot.img +BOOTLOADER_FILES += bootloader/u-boot.dtb +bootloader/.config: state/submodules + $(CTRIZE) $(MAKE) -$(MAKEFLAGS) -C bootloader am335x_evm_config +$(BOOTLOADER_FILES): bootloader/.config + $(CTRIZE) $(MAKE) -$(MAKEFLAGS) -C bootloader -.PHONY: os_kernel -os_kernel: +KERNEL_FILES += kernel/ +kernel/.config: state/submodules $(CTRIZE) $(MAKE) -$(MAKEFLAGS) -C kernel omap2plus_defconfig +$(KERNEL_FILES): kernel/.config $(CTRIZE) $(MAKE) -$(MAKEFLAGS) -C kernel -# sd card block device prefix (assumed partition numbers, see readme.md) -# SDCARD_BD_PREFIX := /dev/sdc -SDCARD_BD_PREFIX := /dev/mmcblk0p -load_bootloader: $(os_bootloader) - mkdir -p /tmp/sdcard-boot - $(MOUNT) $(SDCARD_BD_PREFIX)1 /tmp/sdcard-boot - $(AS_ROOT) $(CP) u-boot/MLO u-boot/u-boot.img u-boot/u-boot.dtb /tmp/sdcard-boot - $(UMOUNT) $(SDCARD_BD_PREFIX)1 - -format_sd: - $(AS_ROOT) mkfs.vfat -n BOOT -F 32 $(SDCARD_BD_PREFIX)1 - $(AS_ROOT) mkfs.ext4 -L ROOTFS -F $(SDCARD_BD_PREFIX)2 +.PHONY: load_bootloader +load_bootloader: $(BOOTLOADER_FILES) + mkdir -p mnt/boot mnt/rootfs + $(MOUNT) $(SDCARD_PART_BOOT) mnt/boot + $(AS_ROOT) $(CP) $(BOOTLOADER_FILES) mnt/boot + $(UMOUNT) mnt/boot + +.PHONY: sd_format +sd_format: + $(AS_ROOT) mkfs.vfat -n BOOT -F 32 $(SDCARD_PART_BOOT) + $(AS_ROOT) mkfs.ext4 -L ROOTFS -F $(SDCARD_PART_ROOTFS) diff --git a/state/gen b/state/gen new file mode 100755 index 0000000..23a3382 --- /dev/null +++ b/state/gen @@ -0,0 +1,65 @@ +#!/bin/sh +# redirect stdout to stderr (stdout gets interpreted by make) +exec 1>&2 +# create files in the same directory as this script +cd "$(dirname "$0")" +# do not run anything if make was run with -n (dry run) +# [ "${MAKEFLAGS#*n}" != "$MAKEFLAGS" ] && exit + +touch_rm_exit_code() { [ $? -eq 0 ] && touch "$1" || rm -f "$1" ; } + +# container image (initialized here, updated in makefile) +$CTR image exists "$CTR_IMG_TAG" 1> /dev/null 2> /dev/null +touch_rm_exit_code container_img + +# check if all the submodules are initialized +test -z "$(git submodule status | grep '^-')" +touch_rm_exit_code submodules + +rm -f auto.mk + +# guess which device is the sd card by size (around 8GB) +for SDCARD_DISK in "$(lsblk --noheadings --bytes --output PATH,SIZE,TYPE | awk ' + $3 != "disk" { next } + ($2 < 7900000000) { next } + ($2 > 8000000000) { next } + { print $1 }')" +do + [ -z "$SDCARD_DISK" ] && continue + # check if the sd card is already correctly partitioned & formatted + PARTS="$(lsblk "$SDCARD_DISK" --noheadings --output PATH,SIZE,TYPE,PTTYPE,FSTYPE,LABEL | awk ' + NR == 1 { + if ($4 != "dos") exit(1) + } + NR == 2 { + if ($6 != "BOOT") exit(1) + if ($2 != "64M") exit(1) + if ($5 != "vfat") exit(1) + print $1 + } + NR == 3 { + if ($6 != "ROOTFS") exit(1) + if ($5 != "ext4") exit(1) + print $1 + } + END { if (NR != 3) exit(1) }')" || continue + SDCARD_PART_BOOT="$(echo "$PARTS" | sed '1!d')" + SDCARD_PART_ROOTFS="$(echo "$PARTS" | sed '2!d')" + break +done + +if [ -n "$SDCARD_DISK" ]; then + echo "SDCARD_DISK ?= $SDCARD_DISK" >> auto.mk +fi + +if [ -n "$SDCARD_PART_BOOT" ] && [ -n "$SDCARD_PART_ROOTFS" ]; then + echo "SDCARD_PART_BOOT ?= $SDCARD_PART_BOOT" >> auto.mk + echo "SDCARD_PART_ROOTFS ?= $SDCARD_PART_ROOTFS" >> auto.mk + touch sdcard_part_fmt +else + rm -f sdcard_part_fmt +fi + +# export all variables in auto.mk +echo "export" >> auto.mk + diff --git a/u-boot b/u-boot deleted file mode 160000 index 050a9b9..0000000 --- a/u-boot +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 050a9b981d6a835133521b599be3ae189ce70f41 -- cgit v1.2.3