Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. # Copyright (c) 2020 StarFiveTech, Inc
  3. # compiler tool chain
  4. CROSS_COMPILE?=riscv64-unknown-elf-
  5. CC=${CROSS_COMPILE}gcc
  6. LD=${CROSS_COMPILE}ld
  7. OBJCOPY=${CROSS_COMPILE}objcopy
  8. OBJDUMP=${CROSS_COMPILE}objdump
  9. #DDR_SPEED 1:1600. 2:2133 3:2800 4 :3200
  10. DDR_SPEED = 2133
  11. SUFFIX=$(shell date +%y%m%d)
  12. GIT_VERSION=$(shell git show -s --pretty=format:%h)
  13. VERSION=$(SUFFIX)-$(GIT_VERSION)
  14. TARGET = ddrinit-$(DDR_SPEED)-$(SUFFIX)
  15. LINKER_SCRIPT := ddrinit.lds
  16. MAP_FILE := ddrinit.map
  17. INCLUDE_DIR = -I. -I../boot\
  18. -I../common\
  19. -I../gpio\
  20. -I../spi\
  21. -I../system\
  22. -I../uart \
  23. -I../timer \
  24. -I../sdio\
  25. -I../gpt \
  26. -I../crc32 \
  27. ifeq ($(strip $(DDR_SPEED)),1600)
  28. INCLUDE_DIR +=-I../ddrphy_cfg/memory/jedec_lpddr4_16gb_3200/regconfig_sim_800_cl14_bl16
  29. else ifeq ($(strip $(DDR_SPEED)),2133)
  30. INCLUDE_DIR +=-I../ddrphy_cfg/memory/jedec_lpddr4_16gb_3200/regconfig_sim_1066_cl20_bl16
  31. else ifeq ($(strip $(DDR_SPEED)),2800)
  32. INCLUDE_DIR +=-I../ddrphy_cfg/memory/jedec_lpddr4_16gb_3200/regconfig_sim_1600_cl28_bl16
  33. else ifeq ($(strip $(DDR_SPEED)),3200)
  34. INCLUDE_DIR +=-I../ddrphy_cfg/memory/jedec_lpddr4_16gb_3200/regconfig_sim_1600_cl28_bl16
  35. else
  36. $(error DDR_SPEED $(DDR_SPEED) illegal!)
  37. endif
  38. # compiler options
  39. RISCV_ARCH := rv64imafdc
  40. RISCV_ABI := lp64d
  41. CFLAGS += -O2 -g -c -Wall -DVERSION=\"$(VERSION)\"
  42. CFLAGS += -march=$(RISCV_ARCH)
  43. CFLAGS += -mabi=$(RISCV_ABI)
  44. CFLAGS += -mcmodel=medany
  45. CFLAGS += $(INCLUDE_DIR)
  46. CFLAGS += -specs=nano.specs
  47. CCASFLAGS= -mcmodel=medany -mexplicit-relocs
  48. LDFLAGS = -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)-T $(LINKER_SCRIPT) -nostartfiles --specs=nano.specs -Wl,-Map,$(MAP_FILE)
  49. # object list
  50. OBJECTLIST=../boot/start.o \
  51. ../boot/bootmain.o \
  52. ../boot/trap.o \
  53. ../uart/uart.o \
  54. ../uart/cmd.o \
  55. ../uart/xmodem.o \
  56. ../uart/crc16.o \
  57. ../common/util.o \
  58. ../common/ctype.o \
  59. ../gpio/gpio.o \
  60. ../spi/spi.o \
  61. ../spi/spi_probe.o \
  62. ../spi/cadence_qspi.o \
  63. ../spi/spi_flash.o \
  64. ../spi/cadence_qspi_apb.o \
  65. ../timer/timer.o \
  66. ../sdio/bouncebuf.o \
  67. ../sdio/dw_mmc.o \
  68. ../sdio/mmc.o \
  69. ../sdio/mmc_write.o \
  70. ../sdio/sdio.o \
  71. ../gpt/gpt.o \
  72. ../ddrphy_cfg/regconfig.h.sim_PHY.o \
  73. ../ddrphy_cfg/regconfig.h.sim_PI.o \
  74. ../crc32/crc32.o \
  75. ifeq ($(strip $(DDR_SPEED)),1600)
  76. OBJECTLIST +=../ddrc_cfg/lpddr4_800_cl14_bl16/orbit_boot_800.o
  77. OBJECTLIST +=../ddrphy_cfg/lpddr4_1600_cl28_bl16/regconfig_pi_start.o
  78. CFLAGS +=-DDDR_1600
  79. else ifeq ($(strip $(DDR_SPEED)),2133)
  80. OBJECTLIST +=../ddrc_cfg/lpddr4_1066_cl20_bl16/orbit_boot_1066.o
  81. OBJECTLIST +=../ddrphy_cfg/lpddr4_1600_cl28_bl16/regconfig_pi_start.o
  82. CFLAGS +=-DDDR_2133
  83. else ifeq ($(strip $(DDR_SPEED)),2800)
  84. OBJECTLIST +=../ddrc_cfg/lpddr4_1333_cl24_bl16/orbit_boot_1333.o
  85. OBJECTLIST +=../ddrphy_cfg/lpddr4_1600_cl28_bl16/regconfig_pi_start_2800.o
  86. CFLAGS +=-DDDR_2800
  87. else ifeq ($(strip $(DDR_SPEED)),3200)
  88. OBJECTLIST +=../ddrc_cfg/lpddr4_1600_cl28_bl16/orbit_boot_1600.o
  89. OBJECTLIST +=../ddrphy_cfg/lpddr4_1600_cl28_bl16/regconfig_pi_start_3200.o
  90. CFLAGS +=-DDDR_3200
  91. else
  92. $(error DDR_SPEED $(DDR_SPEED) illegal!)
  93. endif
  94. all:$(TARGET).elf $(TARGET).bin $(TARGET).asm
  95. $(TARGET).elf:$(OBJECTLIST)
  96. @echo ================================================================================
  97. $(CC) -o $(TARGET).elf $(LDFLAGS) $(OBJECTLIST)
  98. @echo $(TARGET).elf LINK SUCCEED!
  99. %.bin: %.elf
  100. $(OBJCOPY) -O binary $^ $@
  101. @if [ -f fsz.sh ]; then ./fsz.sh $(TARGET).bin; fi
  102. %.asm: %.elf
  103. $(OBJDUMP) -S $^ > $@
  104. %.dtb: %.dts
  105. dtc $^ -o $@ -O dtb
  106. %.o: %.S
  107. $(CC) $(CFLAGS) $(CCASFLAGS) -c $< -o $@
  108. %.o: %.c
  109. $(CC) $(CFLAGS) -o $@ -c $<
  110. .PHONY: clean
  111. clean:
  112. rm -f $(OBJECTLIST) $(TARGET).bin *.asm *.elf *.out $(MAP_FILE)