-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
243 lines (198 loc) · 7.92 KB
/
Makefile
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
PRODUCT ?= duckbill
HWREV ?= v2
CROSS_COMPILE ?= arm-linux-gnueabi-
JOBS ?= $(shell cat /proc/cpuinfo | grep processor | wc -l)
ifeq ($(PRODUCT),evachargese)
BL_BOARD ?= evachargese
PRODUCT_COMMON:=
else
BL_BOARD ?= duckbill
PRODUCT_COMMON:=duckbill
endif
ROOTFSSIZE:=$(shell echo $$((384 * 1024 * 1024)))
ROOTFSCHUNKSIZE:=$(shell echo $$((64 * 1024 * 1024)))
ifeq ($(PRODUCT),duckbill)
ROOTFSSIZE:=$(shell echo $$((640 * 1024 * 1024)))
endif
ifeq ($(PRODUCT),evachargese)
ROOTFSSIZE:=$(shell echo $$((512 * 1024 * 1024)))
endif
ifeq ($(BL_BOARD),evachargese)
BOOTSTREAM:=imx-bootlets/imx28_ivt_linux.sb
else
BOOTSTREAM:=u-boot/u-boot.sb
endif
TOOLS:=${CURDIR}/tools
PATH:=$(TOOLS)/ptgen:$(TOOLS)/fsl-imx-uuc:${CURDIR}/u-boot/tools/env:$(TOOLS)/elftosb/bld/linux:$(PATH)
export PATH ROOTFSSIZE
.PHONY: help
help:
@echo 'STIP - Simple Target Image Builder'
@echo '----------------------------------'
@echo ''
@echo 'Please have a look at the README.md for valid make targets.'
@echo ''
.PHONY: jessie-requirements
jessie-requirements:
sudo apt-get install -y apt-transport-https build-essential make patch multistrap curl bc binfmt-support libssl-dev qemu-user-static lzop
sudo sh -c 'echo "deb http://emdebian.org/tools/debian/ jessie main" > /etc/apt/sources.list.d/crosstools.list'
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | sudo apt-key add -
sudo dpkg --add-architecture armel
sudo apt-get update
sudo apt-get install -y crossbuild-essential-armel
.PHONY: trusty-requirements xenial-requirements zesty-requirements
trusty-requirements xenial-requirements zesty-requirements:
sudo apt-get install -y apt-transport-https build-essential make patch multistrap bc binfmt-support libssl-dev qemu-user-static lzop
sudo apt-get install -y gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
sudo sh -c 'if [ `dpkg -s multistrap | grep Version | cut -d: -f2` = "2.2.0ubuntu1" ]; then \
cp /usr/sbin/multistrap /usr/sbin/multistrap.orig; \
sed -i -e "s/-y \$$forceyes install/-y install/" /usr/sbin/multistrap; \
fi'
prepare:
git submodule init
git submodule update
tools: tools/fsl-imx-uuc/sdimage tools/ptgen/ptgen tools/elftosb/elftosb
tools/fsl-imx-uuc/sdimage: tools/fsl-imx-uuc/sdimage.c tools/fsl-imx-uuc/Makefile
$(MAKE) -C tools/fsl-imx-uuc
tools/ptgen: tools/ptgen/ptgen.c tools/ptgen/Makefile
$(MAKE) -C tools/ptgen
tools/elftosb/elftosb:
$(MAKE) -C tools/elftosb
.PHONY: tools-clean
tools-clean:
$(MAKE) -C tools/fsl-imx-uuc clean
$(MAKE) -C tools/ptgen clean
$(MAKE) -C tools/elftosb clean
.PHONY: u-boot uboot
u-boot uboot: u-boot/u-boot.sb
u-boot/u-boot.sb:
$(MAKE) -C u-boot $(BL_BOARD)_defconfig CROSS_COMPILE="$(CROSS_COMPILE)"
$(MAKE) -C u-boot -j $(JOBS) env
ln -sf fw_printenv u-boot/tools/env/fw_setenv
$(MAKE) -C u-boot -j $(JOBS) u-boot.sb CROSS_COMPILE="$(CROSS_COMPILE)"
linux: linux/arch/arm/boot/zImage
.PHONY: linux/arch/arm/boot/zImage
linux/arch/arm/boot/zImage:
cat linux-configs/$(BL_BOARD) > linux/.config
$(MAKE) -C linux ARCH=arm CROSS_COMPILE="$(CROSS_COMPILE)" olddefconfig
$(MAKE) -C linux -j $(JOBS) ARCH=arm CROSS_COMPILE="$(CROSS_COMPILE)"
-$(MAKE) -C linux ARCH=arm CROSS_COMPILE="$(CROSS_COMPILE)" \
INSTALL_MOD_PATH="../linux-modules" modules_install
rm -f linux-modules/lib/modules/*/build linux-modules/lib/modules/*/source
linux-clean:
rm -f linux/arch/arm/boot/zImage
linux-menuconfig:
cat linux-configs/$(BL_BOARD) > linux/.config
$(MAKE) -C linux ARCH=arm CROSS_COMPILE="$(CROSS_COMPILE)" olddefconfig
$(MAKE) -C linux ARCH=arm CROSS_COMPILE="$(CROSS_COMPILE)" menuconfig
$(MAKE) -C linux ARCH=arm CROSS_COMPILE="$(CROSS_COMPILE)" savedefconfig
cat linux/defconfig > linux-configs/$(BL_BOARD)
rm linux/defconfig
dtbs:
$(MAKE) -C linux ARCH=arm CROSS_COMPILE="$(CROSS_COMPILE)" dtbs
kernel: linux dtbs
.PHONY: imx-bootlets
imx-bootlets: imx-bootlets/imx28_ivt_linux.sb
imx-bootlets/imx28_ivt_linux.sb: linux/arch/arm/boot/zImage
cat linux/arch/arm/boot/zImage linux/arch/arm/boot/dts/imx28-$(PRODUCT).dtb > imx-bootlets/zImage
$(MAKE) -C imx-bootlets -j1 CROSS_COMPILE="$(CROSS_COMPILE)" MEM_TYPE=MEM_DDR1 BOARD=$(BL_BOARD)
OPENPLCUTILS_INSTALLDIR:=${CURDIR}/programs/open-plc-utils/rootfs
$(OPENPLCUTILS_INSTALLDIR):
$(MAKE) -C programs/open-plc-utils CROSS="arm-linux-gnueabi-"
sudo $(MAKE) -C programs/open-plc-utils ROOTFS="$(OPENPLCUTILS_INSTALLDIR)" install
programs: $(OPENPLCUTILS_INSTALLDIR)
.PHONY: programs-clean
programs-clean:
-rm -rf $(OPENPLCUTILS_INSTALLDIR)
$(MAKE) -C programs/open-plc-utils clean
.PHONY: clean
clean: tools-clean
$(MAKE) -C u-boot clean
$(MAKE) -C linux clean
$(MAKE) -C imx-bootlets clean
rootfs-clean:
$(MAKE) -C debian-rootfs clean
.PHONY: rootfs
rootfs:
$(MAKE) -C debian-rootfs
install: clean-rootfs $(if $(findstring evacharge,$(PRODUCT)),programs)
sudo mkdir -p rootfs
sudo cp -a debian-rootfs/rootfs/* rootfs/
# linux kernel and device tree
sudo mkdir -p rootfs/boot
sudo cp -av linux/arch/arm/boot/zImage rootfs/boot/
sudo cp -av linux/arch/arm/boot/dts/imx28-$(BL_BOARD)*.dtb rootfs/boot/
sudo sh -c 'if [ -d linux-modules/lib/modules ]; then cp -av linux-modules/lib/modules rootfs/lib; fi'
sudo chown 0:0 rootfs/boot/*
sudo chmod 0644 rootfs/boot/*
-sudo chown 0:0 -R rootfs/lib/modules
-sudo sh -c 'find rootfs/lib/modules -type d -exec chmod 0755 {} \;'
-sudo sh -c 'find rootfs/lib/modules -type f -exec chmod 0644 {} \;'
# fold in root fs overlay
sudo mkdir rootfs-tmp
sudo cp -a debian-rootfs/files/* rootfs-tmp/
# fold in common files for this product
ifneq ($(PRODUCT_COMMON),)
sudo cp -a debian-rootfs/files-$(PRODUCT_COMMON)-common/* rootfs-tmp/
endif
# fold in product specific files
sudo sh -c 'if [ -d debian-rootfs/files-$(PRODUCT) ]; then cp -a debian-rootfs/files-$(PRODUCT)/* rootfs-tmp/; fi'
# and fold in customer specific files (if present)
sudo sh -c 'if [ -d debian-rootfs/files-$(PRODUCT)-custom ]; then cp -a debian-rootfs/files-$(PRODUCT)-custom/* rootfs-tmp/ || true; fi'
ifeq ($(PRODUCT),evachargese)
sudo sh -c 'cp -a programs/open-plc-utils/rootfs/* rootfs-tmp/'
endif
sudo mkdir -p rootfs-tmp/usr/bin/
sudo cp -a /usr/bin/qemu-arm-static rootfs-tmp/usr/bin/
sudo chown 0:0 -R rootfs-tmp
# for root fs resizing after first boot
sudo mv rootfs/sbin/init rootfs/sbin/init.orig
sudo cp -a rootfs-tmp/* rootfs
sudo rm -rf rootfs-tmp
# run dpkg-configure stuff inside the chroot
sudo mount -t proc - rootfs/proc
sudo chroot rootfs /init-chroot.sh
# workarounds to stop some daemons
-sudo kill -9 $$(ps ax | grep [q]emu-arm-static | awk '{ print $$1 }')
sudo umount rootfs/proc
# cleanup
-sudo sh -c 'find rootfs -name .stib_placeholder -exec rm {} \;'
sudo rm -f rootfs/init-chroot.sh
sudo rm -rf rootfs/var/cache/apt/*
clean-rootfs:
sudo rm -rf rootfs rootfs-tmp
images-clean clean-images:
rm -f images/*
rootfs-image: images/rootfs.img
.PHONY: images/rootfs.img
images/rootfs.img:
rm -f images/rootfs.img
mkdir -p images
dd if=/dev/zero of=images/rootfs.img seek=$$(($(ROOTFSSIZE) - 1)) bs=1 count=1
sudo mkfs.ext4 -F images/rootfs.img
mktemp -d > images/mountpoint
sudo mount images/rootfs.img $$(cat images/mountpoint) -o loop
-sudo cp -a rootfs/* $$(cat images/mountpoint)
sudo umount $$(cat images/mountpoint)
sudo rmdir $$(cat images/mountpoint)
rm -f images/mountpoint
images/sdcard.img: images/rootfs.img
sh tools/gen_sdcard_ext4.sh images/sdcard.img $(BOOTSTREAM) images/rootfs.img $$(($(ROOTFSSIZE) / (1024 * 1024)))
sh tools/fixup_fdt_file.sh tools/fw_env.config $(PRODUCT) $(HWREV)
.PHONY: disk-image
disk-image: images/sdcard.img
rm -f images/ucl.xml images/emmc.img.*
split -b $(ROOTFSCHUNKSIZE) --numeric-suffixes=1 images/sdcard.img images/emmc.img.
ifeq ($(BL_BOARD),duckbill)
gzip -9 images/emmc.img.*
else
tools/gen_ucl_xml.sh images/ > images/ucl.xml
endif
.PHONY: mrproper
mrproper:
-make -C u-boot mrproper
-make -C linux mrproper
.PHONY: distclean
distclean: mrproper clean-rootfs rootfs-clean tools-clean programs-clean
rm -rf linux-modules
rm -rf images