summaryrefslogtreecommitdiffstats
path: root/boot/u-boot/u-boot.mk
blob: efde3ea991771065664709249d8564044e929155 (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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#############################################################
#
# U-Boot
#
#############################################################
U_BOOT_VERSION:=$(call qstrip,$(BR2_UBOOT_VERSION))

U_BOOT_SOURCE:=u-boot-$(U_BOOT_VERSION).tar.bz2

U_BOOT_SITE:=ftp://ftp.denx.de/pub/u-boot
U_BOOT_DIR:=$(BUILD_DIR)/u-boot-$(U_BOOT_VERSION)
U_BOOT_CAT:=$(BZCAT)
U_BOOT_BIN:=u-boot.bin
U_BOOT_TARGET_BIN:=u-boot-$(U_BOOT_VERSION)-$(DATE).bin

U_BOOT_TOOLS:=$(HOST_DIR)/usr/bin/mkimage
MKIMAGE:=$(U_BOOT_TOOLS)
U_BOOT_AUTOSCRIPT=$(BINARIES_DIR)/autoscript

U_BOOT_TARGETS:=$(BINARIES_DIR)/$(U_BOOT_BIN) $(U_BOOT_TOOLS)

ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_DEFAULT_ENV)),y)
U_BOOT_TARGETS += u-boot-autoscript
endif

TARGET_UBOOT_IPADDR:=$(call qstrip,$(BR2_TARGET_UBOOT_IPADDR))
TARGET_UBOOT_SERVERIP:=$(call qstrip,$(BR2_TARGET_UBOOT_SERVERIP))
TARGET_UBOOT_GATEWAY:=$(call qstrip,$(BR2_TARGET_UBOOT_GATEWAY))
TARGET_UBOOT_NETMASK:=$(call qstrip,$(BR2_TARGET_UBOOT_NETMASK))
TARGET_UBOOT_ETHADDR:=$(call qstrip,$(BR2_TARGET_UBOOT_ETHADDR))

# u-boot still uses arch=ppc for powerpc
U_BOOT_ARCH=$(KERNEL_ARCH:powerpc=ppc)
ifeq ($(UBOOT_BOARD_NAME),)
UBOOT_BOARD_NAME:=$(call qstrip,$(BR2_TARGET_UBOOT_BOARDNAME))
endif

U_BOOT_INC_CONF_FILE:=$(U_BOOT_DIR)/include/config.h

U_BOOT_TARGET_TOOLS:=
ifeq ($(BR2_TARGET_UBOOT_TOOL_MKIMAGE),y)
U_BOOT_TARGETS+=$(TARGET_DIR)/usr/bin/mkimage
endif
ifeq ($(BR2_TARGET_UBOOT_TOOL_ENV),y)
U_BOOT_TARGETS+=$(TARGET_DIR)/usr/sbin/fw_printenv
endif

U_BOOT_CONFIGURE_OPTS += CONFIG_NOSOFTFLOAT=1

# Define a helper function
define insert_define
@echo "#ifdef $(strip $(1))" >> $(U_BOOT_INC_CONF_FILE)
@echo "#undef $(strip $(1))" >> $(U_BOOT_INC_CONF_FILE)
@echo "#endif" >> $(U_BOOT_INC_CONF_FILE)
@echo '#define $(strip $(1)) $(call qstrip,$(2))' >> $(U_BOOT_INC_CONF_FILE)
endef

$(DL_DIR)/$(U_BOOT_SOURCE):
	 $(call DOWNLOAD,$(U_BOOT_SITE),$(U_BOOT_SOURCE))

$(U_BOOT_DIR)/.unpacked: $(DL_DIR)/$(U_BOOT_SOURCE)
	$(U_BOOT_CAT) $(DL_DIR)/$(U_BOOT_SOURCE) \
		| tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
	mkdir -p $(U_BOOT_DIR)
	touch $@

