-
-
Notifications
You must be signed in to change notification settings - Fork 392
Expand file tree
/
Copy pathMakefile
More file actions
174 lines (150 loc) · 6.6 KB
/
Makefile
File metadata and controls
174 lines (150 loc) · 6.6 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
BR_VER = 2024.02.10
BR_MAKE = $(MAKE) -C $(TARGET)/buildroot-$(BR_VER) BR2_EXTERNAL=$(PWD)/general O=$(TARGET)
BR_LINK = https://github.com/buildroot/buildroot/archive
BR_FILE = /tmp/buildroot-$(BR_VER).tar.gz
BR_CONF = $(TARGET)/openipc_defconfig
TARGET ?= $(PWD)/output
export CMAKE_POLICY_VERSION_MINIMUM := 3.5
CONFIG = $(error variable BOARD not defined)
TIMER := $(shell date +%s)
ifeq ($(or $(MAKECMDGOALS), $(BOARD)),)
LIST := $(shell find ./br-ext-*/configs/*_defconfig | sort | \
sed -E "s/br-ext-chip-(.+).configs.(.+)_defconfig/'\2' '\1 \2'/")
BOARD := $(or $(shell whiptail --title "Available boards" --menu "Select a config:" 20 70 12 \
--notags $(LIST) 3>&1 1>&2 2>&3),$(CONFIG))
endif
ifneq ($(BOARD),)
CONFIG := $(shell find br-ext-*/configs/*_defconfig | grep -m1 $(BOARD))
include $(CONFIG)
endif
all: build repack timer
build: defconfig
@$(BR_MAKE) all -j$(shell nproc)
br-%: defconfig
@$(BR_MAKE) $(subst br-,,$@) -j$(shell nproc)
defconfig: prepare
@echo --- $(or $(CONFIG),$(error variable BOARD not found))
@cat $(CONFIG) $(PWD)/general/openipc.fragment > $(BR_CONF)
@grep -s '^BR2_GLOBAL_PATCH_DIR=' $(CONFIG) >> $(BR_CONF) || true
@$(BR_MAKE) BR2_DEFCONFIG=$(BR_CONF) defconfig
prepare:
@if test ! -e $(TARGET)/buildroot-$(BR_VER); then \
wget -c -q $(BR_LINK)/$(BR_VER).tar.gz -O $(BR_FILE); \
mkdir -p $(TARGET); tar -xf $(BR_FILE) -C $(TARGET); fi
help:
@printf "BR-OpenIPC usage:\n \
- make list - show available device configurations\n \
- make deps - install build dependencies\n \
- make clean - remove defconfig and target folder\n \
- make package - list available packages\n \
- make distclean - remove buildroot and output folder\n \
- make br-linux - build linux kernel only\n\n"
list:
@ls -1 br-ext-chip-*/configs
package:
@find $(PWD)/general/package/* -maxdepth 0 -type d -printf "br-%f\n" | grep -v patch
toolname:
@echo toolchain.$(BR2_OPENIPC_SOC_VENDOR)-$(BR2_OPENIPC_SOC_FAMILY)
clean:
@rm -rf $(TARGET)/build $(TARGET)/images $(TARGET)/per-package $(TARGET)/target
distclean:
@rm -rf $(BR_FILE) $(TARGET)
audit-abi:
@python3 $(PWD)/general/scripts/audit-vendor-abi.py
deps:
sudo apt-get install -y automake autotools-dev bc build-essential cpio \
curl file fzf git libncurses-dev libtool lzop make rsync unzip wget libssl-dev
timer:
@echo - Build time: $(shell date -d @$(shell expr $(shell date +%s) - $(TIMER)) -u +%M:%S)
toolchain: defconfig
ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
@cp -rf $(PWD)/general/package/gcc $(TARGET)/buildroot-$(BR_VER)/package
@$(MAKE) -f $(PWD)/general/toolchain.mk BR_CONF=$(BR_CONF) CONFIG=$(PWD)/$(CONFIG)
@$(BR_MAKE) BR2_DEFCONFIG=$(BR_CONF) defconfig
endif
@$(BR_MAKE) sdk -j$(shell nproc)
@$(call BUNDLE_SDK)
toolchain-asan: defconfig
ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
@cp -rf $(PWD)/general/package/gcc $(TARGET)/buildroot-$(BR_VER)/package
@$(MAKE) -f $(PWD)/general/toolchain.mk BR_CONF=$(BR_CONF) CONFIG=$(PWD)/$(CONFIG)
@$(BR_MAKE) BR2_DEFCONFIG=$(BR_CONF) defconfig
endif
@echo 'BR2_EXTRA_GCC_CONFIG_OPTIONS="--enable-libsanitizer"' >> $(BR_CONF)
@$(BR_MAKE) BR2_DEFCONFIG=$(BR_CONF) defconfig
@$(BR_MAKE) sdk -j$(shell nproc)
@$(call BUNDLE_SDK)
repack:
ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS),y)
ifeq ($(BR2_OPENIPC_SOC_VENDOR),"rockchip")
@$(call PREPARE_REPACK,zboot.img,4096,rootfs.squashfs,8192,nor)
else ifeq ($(BR2_OPENIPC_FLASH_SIZE),"8")
@$(call PREPARE_REPACK,uImage,2048,rootfs.squashfs,5120,nor)
else
@$(call PREPARE_REPACK,uImage,2048,rootfs.squashfs,8192,nor)
endif
endif
ifeq ($(BR2_TARGET_ROOTFS_UBI),y)
ifneq ($(filter $(BR2_OPENIPC_SOC_VENDOR),"rockchip" "sigmastar"),)
@$(call PREPARE_REPACK,,,rootfs.ubi,16384,nand)
else
@$(call PREPARE_REPACK,uImage,4096,rootfs.ubi,16384,nand)
endif
endif
ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS),y)
@$(call PREPARE_REPACK,uImage,16384,,,initramfs)
endif
define BUNDLE_SDK
OSDRV_DIR=$(PWD)/general/package/$(BR2_OPENIPC_SOC_VENDOR)-osdrv-$(BR2_OPENIPC_SOC_FAMILY)/files; \
SDK_TGZ=$$(find $(TARGET)/images -name '*_sdk-buildroot.tar.gz' | head -1); \
COMPAT_SRC=$(PWD)/general/package/uclibc-compat/src/uclibc-compat.c; \
SDK_CC=$$(ls $(TARGET)/host/bin/*-gcc 2>/dev/null | head -1); \
if [ -d "$$OSDRV_DIR" ] && [ -n "$$SDK_TGZ" ]; then \
SDK_TOP=$$(tar tzf $$SDK_TGZ | head -1 | cut -d/ -f1); \
rm -rf /tmp/sdk-overlay && mkdir -p /tmp/sdk-overlay/$$SDK_TOP/sdk; \
cp -a $$OSDRV_DIR/* /tmp/sdk-overlay/$$SDK_TOP/sdk/; \
if [ -f "$$COMPAT_SRC" ] && [ -n "$$SDK_CC" ]; then \
$$SDK_CC -shared -Wall -O2 -fPIC \
-o /tmp/sdk-overlay/$$SDK_TOP/sdk/lib/libuclibc-compat.so \
$$COMPAT_SRC; \
COMPAT_STATIC=$(PWD)/general/package/uclibc-compat/src/uclibc-compat-static.c; \
if [ -f "$$COMPAT_STATIC" ]; then \
SDK_AR=$$(echo $$SDK_CC | sed 's/-gcc$$/-ar/'); \
$$SDK_CC -Wall -O2 -fPIC -c \
-o /tmp/sdk-overlay/$$SDK_TOP/sdk/lib/uclibc-compat-static.o \
$$COMPAT_STATIC; \
$$SDK_AR rcs /tmp/sdk-overlay/$$SDK_TOP/sdk/lib/libuclibc-compat-static.a \
/tmp/sdk-overlay/$$SDK_TOP/sdk/lib/uclibc-compat-static.o; \
rm -f /tmp/sdk-overlay/$$SDK_TOP/sdk/lib/uclibc-compat-static.o; \
fi; \
fi; \
gunzip $$SDK_TGZ && \
tar rf $${SDK_TGZ%.tar.gz}.tar -C /tmp/sdk-overlay $$SDK_TOP && \
gzip $${SDK_TGZ%.tar.gz}.tar; \
rm -rf /tmp/sdk-overlay; \
fi
endef
define PREPARE_REPACK
$(if $(1),$(call CHECK_SIZE,$(1),$(2)))
$(if $(3),$(call CHECK_SIZE,$(3),$(4)))
$(call REPACK_FIRMWARE,$(1),$(3),$(5))
endef
define CHECK_SIZE
$(eval FILE_SIZE = $(shell expr $(shell stat -c %s $(TARGET)/images/$(1) || echo 0) / 1024))
if test $(FILE_SIZE) -eq 0; then exit 1; fi
echo - $(1): [$(FILE_SIZE)KB/$(2)KB]
if test $(FILE_SIZE) -gt $(2); then \
echo -- size exceeded by: $(shell expr $(FILE_SIZE) - $(2))KB; exit 1; fi
endef
define REPACK_FIRMWARE
cd $(TARGET)/images && if test -e rootfs.tar; then mv -f rootfs.tar rootfs.$(BR2_OPENIPC_SOC_MODEL).tar; fi
$(if $(1),cd $(TARGET)/images && if test -e $(1); then mv -f $(1) $(1).$(BR2_OPENIPC_SOC_MODEL); fi)
$(if $(2),cd $(TARGET)/images && if test -e $(2); then mv -f $(2) $(2).$(BR2_OPENIPC_SOC_MODEL); fi)
$(if $(1),cd $(TARGET)/images && md5sum $(1).$(BR2_OPENIPC_SOC_MODEL) > $(1).$(BR2_OPENIPC_SOC_MODEL).md5sum)
$(if $(2),cd $(TARGET)/images && md5sum $(2).$(BR2_OPENIPC_SOC_MODEL) > $(2).$(BR2_OPENIPC_SOC_MODEL).md5sum)
$(if $(1),$(eval KERNEL = $(1).$(BR2_OPENIPC_SOC_MODEL) $(1).$(BR2_OPENIPC_SOC_MODEL).md5sum),$(eval KERNEL =))
$(if $(2),$(eval ROOTFS = $(2).$(BR2_OPENIPC_SOC_MODEL) $(2).$(BR2_OPENIPC_SOC_MODEL).md5sum),$(eval ROOTFS =))
$(eval ARCHIVE = openipc.$(BR2_OPENIPC_SOC_MODEL)-$(3)-$(BR2_OPENIPC_VARIANT).tgz)
cd $(TARGET)/images && tar -czf $(ARCHIVE) $(KERNEL) $(ROOTFS)
rm -f $(TARGET)/images/*.md5sum
endef