-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
107 lines (85 loc) · 3.89 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
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
################################################################################
## Config
################################################################################
KERNEL_INTREE_DT_NAME ?= sun8i-h3-nanopi-neo
KERNEL_DEFCONFIG ?= sunxi
UBOOT_BOARD_DEFCONFIG ?= nanopi_neo
UBOOT_FORMAT_CUSTOM_NAME ?= u-boot-sunxi-with-spl.bin
UBOOT_VERSION ?= v2017.11
IMAGE_SIZE ?= 4000M
ROOTFS_TARBALL = alpine-minirootfs-3.7.0-armhf.tar.gz
ROOTFS_TARBALL_URL = http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/armhf/$(ROOTFS_TARBALL)
################################################################################
## Possible modifiers:
## DO_UBOOT_DEFCONFIG
## DO_UBOOT_MENUCONFIG
## DO_LINUX_DEFCONFIG
## DO_LINUX_MENUCONFIG
################################################################################
################################################################################
TSTAMP:=$(shell date +'%Y%m%d-%H%M%S')
SDCARD_IMAGE:=nanopi-alpine-$(TSTAMP).img
KERNEL_PRODUCTS=$(addprefix sources/linux/,arch/arm/boot/zImage arch/arm/boot/dts/$(KERNEL_INTREE_DT_NAME).dtb)
KERNEL_PRODUCTS_OUTPUT=$(addprefix output/,$(notdir $(KERNEL_PRODUCTS)))
# export MKFS_F2FS=/usr/sbin/mkfs.f2fs
# export SLOAD_F2FS=/usr/sbin/sload.f2fs
.PHONY: all
all: output/nanopi-alpine.img
sources/$(ROOTFS_TARBALL):
wget -O 'sources/$(ROOTFS_TARBALL)' '$(ROOTFS_TARBALL_URL)'
.SECONDARY: sources/linux.git
sources/u-boot.git:
git clone git://git.denx.de/u-boot.git 'sources/u-boot'; cd sources/u-boot; git checkout tags/$(UBOOT_VERSION)
touch '$@' # sentinel file
sources/u-boot/.config: sources/u-boot.git
if [ ! -f u-boot.config ] || [ -n '$(DO_UBOOT_DEFCONFIG)' ]; then \
$(MAKE) -C sources/u-boot/ '$(UBOOT_BOARD_DEFCONFIG)_defconfig'; \
else \
cp u-boot.config sources/u-boot/.config; \
fi
if [ -n '$(DO_UBOOT_MENUCONFIG)' ]; then \
$(MAKE) -C sources/u-boot/ menuconfig; \
fi
sources/u-boot/u-boot-sunxi-with-spl.bin: sources/u-boot/.config
$(MAKE) -C sources/u-boot/ all
output/$(UBOOT_FORMAT_CUSTOM_NAME): sources/u-boot/$(UBOOT_FORMAT_CUSTOM_NAME)
cp $^ $@
.SECONDARY: sources/linux.git
sources/linux.git:
git clone --depth=1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 'sources/linux/'
touch '$@' # sentinel file
sources/linux/.config: sources/linux.git
if [ ! -f kernel.config ] || [ -n '$(DO_LINUX_DEFCONFIG)' ]; then \
$(MAKE) -C sources/linux/ '$(KERNEL_DEFCONFIG)_defconfig'; \
else \
cp kernel.config sources/linux/.config; \
fi
if [ -n '$(DO_LINUX_MENUCONFIG)' ]; then \
$(MAKE) -C sources/linux/ menuconfig; \
fi
$(KERNEL_PRODUCTS): sources/linux/.config
$(MAKE) -C sources/linux/ all
$(KERNEL_PRODUCTS_OUTPUT): $(KERNEL_PRODUCTS)
cp $^ output/
output/boot.scr: boot.cmd
mkimage -C none -A arm -T script -d '$^' '$@'
output/nanopi-alpine.img: output/$(UBOOT_FORMAT_CUSTOM_NAME) output/boot.scr sources/$(ROOTFS_TARBALL) $(KERNEL_PRODUCTS_OUTPUT)
truncate -s '$(IMAGE_SIZE)' '$@'
sudo sh -c " \
UBOOT='output/$(UBOOT_FORMAT_CUSTOM_NAME)' \
BOOTSCR='output/boot.scr' \
KERNEL='$(word 1,$(KERNEL_PRODUCTS_OUTPUT))' \
DTB='$(word 2,$(KERNEL_PRODUCTS_OUTPUT))' \
ROOTFS_TARBALL='sources/$(ROOTFS_TARBALL)' \
IMAGE='$@' \
./make-image.sh"
.PHONY: clean
clean:
# if [ -d u-boot/ ]; then $(MAKE) -C sources/u-boot/ clean; fi
# if [ -d linux/ ]; then $(MAKE) -C sources/linux/ clean; fi
rm -f output/*
.PHONY: distclean
distclean:
rm -rf sources/*