summaryrefslogtreecommitdiff
path: root/target/device/Atmel/u-boot/u-boot.mk
blob: cf7b974f1f97447882a56a5bc4e7e270bc1cac02 (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#############################################################
#
# u-boot mkimage to build to target u-boot filesystems and
#
# u-boot.bin - the boot loader for the target - which needs soft float, so
# we won't make it.
#
#
#############################################################
UBOOT_VERSION:=1.2.0-atmel
ATMEL_MIRROR:=$(strip $(subst ",, $(BR2_ATMEL_MIRROR)))
#"))
UBOOT_DIR:=$(BUILD_DIR)/u-boot-$(UBOOT_VERSION)
UBOOT_BUILD_DIR:=$(PROJECT_BUILD_DIR)/u-boot-$(UBOOT_VERSION)
UBOOT_SOURCE:=u-boot-$(UBOOT_VERSION).tar.bz2
#UBOOT_SOURCE:=u-boot-1.1.5-atmel.tar.bz2
#UBOOT_SITE:=http://$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/u-boot
UBOOT_SITE:=$(ATMEL_MIRROR)
UBOOT_PATCH_SITE:=$(ATMEL_MIRROR)
UBOOT_CAT:=$(BZCAT)
UBOOT_PATCH_SOURCE:=u-boot-1.2.0-atmel-patch.tar.bz2

MKIMAGE_BINLOC:=$(UBOOT_BUILD_DIR)/tools/mkimage
MKIMAGE:=$(KERNEL_CROSS)mkimage

UBOOT_BIN:=$(BOARD_NAME)-u-boot-$(UBOOT_VERSION)-$(DATE).bin

UBOOT_PATCHES:=$(PROJECT_BUILD_DIR)/u-boot-patches

UBOOT_ATMEL_BMP:=$(UBOOT_PATCHES)/atmel.bmp

UBOOT_SCR=$(BINARIES_DIR)/autoscript
TARGET_UBOOT_IPADDR:=$(strip $(subst ",, $(BR2_TARGET_UBOOT_IPADDR_AT91)))
#"))
TARGET_UBOOT_SERVERIP:=$(strip $(subst ",, $(BR2_TARGET_UBOOT_SERVERIP_AT91)))
#"))
TARGET_UBOOT_GATEWAY:=$(strip $(subst ",, $(BR2_TARGET_UBOOT_GATEWAY_AT91)))
#"))
TARGET_UBOOT_NETMASK:=$(strip $(subst ",, $(BR2_TARGET_UBOOT_NETMASK_AT91)))
#"))
TARGET_UBOOT_ETHADDR:=$(strip $(subst ",, $(BR2_TARGET_UBOOT_ETHADDR_AT91)))
#"))
UBOOT_CUSTOM:=$(UBOOT_DIR)/include/custom.h

$(DL_DIR)/$(UBOOT_SOURCE):
	$(WGET) -P $(DL_DIR) $(UBOOT_SITE)/$(UBOOT_SOURCE)

$(DL_DIR)/$(UBOOT_PATCH_SOURCE):
	$(WGET) -P $(DL_DIR) $(UBOOT_PATCH_SITE)/$(UBOOT_PATCH_SOURCE)

$(UBOOT_DIR)/.unpacked: $(DL_DIR)/$(UBOOT_SOURCE)
	mkdir -p $(BUILD_DIR)
	$(UBOOT_CAT) $(DL_DIR)/$(UBOOT_SOURCE) | tar -C $(BUILD_DIR) -xvf -
	touch $@

$(UBOOT_PATCHES)/.unpacked: $(DL_DIR)/$(UBOOT_PATCH_SOURCE)
	mkdir -p $(UBOOT_PATCHES)
	bzcat $(DL_DIR)/$(UBOOT_PATCH_SOURCE) | tar -C $(UBOOT_PATCHES) -xvf -
	touch $@

$(UBOOT_DIR)/.patched.$(UBOOT_PATCH_SOURCE): $(UBOOT_DIR)/.unpacked $(UBOOT_PATCHES)/.unpacked
	toolchain/patch-kernel.sh $(UBOOT_DIR) $(UBOOT_PATCHES) \*.patch
	touch $(UBOOT_DIR)/.patched.$(UBOOT_PATCH_SOURCE)
# cp $(UBOOT_CONFIG_FILE) $(UBOOT_DIR)/include/configs/.
# cp $(UBOOT_PATCHES)/cmd_defenv.c $(UBOOT_DIR)/common/.
# cp $(UBOOT_ATMEL_BMP) $(UBOOT_DIR)/tools/logos/.

$(UBOOT_BUILD_DIR)/.configured: $(UBOOT_DIR)/.patched.$(UBOOT_PATCH_SOURCE)
ifneq ($(strip $(UBOOT_CONFIG_FILE)),)
	cp $(UBOOT_CONFIG_FILE) $(UBOOT_DIR)/include/configs/.
endif
	$(MAKE) \
		O=$(UBOOT_BUILD_DIR) \
		CONFIG_NOSOFTFLOAT=1 \
		-C $(UBOOT_DIR) \
		$(UBOOT_CONFIG)
	$(SED) 's/ $$(SREC) $$(BIN)//' $(UBOOT_DIR)/examples/Makefile
	touch $(UBOOT_BUILD_DIR)/.configured
# $(MAKE) O=$(UBOOT_BUILD_DIR) -C $(UBOOT_DIR)

$(MKIMAGE_BINLOC): $(UBOOT_BUILD_DIR)/.configured
	$(MAKE) \
		O=$(UBOOT_BUILD_DIR) \
		CROSS_COMPILE= \
		CONFIG_NOSOFTFLOAT=1 \
		TOPDIR=$(UBOOT_DIR) \
		SRCTREE=$(UBOOT_DIR) \
		-C $(UBOOT_DIR) tools
	touch $(MKIMAGE_BINLOC)

$(UBOOT_BUILD_DIR)/u-boot.bin: $(UBOOT_BUILD_DIR)/.configured $(UBOOT_CUSTOM)
	echo TARGET_CROSS=$(TARGET_CROSS)
	$(MAKE) O=$(UBOOT_BUILD_DIR) \
		CROSS_COMPILE=$(TARGET_CROSS) \
		CONFIG_NOSOFTFLOAT=1 \
		TOPDIR=$(UBOOT_DIR) \
		SRCTREE=$(UBOOT_DIR) \
		TFTPBOOT=$(TARGET_ATMEL_COPYTO) \
		-C $(UBOOT_DIR)

$(BINARIES_DIR)/$(UBOOT_BIN): $(UBOOT_BUILD_DIR)/u-boot.bin
	mkdir -p $(BINARIES_DIR)
	cp $(UBOOT_BUILD_DIR)/u-boot.bin $(BINARIES_DIR)/$(UBOOT_BIN)

$(TARGET_ATMEL_COPYTO)/$(UBOOT_BIN): $(UBOOT_BUILD_DIR)/u-boot.bin
	mkdir -p $(TARGET_ATMEL_COPYTO)
	cp $(UBOOT_BUILD_DIR)/u-boot.bin $(TARGET_ATMEL_COPYTO)/$(UBOOT_BIN)

uboot-bin: $(BINARIES_DIR)/$(UBOOT_BIN) $(TARGET_ATMEL_COPYTO)/$(UBOOT_BIN)

$(UBOOT_CUSTOM).test: .config $(UBOOT_BUILD_DIR)/.configured
	echo "/* Automatically generated file, do not edit */" \
	> $(UBOOT_CUSTOM).test
ifneq ($(TARGET_HOSTNAME),)
	echo "#if defined(CONFIG_HOSTNAME)" >> $(UBOOT_CUSTOM).test
	echo "#undef CONFIG_HOSTNAME" >> $(UBOOT_CUSTOM).test
	echo "#define CONFIG_HOSTNAME $(TARGET_HOSTNAME)">> $(UBOOT_CUSTOM).test
	echo "#endif" >> $(UBOOT_CUSTOM).test
endif
ifneq ($(TARGET_UBOOT_IPADDR),)
	echo "#define CONFIG_IPADDR $(TARGET_UBOOT_IPADDR)">> $(UBOOT_CUSTOM).test
endif
ifneq ($(TARGET_UBOOT_SERVERIP),)
	echo "#define CONFIG_SERVERIP $(TARGET_UBOOT_SERVERIP)">> $(UBOOT_CUSTOM).test
endif
ifneq ($(TARGET_UBOOT_GATEWAY),)
	echo "#define CONFIG_GATEWAYIP $(TARGET_UBOOT_GATEWAY)">> $(UBOOT_CUSTOM).test
endif
ifneq ($(TARGET_UBOOT_NETMASK),)
	echo "#define CONFIG_NETMASK $(TARGET_UBOOT_NETMASK)">> $(UBOOT_CUSTOM).test
endif
ifneq ($(TARGET_UBOOT_ETHADDR),)
	echo "#define CONFIG_ETHADDR $(TARGET_UBOOT_ETHADDR)">> $(UBOOT_CUSTOM).test
endif
	diff -q $(UBOOT_CUSTOM).test $(UBOOT_CUSTOM) || cp -af $(UBOOT_CUSTOM).test $(UBOOT_CUSTOM)

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

$(UBOOT_SCR).$(PROJECT): $(UBOOT_SCR) $(MKIMAGE)
	$(MKIMAGE) -A arm \
				-O linux \
				-T script \
				-C none \
				-a 0 \
				-e 0 \
				-n "autoscr config" \
				-d $(UBOOT_SCR) \
				$(UBOOT_SCR).$(PROJECT)
	cp $(UBOOT_SCR).$(PROJECT) $(TARGET_ATMEL_COPYTO)

$(MKIMAGE): $(MKIMAGE_BINLOC)
	cp -f $(MKIMAGE_BINLOC) $(MKIMAGE)

uboot: $(MKIMAGE) uboot-bin $(UBOOT_SCR).$(PROJECT)

uboot-source: $(DL_DIR)/$(UBOOT_SOURCE)

uboot-clean:
	rm -fr $(UBOOT_BUILD_DIR)
	rm -fr $(UBOOT_PATCHES)
	rm -f $(BINARIES_DIR)/$(UBOOT_BIN)
	rm -fr $(UBOOT_DIR)
	rm -f $(UBOOT_SCR)
	rm -f $(UBOOT_SCR).$(PROJECT)
# -$(MAKE) -C $(UBOOT_DIR)/uboot-tools clean

uboot-dirclean: uboot-clean
	rm -rf $(UBOOT_DIR)

uboot-new:
	rm -fr $(UBOOT_BUILD_DIR)/u-boot
	rm -fr $(UBOOT_BUILD_DIR)/u-boot.gz
	rm -fr $(UBOOT_BUILD_DIR)/u-boot.bin
	rm -fr $(TARGET_ATMEL_COPYTO)/$(UBOOT_BIN)
	rm -fr $(BINARIES_DIR)/$(UBOOT_BIN)

.PHONY: uboot-bin
#############################################################
#
# Build the uboot root filesystem image
#
#############################################################

UBOOT_TARGET:=$(IMAGE).uboot

ubootroot: host-fakeroot makedevs uboot
	-@find $(TARGET_DIR) -type f -perm +111 | xargs $(STRIPCMD) 2>/dev/null || true
	@rm -rf $(TARGET_DIR)/usr/man
	@rm -rf $(TARGET_DIR)/usr/info
	-/sbin/ldconfig -r $(TARGET_DIR) 2>/dev/null
	# Use fakeroot to pretend all target binaries are owned by root
	rm -f $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))
	touch $(STAGING_DIR)/.fakeroot.00000
	cat $(STAGING_DIR)/.fakeroot* > $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))
	echo "chown -R root:root $(TARGET_DIR)" >> $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))
	# Use fakeroot to pretend to create all needed device nodes
	echo "$(STAGING_DIR)/bin/makedevs -d $(TARGET_DEVICE_TABLE) $(TARGET_DIR)" \
		>> $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))
	# Use fakeroot so mkuboot believes the previous fakery
	echo "$(UBOOT_DIR)/uboot-tools/mkuboot " \
		    "$(TARGET_DIR) $(UBOOT_TARGET) " \
		    "-noappend $(UBOOT_ENDIANNESS)" \
		>> $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))
	chmod a+x $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))
	$(STAGING_DIR)/usr/bin/fakeroot -- $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))
	-@rm -f $(STAGING_DIR)/_fakeroot.$(notdir $(UBOOT_TARGET))

