Makefile 19 KB

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