$(U_BOOT_DIR)/.patched: $(U_BOOT_DIR)/.unpacked
	toolchain/patch-kernel.sh $(U_BOOT_DIR) boot/u-boot \
		u-boot-$(U_BOOT_VERSION)-\*.patch \
		u-boot-$(U_BOOT_VERSION)-\*.patch.$(ARCH)
ifneq ($(qstrip $(BR2_TARGET_UBOOT_CUSTOM_PATCH_DIR)),)
	toolchain/patch-kernel.sh $(U_BOOT_DIR) $(U_BOOT_CUSTOM_PATCH_DIR) u-boot-$(U_BOOT_VERSION)-\*.patch
endif
	touch $@

$(U_BOOT_DIR)/.configured: $(U_BOOT_DIR)/.patched
	$(TARGET_CONFIGURE_OPTS)		\
		CFLAGS="$(TARGET_CFLAGS)"	\
		LDFLAGS="$(TARGET_LDFLAGS)"	\
		$(U_BOOT_CONFIGURE_OPTS) \
		$(MAKE) -C $(U_BOOT_DIR)	\
		$(UBOOT_BOARD_NAME)_config
	touch $@

$(U_BOOT_DIR)/.header_modified: $(U_BOOT_DIR)/.configured
	# Modify configuration header in $(U_BOOT_INC_CONF_FILE)
ifdef BR2_TARGET_UBOOT_DEFAULT_ENV
	@echo >> $(U_BOOT_INC_CONF_FILE)
	@echo "/* Add a wrapper around the values Buildroot sets. */" >> $(U_BOOT_INC_CONF_FILE)
	@echo "#ifndef __BR2_ADDED_CONFIG_H" >> $(U_BOOT_INC_CONF_FILE)
	@echo "#define __BR2_ADDED_CONFIG_H" >> $(U_BOOT_INC_CONF_FILE)
	$(call insert_define, DATE, $(DATE))
	$(call insert_define, CONFIG_LOAD_SCRIPTS, 1)
endif # BR2_TARGET_UBOOT_DEFAULT_ENV
ifdef BR2_TARGET_UBOOT_NETWORK
ifneq ($(strip $(BR2_TARGET_UBOOT_IPADDR)),"")
	$(call insert_define, CONFIG_IPADDR, $(BR2_TARGET_UBOOT_IPADDR))
ifneq ($(strip $(BR2_TARGET_UBOOT_GATEWAY)),"")
	$(call insert_define, CONFIG_GATEWAYIP, $(BR2_TARGET_UBOOT_GATEWAY))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_NETMASK)),"")
	$(call insert_define, CONFIG_NETMASK, $(BR2_TARGET_UBOOT_NETMASK))
endif
endif # end BR2_TARGET_U_BOOT_IPADDR
ifneq ($(strip $(BR2_TARGET_UBOOT_SERVERIP)),"")
	$(call insert_define, CONFIG_SERVERIP, $(BR2_TARGET_UBOOT_SERVERIP))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_ETHADDR)),"")
	$(call insert_define, CONFIG_ETHADDR, $(BR2_TARGET_UBOOT_ETHADDR))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_ETH1ADDR)),)
ifneq ($(strip $(BR2_TARGET_UBOOT_ETH1ADDR)),"")
	$(call insert_define, CONFIG_ETH1ADDR, $(BR2_TARGET_UBOOT_ETH1ADDR))
endif
endif
endif # BR2_TARGET_UBOOT_NETWORK
ifeq ($(BR2_TARGET_UBOOT_SILENT),y)
	$(call insert_define, CONFIG_SILENT_CONSOLE,)
