forked from nerves-project/nerves_system_br
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
142 lines (117 loc) · 5.17 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
TOPDIR := $(shell pwd)
# Unreleased version of BR required for Galileo support
NERVES_BR_VERSION = 7fed757456d30aae7be381f6a4aa463523ae1bb8
NERVES_BR_URL = git://git.buildroot.net/buildroot
NERVES_DEFCONFIG = $(shell grep BR2_DEFCONFIG= buildroot/.config | sed -e 's/.*"\(.*\)"/\1/')
# Location to download files to so that they don't need
# to be redownloaded when working a lot with buildroot
#
# NOTE: If you are a heavy Buildroot user and have an alternative location,
# override this environment variable or symlink this directory.
NERVES_BR_DL_DIR ?= $(HOME)/.nerves/cache/buildroot
# Check the OS and architecture to give more helpful errors
ifneq ($(shell uname -s),Linux)
$(error Nerves system images can only be built using Linux)
endif
ifneq ($(shell uname -p),x86_64)
$(error 64-bit Linux required for supported cross-compilers)
endif
MAKE_BR = make -C buildroot BR2_EXTERNAL=$(TOPDIR)
all: br-make
.buildroot-downloaded:
@echo "Caching downloaded files in $(NERVES_BR_DL_DIR)."
@[ -e $(NERVES_BR_DL_DIR) ] || mkdir -p $(NERVES_BR_DL_DIR)
@echo "Downloading Buildroot..."
@scripts/clone_or_dnload.sh $(NERVES_BR_URL) $(NERVES_BR_VERSION) $(NERVES_BR_DL_DIR)
@touch .buildroot-downloaded
# Apply our patches that either haven't been submitted or merged upstream yet
.buildroot-patched: .buildroot-downloaded
buildroot/support/scripts/apply-patches.sh buildroot patches || exit 1
touch .buildroot-patched
# Symlink Buildroot's dl directory so that it can be cached between builds
if [ -d $(NERVES_BR_DL_DIR) -a ! -e buildroot/dl ]; then \
ln -sf $(NERVES_BR_DL_DIR) buildroot/dl; \
fi
reset-buildroot: .buildroot-downloaded
# Reset buildroot to a pristine condition so that the
# patches can be applied again.
cd buildroot && git clean -fdx && git reset --hard
rm -f .buildroot-patched
update-patches: reset-buildroot .buildroot-patched
%_defconfig: $(TOPDIR)/configs/%_defconfig .buildroot-patched
$(MAKE_BR) $@
buildroot/.config: .buildroot-patched
@echo
@echo 'ERROR: Please choose a Nerves SDK configuration and run'
@echo ' "make <platform>_defconfig"'
@echo
@echo 'Run "make help" or look in the configs directory for options'
@false
br-make: buildroot/.config
$(MAKE_BR)
@echo
@echo SDK is ready to use. Demo images are in buildroot/output/images.
system: br-make
scripts/mksystem.sh
# Replace everything on the SDCard with new bits
burn-complete: burn
burn:
sudo buildroot/output/host/usr/bin/fwup -a -i $(firstword $(wildcard buildroot/output/images/*.fw)) -t complete
# Upgrade the image on the SDCard (app data won't be removed)
# This is usually the fastest way to update an SDCard that's already
# been programmed. It won't update bootloaders, so if something is
# really messed up, burn-complete may be better.
burn-upgrade:
sudo buildroot/output/host/usr/bin/fwup -a -i $(firstword $(wildcard buildroot/output/images/*.fw)) -t upgrade
sudo buildroot/output/host/usr/bin/fwup -y -a -i /tmp/finalize.fw -t on-reboot
sudo rm /tmp/finalize.fw
menuconfig: buildroot/.config
$(MAKE_BR) menuconfig
@echo
@echo "!!! Important !!!"
@echo "1. $(subst $(shell pwd)/,,$(NERVES_DEFCONFIG)) has NOT been updated."
@echo " Changes will be lost if you run 'make distclean'."
@echo " Run 'make savedefconfig' to update."
@echo "2. Buildroot normally requires you to run 'make clean' and 'make' after"
@echo " changing the configuration. You don't technically have to do this,"
@echo " but if you're new to Buildroot, it's best to be safe."
savedefconfig: buildroot/.config
$(MAKE_BR) savedefconfig
linux-menuconfig: buildroot/.config
$(MAKE_BR) linux-menuconfig
$(MAKE_BR) linux-savedefconfig
@echo
@echo Going to update your boards/.../linux-x.y.config. If you do not have one,
@echo you will get an error shortly. You will then have to make one and update,
@echo your buildroot configuration to use it.
$(MAKE_BR) linux-update-defconfig
busybox-menuconfig: buildroot/.config
$(MAKE_BR) busybox-menuconfig
@echo
@echo Going to update your boards/.../busybox-x.y.config. If you do not have one,
@echo you will get an error shortly. You will then have to make one and update
@echo your buildroot configuration to use it.
$(MAKE_BR) busybox-update-config
clean: realclean
distclean: realclean
realclean:
-[ ! -d buildroot ] || chmod -R u+w buildroot
-rm -fr buildroot .buildroot-patched .buildroot-downloaded
help:
@echo 'Nerves System Help'
@echo '------------------'
@echo
@echo 'Targets:'
@echo ' all - Build the current configuration'
@echo ' burn - Burn the most recent build to an SDCard (requires sudo)'
@echo ' system - Build a system image for use with bake'
@echo ' clean - Clean everything - run make xyz_defconfig after this'
@echo
@echo 'Configuration:'
@echo " menuconfig - Run Buildroot's menuconfig"
@echo ' linux-menuconfig - Run menuconfig on the Linux kernel'
@echo
@echo 'Nerves built-in configs:'
@$(foreach b, $(sort $(notdir $(wildcard configs/*_defconfig))), \
printf " %-29s - Build for %s\\n" $(b) $(b:_defconfig=);)
.PHONY: all burn burn-complete burn-upgrade system clean menuconfig linux-menuconfig