1################################################################################ 2# Create By Hisilicon 3################################################################################ 4 5PWD = $(shell pwd) 6HW_CROSS_COMPILE = $(CROSS_COMPILE) 7TOPDIR = 8 9################################################################################ 10CC := $(HW_CROSS_COMPILE)gcc 11AR := $(HW_CROSS_COMPILE)ar 12LD := $(HW_CROSS_COMPILE)ld 13OBJCOPY := $(HW_CROSS_COMPILE)objcopy 14 15 16################################################################################ 17BOOT := u-boot-$(SOC) 18TEXTBASE := 0x40700000 19 20CFLAGS :=-Os -fno-builtin -ffreestanding \ 21 -D__KERNEL__ -DTEXT_BASE=$(TEXTBASE) \ 22 -I$(TOPDIR)/include \ 23 -I$(TOPDIR)/drivers/ddr/hisilicon/default \ 24 -I$(TOPDIR)/drivers/ddr/hisilicon/$(SOC) \ 25 -I$(TOPDIR)/arch/arm/include \ 26 -I$(TOPDIR)/lib/hw_dec \ 27 -fno-pic -ffunction-sections \ 28 -fdata-sections -fno-common -ffixed-r9 \ 29 -fno-common -pipe -march=armv7-a \ 30 -Wall -Wstrict-prototypes -fno-stack-protector \ 31 -D__LINUX_ARM_ARCH__=7 -D__ARM__ \ 32 -DCONFIG_MMC\ 33 $(MKFLAGS) -fno-strict-aliasing 34 35 36ifeq ($(ENABLE_MINI_BOOT),y) 37 CFLAGS += -DENABLE_MINI_BOOT 38 UBOOT_LDS := u-boot-mini.lds 39else 40 UBOOT_LDS := u-boot.lds 41endif 42 43################################################################################ 44 45START := start.o 46COBJS := lowlevel_init_v300.o \ 47 init_registers.o \ 48 uart.o \ 49 ddr_training_impl.o \ 50 ddr_training_ctl.o \ 51 ddr_training_boot.o \ 52 ddr_training_custom.o \ 53 ddr_training_console.o \ 54 pll_trainning.o \ 55 startup.o \ 56 image_data.o \ 57 reset.o 58 59SSRC := arch/arm/cpu/armv7/$(SOC)/start.S \ 60 arch/arm/cpu/armv7/$(SOC)/reset.S \ 61 arch/arm/cpu/armv7/$(SOC)/uart.S \ 62 arch/arm/cpu/armv7/$(SOC)/init_registers.c \ 63 arch/arm/cpu/armv7/$(SOC)/lowlevel_init_v300.c \ 64 drivers/ddr/hisilicon/default/ddr_training_impl.c \ 65 drivers/ddr/hisilicon/default/ddr_training_ctl.c \ 66 drivers/ddr/hisilicon/default/ddr_training_boot.c \ 67 drivers/ddr/hisilicon/default/ddr_training_console.c \ 68 drivers/ddr/hisilicon/$(SOC)/ddr_training_custom.c \ 69 arch/arm/cpu/armv7/$(SOC)/pll_trainning.c \ 70 lib/hw_dec/hw_decompress.c \ 71 lib/hw_dec/hw_decompress_$(SOC).c \ 72 lib/hw_dec/hw_decompress_v1.c \ 73 lib/hw_dec/hw_decompress_v1.h 74 75ifneq ($(ENABLE_MINI_BOOT),y) 76COBJS += emmc_boot.o \ 77 div0.o 78SSRC += arch/arm/cpu/armv7/$(SOC)/emmc_boot.c \ 79 arch/arm/cpu/armv7/$(SOC)/himci_boot.c \ 80 arch/arm/lib/div0.c 81endif 82 83REG := $(wildcard $(TOPDIR)/*.reg $(TOPDIR)/.reg) 84SRC := $(notdir $(SSRC)) 85 86################################################################################ 87.PHONY: $(BOOT).bin 88$(BOOT).bin: $(BOOT).tmp regfile 89 @dd if=./$(BOOT).tmp of=./tmp1 bs=1 count=64 2>/dev/null 90 @dd if=$(REG) of=./tmp2 bs=5120 conv=sync 2>/dev/null 91 @dd if=./$(BOOT).tmp of=./tmp3 bs=1 skip=5184 2>/dev/null 92 @cat tmp1 tmp2 tmp3 > $(BOOT).bin 93 @rm -f tmp1 tmp2 tmp3 94 @chmod 754 $(BOOT).bin 95 @cp -fv $@ $(TOPDIR) 96 @echo $(BOOT).bin is Ready. 97 98$(BOOT).tmp: $(BOOT).elf 99 $(OBJCOPY) -O srec $< $(BOOT).srec 100 $(OBJCOPY) -j .text -O binary $< $(BOOT).text 101 $(OBJCOPY) --gap-fill=0xff -O binary $< $@ 102 103$(BOOT).elf: image_data.gzip $(SRC) $(START) $(COBJS) 104 $(LD) -Bstatic -T $(UBOOT_LDS) -Ttext $(TEXTBASE) $(START) \ 105 $(COBJS) -Map $(BOOT).map -o $@ 106 $(OBJDUMP) -d $@ > $@.asm 107 108.PHONY: regfile 109regfile: 110 @if [ "$(words $(REG))" = "0" ]; then ( \ 111 echo '***' Need '.reg' or '*.reg' file in directory $(TOPDIR); \ 112 exit 1; \ 113 ) fi 114 @if [ "$(words $(REG))" != "1" ]; then ( \ 115 echo '***' Found multi '.reg' or '*.reg' file in directory $(TOPDIR); \ 116 echo '***' Files: $(notdir $(REG)); \ 117 exit 1; \ 118 ) fi 119 120################################################################################ 121start.o: start.S 122 $(CC) -D__ASSEMBLY__ $(CFLAGS) -o $@ $< -c 123 124# -1 : --fast -9 : --best 125image_data.gzip: $(BINIMAGE) 126 ./gzip -fNqc -7 $< > $@ 127 128%.o: %.c 129 $(CC) $(CFLAGS) -Wall -Wstrict-prototypes \ 130 -fno-stack-protector -o $@ $< -c 131 132%.o: %.S 133 $(CC) -D__ASSEMBLY__ $(CFLAGS) -o $@ $< -c 134 135image_data.o: image_data.S image_data.gzip 136 $(CC) -D__ASSEMBLY__ $(CFLAGS) -o $@ $< -c 137 138############################################################################# 139 140$(SRC): 141 ln -sf ../../../../../../$(filter %/$@,$(SSRC)) $@ 142################################################################################ 143TMPS := $(COBJS) start.o $(SRC) \ 144 $(BOOT).map $(BOOT).elf $(BOOT).srec $(BOOT).bin $(BOOT).text $(BOOT).tmp \ 145 image_data.gzip 146 147distclean: clean 148 149clean: 150 -rm -f $(TMPS) 151 152################################################################################ 153.PHONY: clean 154################################################################################ 155