endif
ifdef BR2_TARGET_UBOOT_DEFAULT_ENV
ifneq ($(strip $(BR2_TARGET_UBOOT_KERNEL_START)),"")
	$(call insert_define, KERNEL_START, $(BR2_TARGET_UBOOT_KERNEL_START))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_KERNEL_LOCATION)),"")
	$(call insert_define, KERNEL_LOCATION, $(BR2_TARGET_UBOOT_KERNEL_LOCATION))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_FILESYSTEM_START)),"")
	$(call insert_define, FILESYSTEM_START, $(BR2_TARGET_UBOOT_FILESYSTEM_START))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_FILESYSTEM_LOCATION)),"")
	$(call insert_define, FILESYSTEM_LOCATION, $(BR2_TARGET_UBOOT_FILESYSTEM_LOCATION))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_FILESYSTEM_SIZE)),"")
	$(call insert_define, FILESYSTEM_SIZE, $(BR2_TARGET_UBOOT_FILESYSTEM_SIZE))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_END_OF_FLASH)),"")
	$(call insert_define, END_OF_FLASH, $(BR2_TARGET_UBOOT_END_OF_FLASH))
endif
ifneq ($(strip $(BR2_TARGET_UBOOT_MEMORY_SIZE)),"")
	$(call insert_define, MEMORY_SIZE, $(BR2_TARGET_UBOOT_MEMORY_SIZE))
endif
	@echo "#endif /* __BR2_ADDED_CONFIG_H */" >> $(U_BOOT_INC_CONF_FILE)
endif # BR2_TARGET_UBOOT_DEFAULT_ENV
	touch $@

$(U_BOOT_DIR)/$(U_BOOT_BIN): $(U_BOOT_DIR)/.header_modified
	$(TARGET_CONFIGURE_OPTS) \
		CFLAGS="$(TARGET_CFLAGS)" \
		LDFLAGS="$(TARGET_LDFLAGS)" \
		$(U_BOOT_CONFIGURE_OPTS) \
		$(MAKE) CROSS_COMPILE="$(TARGET_CROSS)" ARCH=$(U_BOOT_ARCH) \
		 -C $(U_BOOT_DIR)

$(BINARIES_DIR)/$(U_BOOT_BIN): $(U_BOOT_DIR)/$(U_BOOT_BIN)
	rm -f $(BINARIES_DIR)/$(U_BOOT_BIN)
	rm -f $(BINARIES_DIR)/$(U_BOOT_TARGET_BIN)
	cp -dpf $(U_BOOT_DIR)/$(U_BOOT_BIN) $(BINARIES_DIR)/$(U_BOOT_TARGET_BIN)
	(cd $(BINARIES_DIR); ln -s $(U_BOOT_TARGET_BIN) $(U_BOOT_BIN))

$(U_BOOT_TOOLS): $(U_BOOT_DIR)/$(U_BOOT_BIN)
	mkdir -p $(@D)
	cp -dpf $(U_BOOT_DIR)/tools/mkimage $@

$(TARGET_DIR)/usr/bin/mkimage: $(U_BOOT_DIR)/$(U_BOOT_BIN)
	mkdir -p $(@D)
	$(TARGET_CC) -I$(U_BOOT_DIR)/include -I$(U_BOOT_DIR)/tools \
		-DUSE_HOSTCC -o $@ \
		$(U_BOOT_DIR)/common/image.c \
		$(wildcard $(addprefix $(U_BOOT_DIR)/tools/,default_image.c \
			fit_image.c imximage.c kwbimage.c mkimage.c)) \
		$(addprefix $(U_BOOT_DIR)/lib_generic/,crc32.c md5.c sha1.c) \
		$(U_BOOT_DIR)/tools/os_support.c \
		$(U_BOOT_DIR)/libfdt/fdt*.c

	$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $@

