Makefile 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. ISA ?= rv64imafdc
  2. ABI ?= lp64d
  3. #TARGET_BOARD is JH7110 or NULL
  4. SOC := JH7110
  5. BOARD_FLAGS :=
  6. HWBOARD ?= visionfive2
  7. HWBOARD_FLAG ?= HWBOARD_VISIONFIVE2
  8. srcdir := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
  9. srcdir := $(srcdir:/=)
  10. confdir := $(srcdir)/conf
  11. wrkdir := $(CURDIR)/work
  12. buildroot_srcdir := $(srcdir)/buildroot
  13. buildroot_initramfs_wrkdir := $(wrkdir)/buildroot_initramfs
  14. # TODO: make RISCV be able to be set to alternate toolchain path
  15. RISCV ?= $(buildroot_initramfs_wrkdir)/host
  16. RVPATH := $(RISCV)/bin:$(PATH)
  17. target := riscv64-buildroot-linux-gnu
  18. CROSS_COMPILE := $(RISCV)/bin/$(target)-
  19. buildroot_initramfs_tar := $(buildroot_initramfs_wrkdir)/images/rootfs.tar
  20. buildroot_initramfs_config := $(confdir)/buildroot_initramfs_config
  21. buildroot_initramfs_sysroot_stamp := $(wrkdir)/.buildroot_initramfs_sysroot
  22. buildroot_initramfs_sysroot := $(wrkdir)/buildroot_initramfs_sysroot
  23. buildroot_rootfs_wrkdir := $(wrkdir)/buildroot_rootfs
  24. buildroot_rootfs_ext := $(buildroot_rootfs_wrkdir)/images/rootfs.ext4
  25. buildroot_rootfs_config := $(confdir)/buildroot_rootfs_config
  26. linux_srcdir := $(srcdir)/linux
  27. linux_wrkdir := $(wrkdir)/linux
  28. ifeq ($(HWBOARD), evb)
  29. linux_defconfig := $(linux_srcdir)/arch/riscv/configs/starfive_jh7110_defconfig
  30. else
  31. linux_defconfig := $(linux_srcdir)/arch/riscv/configs/starfive_visionfive2_defconfig
  32. endif
  33. vmlinux := $(linux_wrkdir)/vmlinux
  34. vmlinux_stripped := $(linux_wrkdir)/vmlinux-stripped
  35. vmlinux_bin := $(wrkdir)/vmlinux.bin
  36. module_install_path:=$(wrkdir)/module_install_path
  37. its_file=$(confdir)/$(HWBOARD)-fit-image.its
  38. uboot_its_file=$(confdir)/$(HWBOARD)-uboot-fit-image.its
  39. vfat_image := $(wrkdir)/starfive-$(HWBOARD)-vfat.part
  40. #ext_image := $(wrkdir) # TODO
  41. initramfs := $(wrkdir)/initramfs.cpio.gz
  42. sbi_srcdir := $(srcdir)/opensbi
  43. sbi_wrkdir := $(wrkdir)/opensbi
  44. sbi_bin := $(wrkdir)/opensbi/platform/generic/firmware/fw_payload.bin
  45. fit := $(wrkdir)/image.fit
  46. uboot_fit := $(wrkdir)/$(HWBOARD)_fw_payload.img
  47. fesvr_srcdir := $(srcdir)/riscv-fesvr
  48. fesvr_wrkdir := $(wrkdir)/riscv-fesvr
  49. libfesvr := $(fesvr_wrkdir)/prefix/lib/libfesvr.so
  50. spike_srcdir := $(srcdir)/riscv-isa-sim
  51. spike_wrkdir := $(wrkdir)/riscv-isa-sim
  52. spike := $(spike_wrkdir)/prefix/bin/spike
  53. qemu_srcdir := $(srcdir)/riscv-qemu
  54. qemu_wrkdir := $(wrkdir)/riscv-qemu
  55. qemu := $(qemu_wrkdir)/prefix/bin/qemu-system-riscv64
  56. uboot_srcdir := $(srcdir)/u-boot
  57. uboot_wrkdir := $(wrkdir)/u-boot
  58. uboot_dtb_file := $(wrkdir)/u-boot/arch/riscv/dts/starfive_$(HWBOARD).dtb
  59. uboot := $(uboot_wrkdir)/u-boot.bin
  60. spl_tool_srcdir :=$(CURDIR)/soft_3rdpart/spl_tool/
  61. spl_bin_normal_out :=$(wrkdir)/u-boot-spl.bin.normal.out
  62. uboot_config := starfive_$(HWBOARD)_defconfig
  63. uboot_defconfig := $(uboot_srcdir)/configs/$(uboot_config)
  64. rootfs := $(wrkdir)/rootfs.bin
  65. target_gcc := $(CROSS_COMPILE)gcc
  66. version := $(wrkdir)/version
  67. .PHONY: all check_arg
  68. all: check_arg $(fit) $(vfat_image) $(uboot_fit) $(spl_bin_normal_out)
  69. @echo
  70. @echo "This image has been generated for an ISA of $(ISA) and an ABI of $(ABI)"
  71. @echo "Find the image in work/image.fit, which should be copied to an MSDOS boot partition 1"
  72. @echo
  73. @echo "To completely erase, reformat, and program a disk sdX, run:"
  74. @echo " make DISK=/dev/sdX format-boot-loader"
  75. @echo " ... you will need gdisk and e2fsprogs installed"
  76. @echo " Please note this will not currently format the SDcard ext4 partition"
  77. @echo " This can be done manually if needed"
  78. @echo
  79. check_arg:
  80. ifeq ( , $(filter $(HWBOARD), visionfive2 evb fpga))
  81. $(error board $(HWBOARD) is not supported, BOARD=[visionfive2 | evb | fpga(deflault)])
  82. endif
  83. # TODO: depracated for now
  84. #ifneq ($(RISCV),$(buildroot_initramfs_wrkdir)/host)
  85. #$(target_gcc):
  86. # $(error The RISCV environment variable was set, but is not pointing at a toolchain install tree)
  87. #else
  88. #$(target_gcc): $(buildroot_initramfs_tar)
  89. #endif
  90. .PHONY: visionfive2 evb fpga
  91. visionfive2: HWBOARD := visionfive2
  92. visionfive2: HWBOARD_FLAG := HWBOARD_VISIONFIVE2
  93. visionfive2: uboot_config := starfive_$(HWBOARD)_defconfig
  94. visionfive2: uboot_dtb_file := $(wrkdir)/u-boot/arch/riscv/dts/starfive_$(HWBOARD).dtb
  95. visionfive2: linux_defconfig := $(linux_srcdir)/arch/riscv/configs/starfive_visionfive2_defconfig
  96. visionfive2: uboot_fit := $(wrkdir)/$(HWBOARD)_fw_payload.img
  97. visionfive2: vfat_image := $(wrkdir)/starfive-$(HWBOARD)-vfat.part
  98. visionfive2: its_file=$(confdir)/$(HWBOARD)-fit-image.its
  99. visionfive2: uboot_its_file=$(confdir)/$(HWBOARD)-uboot-fit-image.its
  100. visionfive2: all
  101. evb: HWBOARD := evb
  102. evb: HWBOARD_FLAG := HWBOARD_EVB
  103. evb: uboot_config := starfive_$(HWBOARD)_defconfig
  104. evb: uboot_dtb_file := $(wrkdir)/u-boot/arch/riscv/dts/starfive_$(HWBOARD).dtb
  105. evb: linux_defconfig := $(linux_srcdir)/arch/riscv/configs/starfive_jh7110_defconfig
  106. evb: uboot_fit := $(wrkdir)/$(HWBOARD)_fw_payload.img
  107. evb: vfat_image := $(wrkdir)/starfive-$(HWBOARD)-vfat.part
  108. evb: its_file=$(confdir)/$(HWBOARD)-fit-image.its
  109. evb: uboot_its_file=$(confdir)/$(HWBOARD)-uboot-fit-image.its
  110. evb: all
  111. fpga: HWBOARD := fpga
  112. fpga: all
  113. fpga: HWBOARD_FLAG := HWBOARD_FPGA
  114. $(version):
  115. cd $(linux_srcdir) && \
  116. sh $(confdir)/version > $(version)
  117. chmod 777 $(version)
  118. $(buildroot_initramfs_wrkdir)/.config: $(buildroot_srcdir)
  119. # rm -rf $(dir $@)
  120. mkdir -p $(dir $@)
  121. cp $(buildroot_initramfs_config) $@
  122. $(MAKE) -C $< RISCV=$(RISCV) O=$(buildroot_initramfs_wrkdir) olddefconfig
  123. # buildroot_initramfs provides gcc
  124. $(buildroot_initramfs_tar): $(buildroot_srcdir) $(buildroot_initramfs_wrkdir)/.config $(buildroot_initramfs_config)
  125. $(MAKE) -C $< RISCV=$(RISCV) O=$(buildroot_initramfs_wrkdir)
  126. .PHONY: buildroot_initramfs-menuconfig
  127. buildroot_initramfs-menuconfig: $(buildroot_initramfs_wrkdir)/.config $(buildroot_srcdir)
  128. $(MAKE) -C $(dir $<) O=$(buildroot_initramfs_wrkdir) menuconfig
  129. $(MAKE) -C $(dir $<) O=$(buildroot_initramfs_wrkdir) savedefconfig
  130. cp $(dir $<)defconfig $(buildroot_initramfs_config)
  131. # use buildroot_initramfs toolchain
  132. # TODO: fix path and conf/buildroot_rootfs_config
  133. $(buildroot_rootfs_wrkdir)/.config: $(buildroot_srcdir) $(buildroot_initramfs_tar)
  134. # rm -rf $(dir $@)
  135. mkdir -p $(dir $@)
  136. cp $(buildroot_rootfs_config) $@
  137. $(MAKE) -C $< RISCV=$(RISCV) PATH=$(RVPATH) O=$(buildroot_rootfs_wrkdir) olddefconfig
  138. $(buildroot_rootfs_ext): $(buildroot_srcdir) $(buildroot_rootfs_wrkdir)/.config $(target_gcc) $(buildroot_rootfs_config) $(version)
  139. mkdir -p $(buildroot_rootfs_wrkdir)/target/lib/
  140. cp -r $(module_install_path)/lib/modules $(buildroot_rootfs_wrkdir)/target/lib/
  141. $(MAKE) -C $< RISCV=$(RISCV) PATH=$(RVPATH) O=$(buildroot_rootfs_wrkdir)
  142. cp $(version) $(buildroot_rootfs_wrkdir)/target/usr/bin/version
  143. rm -rf $(buildroot_rootfs_ext)
  144. $(MAKE) -C $< RISCV=$(RISCV) PATH=$(RVPATH) O=$(buildroot_rootfs_wrkdir)
  145. .PHONY: buildroot_rootfs
  146. buildroot_rootfs: $(buildroot_rootfs_ext)
  147. .PHONY: buildroot_rootfs-menuconfig
  148. buildroot_rootfs-menuconfig: $(buildroot_rootfs_wrkdir)/.config $(buildroot_srcdir)
  149. $(MAKE) -C $(dir $<) O=$(buildroot_rootfs_wrkdir) menuconfig
  150. $(MAKE) -C $(dir $<) O=$(buildroot_rootfs_wrkdir) savedefconfig
  151. cp $(dir $<)defconfig conf/buildroot_rootfs_config
  152. $(buildroot_initramfs_sysroot_stamp): $(buildroot_initramfs_tar)
  153. mkdir -p $(buildroot_initramfs_sysroot)
  154. tar -xpf $< -C $(buildroot_initramfs_sysroot) --exclude ./dev --exclude ./usr/share/locale
  155. touch $@
  156. $(linux_wrkdir)/.config: $(linux_defconfig) $(linux_srcdir)
  157. mkdir -p $(dir $@)
  158. cp -p $< $@
  159. $(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
  160. ifeq (,$(filter rv%c,$(ISA)))
  161. sed 's/^.*CONFIG_RISCV_ISA_C.*$$/CONFIG_RISCV_ISA_C=n/' -i $@
  162. $(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
  163. endif
  164. ifeq ($(ISA),$(filter rv32%,$(ISA)))
  165. sed 's/^.*CONFIG_ARCH_RV32I.*$$/CONFIG_ARCH_RV32I=y/' -i $@
  166. sed 's/^.*CONFIG_ARCH_RV64I.*$$/CONFIG_ARCH_RV64I=n/' -i $@
  167. $(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
  168. endif
  169. $(uboot_wrkdir)/.config: $(uboot_defconfig)
  170. mkdir -p $(dir $@)
  171. cp -p $< $@
  172. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) ARCH=riscv olddefconfig
  173. $(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(target_gcc)
  174. $(MAKE) -C $< O=$(linux_wrkdir) \
  175. ARCH=riscv \
  176. CROSS_COMPILE=$(CROSS_COMPILE) \
  177. PATH=$(RVPATH) \
  178. HWBOARD_FLAG=$(HWBOARD_FLAG) \
  179. vmlinux \
  180. all \
  181. modules
  182. $(MAKE) -C $< O=$(linux_wrkdir) \
  183. ARCH=riscv \
  184. CROSS_COMPILE=$(CROSS_COMPILE) \
  185. PATH=$(RVPATH) \
  186. INSTALL_MOD_PATH=$(module_install_path) \
  187. modules_install
  188. vpudriver-build: $(vmlinux)
  189. $(MAKE) -C $(buildroot_initramfs_wrkdir) O=$(buildroot_initramfs_wrkdir) \
  190. INSTALL_MOD_PATH=$(module_install_path) wave511driver
  191. $(MAKE) -C $(buildroot_initramfs_wrkdir) O=$(buildroot_initramfs_wrkdir) \
  192. INSTALL_MOD_PATH=$(module_install_path) wave420ldriver
  193. $(MAKE) -C $(buildroot_initramfs_wrkdir) O=$(buildroot_initramfs_wrkdir) \
  194. INSTALL_MOD_PATH=$(module_install_path) codaj12driver
  195. .PHONY: initrd
  196. initrd: $(initramfs)
  197. $(initramfs).d: $(buildroot_initramfs_sysroot)
  198. $(linux_srcdir)/usr/gen_initramfs_list.sh -l $(confdir)/initramfs.txt $(buildroot_initramfs_sysroot) > $@
  199. $(initramfs): $(buildroot_initramfs_sysroot) $(vmlinux) vpudriver-build $(version)
  200. cp -r $(module_install_path)/lib/modules $(buildroot_initramfs_sysroot)/lib/
  201. cp $(version) $(buildroot_initramfs_sysroot)/usr/bin/version && \
  202. cd $(linux_wrkdir) && \
  203. $(linux_srcdir)/usr/gen_initramfs_list.sh \
  204. -o $@ -u $(shell id -u) -g $(shell id -g) \
  205. $(confdir)/initramfs.txt \
  206. $(buildroot_initramfs_sysroot)
  207. $(vmlinux_stripped): $(vmlinux)
  208. PATH=$(RVPATH) $(target)-strip -o $@ $<
  209. $(vmlinux_bin): $(vmlinux)
  210. PATH=$(RVPATH) $(target)-objcopy -O binary $< $@
  211. .PHONY: linux-menuconfig
  212. linux-menuconfig: $(linux_wrkdir)/.config
  213. $(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv menuconfig
  214. $(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv savedefconfig
  215. cp $(dir $<)defconfig $(linux_defconfig)
  216. # Note: opensbi generic platform default FW_TEXT_START is 0x80000000
  217. # For JH7110, need to specify the FW_TEXT_START to 0x40000000
  218. # Otherwise, the fw_payload.bin downloading via jtag will not run.
  219. # not affect the evb_fw_payload.img for its file has FW_TEXT_START
  220. $(sbi_bin): $(uboot) $(vmlinux)
  221. rm -rf $(sbi_wrkdir)
  222. mkdir -p $(sbi_wrkdir)
  223. cd $(sbi_wrkdir) && O=$(sbi_wrkdir) CFLAGS="-mabi=$(ABI) -march=$(ISA)" ${MAKE} -C $(sbi_srcdir) CROSS_COMPILE=$(CROSS_COMPILE) \
  224. PLATFORM=generic FW_PAYLOAD_PATH=$(uboot) FW_FDT_PATH=$(uboot_dtb_file) FW_TEXT_START=0x40000000
  225. $(fit): $(sbi_bin) $(vmlinux_bin) $(uboot) $(its_file) ${initramfs}
  226. $(uboot_wrkdir)/tools/mkimage -f $(its_file) -A riscv -O linux -T flat_dt $@
  227. @if [ -f fsz.sh ]; then ./fsz.sh $(sbi_bin); fi
  228. $(libfesvr): $(fesvr_srcdir)
  229. rm -rf $(fesvr_wrkdir)
  230. mkdir -p $(fesvr_wrkdir)
  231. mkdir -p $(dir $@)
  232. cd $(fesvr_wrkdir) && $</configure \
  233. --prefix=$(dir $(abspath $(dir $@)))
  234. $(MAKE) -C $(fesvr_wrkdir)
  235. $(MAKE) -C $(fesvr_wrkdir) install
  236. touch -c $@
  237. $(spike): $(spike_srcdir) $(libfesvr)
  238. rm -rf $(spike_wrkdir)
  239. mkdir -p $(spike_wrkdir)
  240. mkdir -p $(dir $@)
  241. cd $(spike_wrkdir) && PATH=$(RVPATH) $</configure \
  242. --prefix=$(dir $(abspath $(dir $@))) \
  243. --with-fesvr=$(dir $(abspath $(dir $(libfesvr))))
  244. $(MAKE) PATH=$(RVPATH) -C $(spike_wrkdir)
  245. $(MAKE) -C $(spike_wrkdir) install
  246. touch -c $@
  247. $(qemu): $(qemu_srcdir)
  248. rm -rf $(qemu_wrkdir)
  249. mkdir -p $(qemu_wrkdir)
  250. mkdir -p $(dir $@)
  251. which pkg-config
  252. # pkg-config from buildroot blows up qemu configure
  253. cd $(qemu_wrkdir) && $</configure \
  254. --prefix=$(dir $(abspath $(dir $@))) \
  255. --target-list=riscv64-softmmu
  256. $(MAKE) -C $(qemu_wrkdir)
  257. $(MAKE) -C $(qemu_wrkdir) install
  258. touch -c $@
  259. .PHONY: uboot-menuconfig
  260. uboot-menuconfig: $(uboot_wrkdir)/.config
  261. $(MAKE) -C $(uboot_srcdir) O=$(dir $<) ARCH=riscv menuconfig
  262. $(MAKE) -C $(uboot_srcdir) O=$(dir $<) ARCH=riscv savedefconfig
  263. cp $(dir $<)defconfig $(uboot_defconfig)
  264. $(uboot): $(uboot_srcdir) $(target_gcc)
  265. rm -rf $(uboot_wrkdir)
  266. mkdir -p $(uboot_wrkdir)
  267. mkdir -p $(dir $@)
  268. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) $(uboot_config)
  269. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE)
  270. $(spl_bin_normal_out): $(spl_tool_srcdir) $(uboot)
  271. cd $(spl_tool_srcdir) && \
  272. ./create_sbl $(uboot_wrkdir)/spl/u-boot-spl.bin 0x01010101 && \
  273. cd -
  274. cp $(spl_tool_srcdir)/u-boot-spl.bin.normal.out $(spl_bin_normal_out)
  275. rm -f $(spl_tool_srcdir)/u-boot-spl.bin*
  276. $(uboot_fit): $(sbi_bin) $(uboot_its_file) $(uboot)
  277. $(uboot_wrkdir)/tools/mkimage -f $(uboot_its_file) -A riscv -O u-boot -T firmware $(uboot_fit)
  278. $(rootfs): $(buildroot_rootfs_ext)
  279. cp $< $@
  280. $(buildroot_initramfs_sysroot): $(buildroot_initramfs_sysroot_stamp)
  281. .PHONY: buildroot_initramfs_sysroot vmlinux fit uboot_fit
  282. buildroot_initramfs_sysroot: $(buildroot_initramfs_sysroot)
  283. vmlinux: $(vmlinux)
  284. fit: $(fit)
  285. uboot_fit: $(uboot_fit)
  286. .PHONY: clean
  287. clean:
  288. rm -rf work/u-boot
  289. rm -rf work/opensbi
  290. rm -f work/*-vfat.part
  291. rm -f work/image.fit
  292. rm -f work/*_fw_payload.img
  293. rm -f work/initramfs.cpio.gz
  294. rm -f work/linux/vmlinux*
  295. rm -f work/u-boot-spl.bin.normal.out
  296. rm -f work/version
  297. .PHONY: distclean
  298. distclean:
  299. rm -rf -- $(wrkdir) $(toolchain_dest)
  300. .PHONY: sim
  301. sim: $(spike) $(sbi_bin)
  302. $(spike) --isa=$(ISA) -p4 $(sbi_bin)
  303. .PHONY: qemu
  304. qemu: $(qemu) $(sbi_bin) $(vmlinux) $(initramfs)
  305. $(qemu) -nographic -machine virt -bios $(sbi_bin) -kernel $(vmlinux) -initrd $(initramfs) \
  306. -netdev user,id=net0 -device virtio-net-device,netdev=net0
  307. .PHONY: qemu-rootfs
  308. qemu-rootfs: $(qemu) $(sbi_bin) $(vmlinux) $(initramfs) $(rootfs)
  309. $(qemu) -nographic -machine virt -bios $(sbi_bin) -kernel $(vmlinux) -initrd $(initramfs) \
  310. -drive file=$(rootfs),format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
  311. -netdev user,id=net0 -device virtio-net-device,netdev=net0
  312. .PHONY: uboot
  313. uboot: $(uboot)
  314. # Relevant partition type codes with GUID
  315. SPL = 2E54B353-1271-4842-806F-E436D6AF6985
  316. VFAT = EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  317. LINUX = 0FC63DAF-8483-4772-8E79-3D69D8477DE4
  318. UBOOT = 5B193300-FC78-40CD-8002-E86C45580B47
  319. UBOOTENV = a09354ac-cd63-11e8-9aff-70b3d592f0fa
  320. UBOOTDTB = 070dd1a8-cd64-11e8-aa3d-70b3d592f0fa
  321. UBOOTFIT = 04ffcafa-cd65-11e8-b974-70b3d592f0fa
  322. # Note: The following are the sector number used to partition
  323. # The default sector size is 512 Bytes
  324. # The partition start should be align on 2048-sector boundaries
  325. # expand the vfat size to 300+M for the vpu/jpu or other debug
  326. SPL_START = 2048
  327. SPL_END = 6143
  328. UBOOT_START = 6144
  329. UBOOT_END = 16383
  330. UBOOT_SIZE = $(shell expr $(UBOOT_END) - $(UBOOT_START) + 1)
  331. VFAT_START = 16384
  332. VFAT_END = 614399
  333. VFAT_SIZE = $(shell expr $(VFAT_END) - $(VFAT_START) + 1)
  334. ROOT_START = 614400
  335. $(vfat_image): $(fit) $(confdir)/jh7110_uEnv.txt $(confdir)/vf2_uEnv.txt
  336. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  337. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  338. exit 1; fi
  339. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  340. /sbin/mkfs.vfat $(vfat_image)
  341. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::starfiveu.fit
  342. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/jh7110_uEnv.txt ::jh7110_uEnv.txt
  343. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/vf2_uEnv.txt ::vf2_uEnv.txt
  344. .PHONY: format-boot-loader
  345. format-boot-loader: $(sbi_bin) $(uboot) $(fit) $(vfat_image) $(spl_bin_normal_out)
  346. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  347. sudo /sbin/sgdisk --clear \
  348. --new=1:$(SPL_START):$(SPL_END) --change-name=1:"spl" --typecode=1:$(SPL) \
  349. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:"uboot" --typecode=2:$(UBOOT) \
  350. --new=3:$(VFAT_START):$(VFAT_END) --change-name=3:"image" --typecode=3:$(VFAT) \
  351. --new=4:$(ROOT_START):0 --change-name=4:"root" --typecode=4:$(LINUX) \
  352. $(DISK)
  353. -/sbin/partprobe
  354. @sleep 1
  355. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  356. @$(eval PART1 := $(DISK)p1)
  357. @$(eval PART2 := $(DISK)p2)
  358. @$(eval PART3 := $(DISK)p3)
  359. @$(eval PART4 := $(DISK)p4)
  360. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  361. @$(eval PART1 := $(DISK)s1)
  362. @$(eval PART2 := $(DISK)s2)
  363. @$(eval PART3 := $(DISK)s3)
  364. @$(eval PART4 := $(DISK)s4)
  365. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  366. @$(eval PART1 := $(DISK)1)
  367. @$(eval PART2 := $(DISK)2)
  368. @$(eval PART3 := $(DISK)3)
  369. @$(eval PART4 := $(DISK)4)
  370. else
  371. @echo Error: Could not find bootloader partition for $(DISK)
  372. @exit 1
  373. endif
  374. # sudo dd if=$(spl_bin_normal_out) of=$(PART1) bs=4096
  375. sudo dd if=$(uboot_fit) of=$(PART2) bs=4096
  376. sudo dd if=$(vfat_image) of=$(PART3) bs=4096
  377. sync; sleep 1;
  378. #starfive image
  379. format-rootfs-image: format-boot-loader
  380. @echo "Done setting up basic initramfs boot. We will now try to install"
  381. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  382. @echo "you can safely cancel here"
  383. sudo /sbin/mke2fs -t ext4 $(PART4)
  384. -mkdir -p tmp-mnt
  385. -mkdir -p tmp-rootfs
  386. -sudo mount $(PART4) tmp-mnt && \
  387. sudo mount -o loop $(buildroot_rootfs_ext) tmp-rootfs&& \
  388. sudo cp -fr tmp-rootfs/* tmp-mnt/
  389. sync; sleep 1;
  390. sudo umount tmp-mnt
  391. sudo umount tmp-rootfs
  392. rmdir tmp-mnt
  393. rmdir tmp-rootfs
  394. #usb config
  395. format-usb-disk: $(sbi_bin) $(uboot) $(fit) $(vfat_image)
  396. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  397. /sbin/sgdisk --clear \
  398. --new=1:0:+256M --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  399. --new=2:0:+1G --change-name=2:uboot --typecode=2:$(UBOOT) -g\
  400. $(DISK)
  401. -/sbin/partprobe
  402. @sleep 1
  403. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  404. @$(eval PART1 := $(DISK)p1)
  405. @$(eval PART2 := $(DISK)p2)
  406. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  407. @$(eval PART1 := $(DISK)s1)
  408. @$(eval PART2 := $(DISK)s2)
  409. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  410. @$(eval PART1 := $(DISK)1)
  411. @$(eval PART2 := $(DISK)2)
  412. else
  413. @echo Error: Could not find bootloader partition for $(DISK)
  414. @exit 1
  415. endif
  416. dd if=$(uboot) of=$(PART2) bs=4096
  417. dd if=$(vfat_image) of=$(PART1) bs=4096
  418. DEB_IMAGE := debian_nvdla_20190506.tar.xz
  419. DEB_URL := https://github.com/sifive/freedom-u-sdk/releases/download/nvdla-demo-0.1
  420. DEMO_IMAGE := sifive-debian-demo-mar7.tar.xz
  421. DEMO_URL := https://github.com/tmagik/freedom-u-sdk/releases/download/hifiveu-2.0-alpha.1/
  422. #nvdla image
  423. format-nvdla-image: format-boot-loader
  424. @echo "Done setting up basic initramfs boot. We will now try to install"
  425. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  426. @echo "you can safely cancel here"
  427. @test -e $(wrkdir)/$(DEB_IMAGE) || (wget -P $(wrkdir) $(DEB_URL)/$(DEB_IMAGE))
  428. /sbin/mke2fs -t ext4 $(PART4)
  429. -mkdir -p tmp-mnt
  430. -mount $(PART4) tmp-mnt && \
  431. echo "please wait until checkpoint reaches 489k" && \
  432. tar Jxf $(wrkdir)/$(DEB_IMAGE) -C tmp-mnt --checkpoint=1000
  433. umount tmp-mnt
  434. #demo image
  435. format-demo-image: format-boot-loader
  436. @echo "Done setting up basic initramfs boot. We will now try to install"
  437. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  438. @echo "you can safely cancel here"
  439. /sbin/mke2fs -t ext4 $(PART4)
  440. -mkdir tmp-mnt
  441. -sudo mount $(PART4) tmp-mnt && cd tmp-mnt && \
  442. sudo wget $(DEMO_URL)$(DEMO_IMAGE) && \
  443. sudo tar -Jxvf $(DEMO_IMAGE)
  444. sudo umount tmp-mnt
  445. -include $(initramfs).d