blob: 5a9886aafa74b8d23f4f3eddd6751d97dc3b54d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# use sudo (non interactively) when running as regular user
ifneq ($(shell id -u),0)
AS_ROOT := sudo -n
endif
CTR := podman
CTR_IMG_TAG := avans-linux
CTRIZE := $(CTR) run
CTRIZE += --rm
CTRIZE += --tty
CTRIZE += --volume /tmp:/tmp:rw
CTRIZE += --volume .:/workdir:rw
CTRIZE += --env-file ./env
CTRIZE += --env MAKE*
CTRIZE += $(CTR_IMG_TAG)
export
# create dummy files to represent non-file targets (container image build
# status, sd card partition status, git submodule initialization, etc.)
$(eval $(shell state/gen))
# read environment variables from ./env
include ./env
export
.PHONY: all
all: load_boot load_rootfs
.PHONY: sd_format sd_partition
sd_format: state/sdcard_fmt
sd_partition: state/sdcard_part
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 $@
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
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
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:
@echo 'ENVIRONMENT'
@state/gen | grep ':=' | sed -e 's/^\$$(eval / /' -e 's/)$$//'
@echo 'TARGETS'
@ls state | awk '$$0 == "gen" { next } { print }' | sed 's/^/ /'
|