ubootroot-source: uboot-source

ubootroot-clean:
	-$(MAKE) -C $(UBOOT_DIR) clean

ubootroot-dirclean:
	rm -rf $(UBOOT_DIR)

#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(BR2_TARGET_UBOOT_AT91),y)
TARGETS+=uboot
endif

uboot-test:
	-@echo source=$(DL_DIR)/$(UBOOT_SOURCE)
	-@ls $(DL_DIR)/$(UBOOT_SOURCE)
	-@echo patch=$(DL_DIR)/$(UBOOT_PATCH_SOURCE)
	-@ls $(DL_DIR)/$(UBOOT_PATCH_SOURCE)
	-@echo unpacked=$(UBOOT_PATCHES)/.unpacked
	-@ls $(UBOOT_PATCHES)/.unpacked
	-@echo patch-unpacked=$(UBOOT_PATCHES)/.unpacked
	-@ls $(UBOOT_PATCHES)/.unpacked
	-@echo patched-source=$(UBOOT_DIR)/.patched.$(UBOOT_PATCH_SOURCE)
	-@ls $(UBOOT_DIR)/.patched.$(UBOOT_PATCH_SOURCE)
	-@echo configured=$(UBOOT_BUILD_DIR)/.configured
	-@ls $(UBOOT_BUILD_DIR)/.configured
	-@echo mkimage=$(MKIMAGE_BINLOC)
	-@ls $(MKIMAGE_BINLOC)
	-@echo u-boot.bin=$(UBOOT_BUILD_DIR)/u-boot.bin
	-@ls $(UBOOT_BUILD_DIR)/u-boot.bin
	-@echo binaries-u-boot.bin=$(BINARIES_DIR)/$(UBOOT_BIN)
	-@ls $(BINARIES_DIR)/$(UBOOT_BIN)
	-@echo tftpboot=$(TARGET_ATMEL_COPYTO)/$(UBOOT_BIN)
	-@ls $(TARGET_ATMEL_COPYTO)/$(UBOOT_BIN)
	-@echo "mkimage = $(MKIMAGE)"
	-@ls $(MKIMAGE)
	-@echo "u-boot script=$(UBOOT_SCR).$(PROJECT)"
	-@ls $(UBOOT_SCR).$(PROJECT)
	-@echo "u-boot script (ASCII)=$(UBOOT_SCR)"
	-@ls $(UBOOT_SCR)
	-@echo "mkimage binary=$(MKIMAGE_BINLOC)"
	-@ls $(MKIMAGE_BINLOC)