-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
497 lines (412 loc) · 14.9 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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
#
# Copyright (C) 2016 Ingenic Semiconductor Co.,Ltd
#
# Zhang YanMing <[email protected], [email protected]>
#
# X1000 series loader for u-boot/rtos/linux
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi; fi)
#
# Top directory
#
TOPDIR := $(shell pwd)
#
# Cross compiler
#
CROSS_COMPILE := mips-linux-gnu-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJDUMP := $(CROSS_COMPILE)objdump
OBJCOPY := $(CROSS_COMPILE)objcopy
AWK := awk
#
# Out & Tools directory
#
OUTDIR := $(TOPDIR)/out
$(shell [ -d $(OUTDIR) ] || mkdir -p $(OUTDIR))
OUTDIR := $(shell cd $(OUTDIR) && /bin/pwd)
$(if $(OUTDIR),,$(error output directory "$(OUTDIR)" does not exist))
TOOLSDIR := $(TOPDIR)/tools
SLEEPLIB_DIR := $(TOPDIR)/sleep-lib
ifeq ($(FUNCTION), 0)
SLEEPLIB_DIR := $(shell cd $(SLEEPLIB_DIR) && /bin/pwd)
$(if $(SLEEPLIB_DIR),,$(error sleep-lib directory "$(SLEEPLIB_DIR)" does not exist))
endif
#
# Timestamp file
#
TIMESTAMP_FILE = $(TOPDIR)/include/generated/timestamp_autogenerated.h
#
# Includes
#
ifeq ($(TOPDIR)/include/generated/config.mk, $(wildcard $(TOPDIR)/include/generated/config.mk))
include $(TOPDIR)/include/generated/config.mk
ifdef BOARD
ifeq ($(TOPDIR)/boards/$(BOARD)/board.mk, $(wildcard $(TOPDIR)/boards/$(BOARD)/board.mk))
include $(TOPDIR)/boards/$(BOARD)/board.mk
else
$(error Could not found board named "$(BOADR)"!)
endif
else
$(error Please define BOARD first!)
endif
ifeq ($(FUNCTION), 0)
CONFIG_BOOTLOADER := y
ifeq ($(BOOT_NEXT_STAGE), 0)
CONFIG_BOOT_UBOOT := y
else ifeq ($(BOOT_NEXT_STAGE), 1)
CONFIG_BOOT_KERNEL := y
else ifeq ($(BOOT_NEXT_STAGE), 2)
CONFIG_BOOT_RTOS := y
else
$(error Boot next stage "$(BOOT_NEXT_STAGE)" has not support yet!)
endif
endif # FUNCTION := 0
#
# U-boot load & entry address
#
ifeq ($(CONFIG_BOOT_UBOOT), y)
BOOT_NEXT_STAGE_LOAD_ADDR := 0x80100000
BOOT_NEXT_STAGE_ENTRY_ADDR := 0x80100000
endif
#
# RTOS load & entry address
ifeq ($(CONFIG_BOOT_RTOS), y)
BOOT_NEXT_STAGE_LOAD_ADDR := 0x80800000
BOOT_NEXT_STAGE_ENTRY_ADDR := 0x80800000
endif
#
# Kernel load & entry address
#
ifeq ($(CONFIG_BOOT_KERNEL), y)
#
# For zImage(default)
#
BOOT_NEXT_STAGE_LOAD_ADDR := 0x80f00000
BOOT_NEXT_STAGE_ENTRY_ADDR := 0x80f00000
#
# For xImage(zImage with 64byte header)
#
ifeq ($(KERNEL_IMAGE_TYPE), 1)
OFFSET_LEN := 0x40
BOOT_NEXT_STAGE_LOAD_ADDR := $(BOOT_NEXT_STAGE_LOAD_ADDR)-$(OFFSET_LEN)
#BOOT_NEXT_STAGE_LOAD_ADDR := $(shell $(AWK) 'BEGIN{printf("0x%x\n", \
'$(BOOT_NEXT_STAGE_LOAD_ADDR)'-$(OFFSET_LEN)); \
}')
#
# For vmlinux.bin
#
else ifeq ($(KERNEL_IMAGE_TYPE), 2)
BOOT_NEXT_STAGE_LOAD_ADDR := 0x80010000
BOOT_NEXT_STAGE_ENTRY_ADDR := $(BOOT_NEXT_STAGE_LOAD_ADDR)
endif
endif
#
# Configure flags
#
ifeq ($(CONFIG_BOOTLOADER), y)
CFGFLAGS := -DCONFIG_BOOT_NEXT_STAGE_LOAD_ADDR=$(BOOT_NEXT_STAGE_LOAD_ADDR) \
-DCONFIG_BOOT_NEXT_STAGE_ENTRY_ADDR=$(BOOT_NEXT_STAGE_ENTRY_ADDR)
endif
ifeq ($(CONFIG_BOOT_KERNEL), y)
CFGFLAGS += -DCONFIG_BOOT_KERNEL -DCONFIG_KERNEL_IMAGE_TYPE=$(KERNEL_IMAGE_TYPE)
else ifeq ($(CONFIG_BOOT_RTOS), y)
CFGFLAGS += -DCONFIG_BOOT_RTOS
else ifeq ($(CONFIG_BOOT_UBOOT), y)
CFGFLAGS += -DCONFIG_BOOT_UBOOT
endif
ifdef BOOT_FROM
ifeq ($(BOOT_FROM), nor)
CFGFLAGS += -DCONFIG_BOOT_SPI_NOR -DCONFIG_BOOT_SFC
CONFIG_BOOT_SFC=y
CONFIG_BOOT_SPI_NOR=y
endif
ifeq ($(BOOT_FROM), nand)
CFGFLAGS += -DCONFIG_BOOT_SPI_NAND -DCONFIG_BOOT_SFC
CONFIG_BOOT_SFC=y
CONFIG_BOOT_SPI_NAND=y
endif
ifeq ($(BOOT_FROM), mmc)
CFGFLAGS += -DCONFIG_BOOT_MMC
CONFIG_BOOT_MMC=y
endif
ifeq ($(BOOT_FROM), usb)
CFGFLAGS += -DCONFIG_BOOT_USB
CONFIG_BOOT_USB=y
endif
#
# Compiler & Linker options
#
CFLAGS := -Os -g -G 0 -march=mips32r2 -mtune=mips32r2 -mabi=32 -fno-pic \
-fno-builtin -mno-abicalls -nostdlib -EL -msoft-float -std=gnu11 \
-I$(TOPDIR)/include -ffunction-sections -fdata-sections
CHECKFLAGS := -Wall -Wuninitialized -Wstrict-prototypes -Wundef -Werror
LDFLAGS := -nostdlib -EL --gc-sections
ifeq ($(CONFIG_BOOTLOADER), y)
LDFLAGS += -T ldscripts/x-loader.lds
else
LDFLAGS += -T ldscripts/x-loader-burner.lds
endif
SLEEPLIB_LDFLAGS := -nostdlib -T ldscripts/sleep_lib.lds -EL --gc-sections
OBJCFLAGS := --gap-fill=0xff --remove-section=.dynsym
#DEBUGFLAGS := -DDEBUG
override CFLAGS := $(CHECKFLAGS) $(DEBUGFLAGS) $(CFLAGS) $(CFGFLAGS) $(BOARD_CFLAGS)
else
$(error Please define system boot method(nor/nand/mmc/usb)!)
endif
#
# Sources
#
OBJS-y := start.o \
main.o \
drivers/lpddr.o \
drivers/uart.o \
drivers/clk.o \
drivers/gpio.o \
drivers/i2c.o \
drivers/rtc.o \
drivers/efuse.o \
drivers/pmu.o \
drivers/wdt.o \
drivers/aes.o
OBJS-$(CONFIG_BOOTLOADER) += boot.o
OBJS-$(CONFIG_BOOT_KERNEL) += boot_sel.o
OBJS-y += common/printf.o \
common/common.o \
common/ddr_test.o \
common/check_socid.o
OBJS-y += boards/$(BOARD)/board.o
OBJS-$(CONFIG_BOOT_MMC) += drivers/mmc.o
OBJS-$(CONFIG_BOOT_SPI_NAND) += drivers/sfc.o \
drivers/spinand.o
OBJS-$(CONFIG_BOOT_SPI_NOR) += drivers/sfc.o \
drivers/spinor.o
OBJS := $(addprefix $(TOPDIR)/, $(OBJS-y))
#
# Sleep lib source
#
ifeq ($(CONFIG_BOOT_USB),y)
SLEEP_LIBS-y := sleep-lib/sleep_lib_entry.o \
sleep-lib/sleep_lib_clk.o \
sleep-lib/sleep_lib.o
else
SLEEP_LIBS-y := sleep-lib/sleep_lib_entry.o \
sleep-lib/sleep_lib_uart.o \
sleep-lib/sleep_lib_clk.o \
sleep-lib/sleep_lib.o \
common/printf.o \
common/common.o
endif
SLEEP_LIBS := $(addprefix $(TOPDIR)/, $(SLEEP_LIBS-y))
#
# Targets
#
ifeq ($(CONFIG_BOOT_SFC),y)
TARGET := $(OUTDIR)/x-loader-pad-with-sleep-lib.bin
else ifeq ($(CONFIG_BOOT_MMC),y)
TARGET := $(OUTDIR)/x-loader-pad-with-mbr-gpt-with-sleep-lib.bin
else
TARGET := $(OUTDIR)/spl_lpddr.bin
endif
SLEEPLIB := $(OUTDIR)/sleep_lib_tcsm_pad.bin
%.o:%.c
$(CC) -c $(CFLAGS) $< -o $@
%.o:%.S
$(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
.PHONY: all clean Tips backup
all: clean $(TARGET) Tips
Tips: $(TARGET)
@echo -e '\n Image: "$(TARGET)" is ready\n'
$(SLEEPLIB): $(OUTDIR)/sleep_lib_tcsm.elf
$(OBJDUMP) -D $< > $(OUTDIR)/sleep_lib_tcsm.elf.dump
$(OBJCOPY) --gap-fill=0xff -O binary $< $(OUTDIR)/sleep_lib_tcsm.bin
$(OBJCOPY) --gap-fill=0xff --pad-to=8192 -I binary -O binary $(OUTDIR)/sleep_lib_tcsm.bin $@
$(OUTDIR)/sleep_lib_tcsm.elf: $(SLEEP_LIBS)
$(LD) $(SLEEPLIB_LDFLAGS) $(SLEEP_LIBS) -o $@ -Map $(OUTDIR)/sleep_lib_tcsm.map
$(OUTDIR)/x-loader-pad-with-mbr-gpt-with-sleep-lib.bin: $(OUTDIR)/x-loader-pad-with-mbr-gpt.bin $(SLEEPLIB)
cat $< $(SLEEPLIB) > $@
$(OUTDIR)/x-loader-pad-with-sleep-lib.bin: $(OUTDIR)/x-loader-pad.bin $(SLEEPLIB)
cat $< $(SLEEPLIB) > $@
@cp $@ [email protected]
$(OBJCOPY) --gap-fill=0xff --pad-to=26624 -I binary -O binary [email protected] $@
$(OUTDIR)/x-loader-pad-with-mbr-gpt.bin: $(OUTDIR)/mbr-gpt.bin $(OUTDIR)/x-loader-pad.bin $(TOOLSDIR)/spl_params_fixer
cat $(OUTDIR)/mbr-gpt.bin $(OUTDIR)/x-loader-pad.bin > $@
$(TOOLSDIR)/spl_params_fixer $@ $(OUTDIR)/x-loader.bin > /dev/null
$(OUTDIR)/x-loader-pad.bin: $(OUTDIR)/x-loader.bin
$(OBJDUMP) -D $(OUTDIR)/x-loader.elf > $(OUTDIR)/x-loader.elf.dump
$(OBJCOPY) $(OBJCFLAGS) --pad-to=16384 -I binary -O binary $< $@
ifeq ($(CONFIG_BOOT_SFC),y)
$(OUTDIR)/x-loader.bin: $(OUTDIR)/x-loader.elf $(TOOLSDIR)/sfc_boot_checksum
$(OBJCOPY) $(OBJCFLAGS) -O binary $< $@
$(TOOLSDIR)/sfc_boot_checksum $@
else ifeq ($(CONFIG_BOOT_MMC),y)
$(OUTDIR)/x-loader.bin: $(OUTDIR)/x-loader.elf
$(OBJCOPY) $(OBJCFLAGS) -O binary $< $@
else ifeq ($(CONFIG_BOOT_USB),y)
$(OUTDIR)/spl_lpddr.bin: $(OUTDIR)/x-loader.elf
$(OBJDUMP) -D $(OUTDIR)/x-loader.elf > $(OUTDIR)/x-loader.elf.dump
$(OBJCOPY) $(OBJCFLAGS) -O binary $< $@
endif
ifeq ($(CONFIG_BOOT_USB), y)
$(OUTDIR)/x-loader.elf: $(TIMESTAMP_FILE) $(TOOLSDIR)/ddr_params_creator \
$(TOOLSDIR)/uart_baudrate_lut \
$(TOOLSDIR)/efuse_params_creator \
$(TOOLSDIR)/wdt_params_creator \
$(OBJS) $(SLEEP_LIBS)
$(LD) $(LDFLAGS) $(OBJS) $(SLEEP_LIBS) -o $@ -Map $(OUTDIR)/x-loader.map
else
$(OUTDIR)/x-loader.elf: $(TIMESTAMP_FILE) $(TOOLSDIR)/ddr_params_creator \
$(TOOLSDIR)/sfc_timing_params_creator \
$(TOOLSDIR)/uart_baudrate_lut \
$(TOOLSDIR)/efuse_params_creator \
$(TOOLSDIR)/wdt_params_creator \
$(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o $@ -Map $(OUTDIR)/x-loader.map
endif
ifeq ($(CONFIG_GPT_TABLE), y)
ifneq ($(TOPDIR)/boards/$(BOARD)/partitions.tab, $(wildcard $(TOPDIR)/boards/$(BOARD)/partitions.tab))
$(error Can not found "partitions.tab" for board $(BOARD))
else
$(OUTDIR)/mbr-gpt.bin: $(TOOLSDIR)/gpt_creator
$< $(TOPDIR)/boards/$(BOARD)/partitions.tab $(OUTDIR)/mbr-of-gpt.bin $(OUTDIR)/gpt.bin
cat $(OUTDIR)/mbr-of-gpt.bin $(OUTDIR)/gpt.bin > $@
dd if=/dev/zero of=$(OUTDIR)/file.bin bs=512 count=33
cat $@ $(OUTDIR)/file.bin > $(OUTDIR)/file2.bin
dd if=$(OUTDIR)/file2.bin of=$@ bs=512 count=34
rm $(OUTDIR)/file* -rf
endif
else
$(OUTDIR)/mbr-gpt.bin: $(OUTDIR)/mbr.bin
dd if=/dev/zero of=$(OUTDIR)/gpt.bin bs=512 count=33
cat $(OUTDIR)/mbr.bin $(OUTDIR)/gpt.bin > $@
$(OUTDIR)/mbr.bin: $(TOOLSDIR)/mbr_creator.c
gcc -o $(TOOLSDIR)/mbr_creator -D__HOST__ -I$(TOPDIR)/include $<
strip $(TOOLSDIR)/mbr_creator
$(TOOLSDIR)/mbr_creator \
p0off=$(CONFIG_MBR_P0_OFF),p0end=$(CONFIG_MBR_P0_END),p0type=$(CONFIG_MBR_P0_TYPE) \
p1off=$(CONFIG_MBR_P1_OFF),p1end=$(CONFIG_MBR_P1_END),p1type=$(CONFIG_MBR_P1_TYPE) \
p2off=$(CONFIG_MBR_P2_OFF),p2end=$(CONFIG_MBR_P2_END),p2type=$(CONFIG_MBR_P2_TYPE) \
p3off=$(CONFIG_MBR_P3_OFF),p3end=$(CONFIG_MBR_P3_END),p3type=$(CONFIG_MBR_P3_TYPE) \
-o $@ > /dev/zero
endif
#
# Host tools
#
$(TOOLSDIR)/ddr_params_creator: $(TOOLSDIR)/ddr_params_creator.c
gcc -o $@ -D__HOST__ -I$(TOPDIR)/include $<
strip $@
$@ > $(TOPDIR)/include/generated/ddr_reg_values.h
$(TOOLSDIR)/uart_baudrate_lut: $(TOOLSDIR)/uart_baudrate_lut.c
gcc -o $@ -D__HOST__ -I$(TOPDIR)/include $<
strip $@
$@ > $(TOPDIR)/include/generated/uart_baudrate_reg_values.h
$(TOOLSDIR)/efuse_params_creator: $(TOOLSDIR)/efuse_params_creator.c
gcc -o $@ -D__HOST__ -I$(TOPDIR)/include $<
strip $@
$@ > $(TOPDIR)/include/generated/efuse_reg_values.h
$(TOOLSDIR)/sfc_boot_checksum: $(TOOLSDIR)/sfc_boot_checksum.c
gcc -o $@ -D__HOST__ -I$(TOPDIR)/include $<
strip $@
$(TOOLSDIR)/sfc_timing_params_creator: $(TOOLSDIR)/sfc_timing_params_creator.c
gcc -o $@ -D__HOST__ -DCONFIG_BOOT_SFC -I$(TOPDIR)/include $<
strip $@
$@ > $(TOPDIR)/include/generated/sfc_timing_params.h
$(TOOLSDIR)/wdt_params_creator: $(TOOLSDIR)/wdt_params_creator.c
gcc -o $@ -D__HOST__ -DCONFIG_BOOT_SFC -I$(TOPDIR)/include $<
strip $@
$@ > $(TOPDIR)/include/generated/wdt_cfg_params.h
$(TOOLSDIR)/spl_params_fixer: $(TOOLSDIR)/spl_params_fixer.c
gcc -o $@ -D__HOST__ -DCONFIG_BOOT_MMC -I$(TOPDIR)/include $<
strip $@
$(TIMESTAMP_FILE):
@LC_ALL=C date +'#define X_LOADER_DATE "%b %d %C%y"' > [email protected]
@LC_ALL=C date +'#define X_LOADER_TIME "%T"' >> [email protected]
else
all:
@echo "Please configure first!- see README" >&2
@exit 1
endif
#
# Board config
#
unconfig:
rm -f include/generated/config.h include/generated/config.mk
#===============================================================================
burner_config: unconfig
@./mkconfig $(@:_config) burner usb
phoenix_nor_config: unconfig
@./mkconfig $(@:_config) phoenix nor
phoenix_nand_config: unconfig
@./mkconfig $(@:_config) phoenix nand
phoenix_mmc_config: unconfig
@./mkconfig $(@:_config) phoenix mmc
halley2_nor_config: unconfig
@./mkconfig $(@:_config) halley2 nor
halley2_nand_config: unconfig
@./mkconfig $(@:_config) halley2 nand
halley2_mmc_config: unconfig
@./mkconfig $(@:_config) halley2 mmc
yak_nor_config: unconfig
@./mkconfig $(@:_config) yak nor
speaker_nand_config: unconfig
@./mkconfig $(@:_config) speaker nand
yak_minios_nor_config: unconfig
@./mkconfig $(@:_config) yak_minios nor
media_nor_config: unconfig
@./mkconfig $(@:_config) media nor
qrcode_nor_config: unconfig
@./mkconfig $(@:_config) qrcode nor
zlm60_nand_config: unconfig
@./mkconfig $(@:_config) zlm60 nand
skyworth_nor_config: unconfig
@./mkconfig $(@:_config) skyworth nor
a0_ubi_nand_config: unconfig
@./mkconfig $(@:_config) a0_ubi nand
ilock_nor_config: unconfig
@./mkconfig $(@:_config) ilock nor
ilock_nand_config: unconfig
@./mkconfig $(@:_config) ilock nand
uboot_nor_config: unconfig
@./mkconfig $(@:_config) uboot nor
uboot_nand_config: unconfig
@./mkconfig $(@:_config) uboot nand
#
# Put your board's config here
#
#===============================================================================
clean:
rm -rf $(OUTDIR)/* \
$(SLEEP_LIBS) \
$(OBJS) \
$(TOOLSDIR)/sfc_boot_checksum \
$(TOOLSDIR)/ddr_params_creator \
$(TOOLSDIR)/uart_baudrate_lut \
$(TOOLSDIR)/mbr_creator \
$(TOOLSDIR)/spl_params_fixer \
$(TOOLSDIR)/efuse_params_creator \
$(TOOLSDIR)/sfc_timing_params_creator \
$(TOOLSDIR)/wdt_params_creator \
$(TOPDIR)/include/generated/ddr_reg_values.h \
$(TOPDIR)/include/generated/uart_baudrate_reg_values.h \
$(TOPDIR)/include/generated/sfc_timing_params.h \
$(TOPDIR)/include/generated/efuse_reg_values.h \
$(TOPDIR)/include/generated/wdt_cfg_params.h \
$(TIMESTAMP_FILE)
distclean: clean unconfig
backup: distclean
F=`basename $(TOPDIR)` ; cd .. ; \
tar --force-local --exclude=.git -Jcvf `date "+$$F-%Y-%m-%d-%T.tar.xz"` $$F