$(TARGET_DIR)/usr/sbin/fw_printenv: $(U_BOOT_DIR)/$(U_BOOT_BIN)
	mkdir -p $(@D)
	$(TARGET_CC) -I$(U_BOOT_DIR)/include -I$(LINUX_HEADERS_DIR)/include \
		-DUSE_HOSTCC -o $@ \
		$(U_BOOT_DIR)/tools/env/*.c $(U_BOOT_DIR)/lib_generic/crc32.c
	$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $@
	ln -sf fw_printenv $(TARGET_DIR)/usr/sbin/fw_setenv

u-boot: $(U_BOOT_TARGETS)

u-boot-autoscript: $(U_BOOT_AUTOSCRIPT).img

u-boot-clean:
	-$(MAKE) -C $(U_BOOT_DIR) clean
	rm -f $(U_BOOT_TOOLS) $(U_BOOT_TARGET_TOOLS)

u-boot-dirclean:
	rm -rf $(U_BOOT_DIR)

u-boot-source: $(DL_DIR)/$(U_BOOT_SOURCE)

u-boot-unpacked: $(U_BOOT_DIR)/.patched

u-boot-configured: $(U_BOOT_DIR)/.header_modified

#############################################################
#
# Generate an autoscript with the configration items
#
#############################################################

$(U_BOOT_AUTOSCRIPT): .config
	rm -f $(U_BOOT_AUTOSCRIPT)
ifneq ($(TARGET_UBOOT_IPADDR),)
	echo setenv ipaddr $(TARGET_UBOOT_IPADDR) > $(U_BOOT_AUTOSCRIPT)
else
	echo TARGET_UBOOT_IPADDR="$(TARGET_UBOOT_IPADDR)"
endif
ifneq ($(TARGET_UBOOT_SERVERIP),)
	echo setenv serverip $(TARGET_UBOOT_SERVERIP) >> $(U_BOOT_AUTOSCRIPT)
endif
ifneq ($(TARGET_UBOOT_GATEWAY),)
	echo setenv gatewayip $(TARGET_UBOOT_GATEWAY) >> $(U_BOOT_AUTOSCRIPT)
endif
ifneq ($(TARGET_UBOOT_NETMASK),)
	echo setenv netmask $(TARGET_UBOOT_NETMASK) >> $(U_BOOT_AUTOSCRIPT)
endif
	echo setenv linux $(LINUX26_KERNEL_NAME) >> $(U_BOOT_AUTOSCRIPT)
	echo setenv kernel-version $(LINUX26_VERSION) >> $(U_BOOT_AUTOSCRIPT)
	echo setenv kernel-date $(DATE) >> $(U_BOOT_AUTOSCRIPT)
	echo setenv hostname $(TARGET_HOSTNAME) >> $(U_BOOT_AUTOSCRIPT)
	echo setenv fs-date $(DATE) >> $(U_BOOT_AUTOSCRIPT)
	echo setenv rd-1 rootfs.$(ARCH)-$(DATE).ext2 >> $(U_BOOT_AUTOSCRIPT)
	echo setenv rd-2 rootfs.$(ARCH)-$(DATE).jffs2 >> $(U_BOOT_AUTOSCRIPT)
	echo setenv rd rootfs.$(BR2_ARCH)-$(DATE).ext2 >> $(U_BOOT_AUTOSCRIPT)
	echo setenv ver 1 >> $(U_BOOT_AUTOSCRIPT)
ifneq ($(TARGET_UBOOT_ETHADDR),)
	echo setenv ethaddr $(TARGET_UBOOT_ETHADDR) >> $(U_BOOT_AUTOSCRIPT)
endif
	echo setenv fstype ram >> $(U_BOOT_AUTOSCRIPT)
	echo fs >> $(U_BOOT_AUTOSCRIPT)
	echo os >> $(U_BOOT_AUTOSCRIPT)
	echo setargs >> $(U_BOOT_AUTOSCRIPT)
	echo saveenv >> $(U_BOOT_AUTOSCRIPT)

$(U_BOOT_AUTOSCRIPT).img: $(U_BOOT_AUTOSCRIPT) $(MKIMAGE)
	$(MKIMAGE) -A $(ARCH) \
				-O linux \
				-T script \
				-C none \
				-a 0 \
				-e 0 \
				-n "autoscr config" \
				-d $(U_BOOT_AUTOSCRIPT) \
				$(U_BOOT_AUTOSCRIPT).img



#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(BR2_TARGET_UBOOT),y)
TARGETS+=u-boot

# we NEED a board name
ifeq ($(UBOOT_BOARD_NAME),)
$(error NO U-Boot board name set. Check your BR2_TARGET_UBOOT_BOARDNAME setting)
endif

endif