Makefile 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. ISA ?= rv64imafdc
  2. ABI ?= lp64d
  3. #TARGET_BOARD is U74 ,JH7110 or NULL
  4. TARGET_BOARD := JH7110
  5. BOARD_FLAGS :=
  6. HWBOARD ?= fpga
  7. HWBOARD_FLAG ?= HWBOARD_FPGA
  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. linux_defconfig := $(linux_srcdir)/arch/riscv/configs/starfive_jh7110_defconfig
  29. vmlinux := $(linux_wrkdir)/vmlinux
  30. vmlinux_stripped := $(linux_wrkdir)/vmlinux-stripped
  31. vmlinux_bin := $(wrkdir)/vmlinux.bin
  32. ifeq ($(TARGET_BOARD),JH7110)
  33. export TARGET_BOARD
  34. its_file=$(confdir)/$(HWBOARD)-fit-image.its
  35. else ifeq ($(TARGET_BOARD),U74)
  36. export TARGET_BOARD
  37. BOARD_FLAGS += -DTARGET_BOARD_U74
  38. bbl_link_addr :=0x80700000
  39. its_file=$(confdir)/u74_nvdla-uboot-fit-image.its
  40. else
  41. bbl_link_addr :=0x80000000
  42. its_file=$(confdir)/nvdla-uboot-fit-image.its
  43. endif
  44. flash_image := $(wrkdir)/hifive-unleashed-a00-YYYY-MM-DD.gpt
  45. vfat_image := $(wrkdir)/hifive-unleashed-vfat.part
  46. #ext_image := $(wrkdir) # TODO
  47. initramfs := $(wrkdir)/initramfs.cpio.gz
  48. sbi_srcdir := $(srcdir)/opensbi
  49. sbi_wrkdir := $(wrkdir)/opensbi
  50. ifeq ($(TARGET_BOARD),JH7110)
  51. sbi_bin := $(wrkdir)/opensbi/platform/starfive/firmware/fw_payload.bin
  52. else
  53. sbi_bin := $(wrkdir)/opensbi/platform/starfive/firmware/fw_payload.bin
  54. endif
  55. fit := $(wrkdir)/image.fit
  56. fesvr_srcdir := $(srcdir)/riscv-fesvr
  57. fesvr_wrkdir := $(wrkdir)/riscv-fesvr
  58. libfesvr := $(fesvr_wrkdir)/prefix/lib/libfesvr.so
  59. spike_srcdir := $(srcdir)/riscv-isa-sim
  60. spike_wrkdir := $(wrkdir)/riscv-isa-sim
  61. spike := $(spike_wrkdir)/prefix/bin/spike
  62. qemu_srcdir := $(srcdir)/riscv-qemu
  63. qemu_wrkdir := $(wrkdir)/riscv-qemu
  64. qemu := $(qemu_wrkdir)/prefix/bin/qemu-system-riscv64
  65. uboot_srcdir := $(srcdir)/u-boot
  66. uboot_wrkdir := $(wrkdir)/u-boot
  67. ifeq ($(TARGET_BOARD),JH7110)
  68. uboot_dtb_file := $(wrkdir)/u-boot/arch/riscv/dts/starfive_visionfive.dtb
  69. else
  70. uboot_dtb_file := $(wrkdir)/u-boot/arch/riscv/dts/starfive_vic7100_evb.dtb
  71. endif
  72. uboot := $(uboot_wrkdir)/u-boot.bin
  73. uboot_config := HiFive-U540_regression_defconfig
  74. ifeq ($(TARGET_BOARD),JH7110)
  75. uboot_config := starfive_visionfive_defconfig
  76. else ifeq ($(TARGET_BOARD),U74)
  77. uboot_config := starfive_vic7100_evb_smode_defconfig
  78. else
  79. uboot_config := HiFive-U540_nvdla_iofpga_defconfig
  80. endif
  81. uboot_defconfig := $(uboot_srcdir)/configs/$(uboot_config)
  82. rootfs := $(wrkdir)/rootfs.bin
  83. target_gcc := $(CROSS_COMPILE)gcc
  84. .PHONY: all nvdla-demo check_arg
  85. nvdla-demo: check_arg $(fit) $(vfat_image)
  86. @echo "To completely erase, reformat, and program a disk sdX, run:"
  87. @echo " make DISK=/dev/sdX format-nvdla-disk"
  88. @echo " ... you will need gdisk and e2fsprogs installed"
  89. @echo " Please note this will not currently format the SDcard ext4 partition"
  90. @echo " This can be done manually if needed"
  91. @echo
  92. all: check_arg $(fit) $(flash_image)
  93. @echo
  94. @echo "This image has been generated for an ISA of $(ISA) and an ABI of $(ABI)"
  95. @echo "Find the image in work/image.fit, which should be copied to an MSDOS boot partition 1"
  96. @echo
  97. @echo "To completely erase, reformat, and program a disk sdX, run:"
  98. @echo " make DISK=/dev/sdX format-boot-loader"
  99. @echo " ... you will need gdisk and e2fsprogs installed"
  100. @echo " Please note this will not currently format the SDcard ext4 partition"
  101. @echo " This can be done manually if needed"
  102. @echo
  103. check_arg:
  104. ifeq ( , $(filter $(HWBOARD), visionfive evb fpga))
  105. $(error board $(HWBOARD) is not supported, BOARD=[visionfive | evb | fpga(deflault)])
  106. endif
  107. # TODO: depracated for now
  108. #ifneq ($(RISCV),$(buildroot_initramfs_wrkdir)/host)
  109. #$(target_gcc):
  110. # $(error The RISCV environment variable was set, but is not pointing at a toolchain install tree)
  111. #else
  112. #$(target_gcc): $(buildroot_initramfs_tar)
  113. #endif
  114. .PHONY: visionfive evb fpga
  115. visionfive: HWBOARD := visionfive
  116. visionfive: nvdla-demo
  117. visionfive: HWBOARD_FLAG := HWBOARD_VISIONFIVE
  118. evb: HWBOARD := evb
  119. evb: nvdla-demo
  120. evb: HWBOARD_FLAG := HWBOARD_EVB
  121. fpga: HWBOARD := fpga
  122. fpga: nvdla-demo
  123. fpga: HWBOARD_FLAG := HWBOARD_FPGA
  124. $(buildroot_initramfs_wrkdir)/.config: $(buildroot_srcdir)
  125. rm -rf $(dir $@)
  126. mkdir -p $(dir $@)
  127. cp $(buildroot_initramfs_config) $@
  128. $(MAKE) -C $< RISCV=$(RISCV) O=$(buildroot_initramfs_wrkdir) olddefconfig
  129. # buildroot_initramfs provides gcc
  130. $(buildroot_initramfs_tar): $(buildroot_srcdir) $(buildroot_initramfs_wrkdir)/.config $(buildroot_initramfs_config)
  131. $(MAKE) -C $< RISCV=$(RISCV) O=$(buildroot_initramfs_wrkdir)
  132. .PHONY: buildroot_initramfs-menuconfig
  133. buildroot_initramfs-menuconfig: $(buildroot_initramfs_wrkdir)/.config $(buildroot_srcdir)
  134. $(MAKE) -C $(dir $<) O=$(buildroot_initramfs_wrkdir) menuconfig
  135. $(MAKE) -C $(dir $<) O=$(buildroot_initramfs_wrkdir) savedefconfig
  136. cp $(dir $<)defconfig $(buildroot_initramfs_config)
  137. # use buildroot_initramfs toolchain
  138. # TODO: fix path and conf/buildroot_rootfs_config
  139. $(buildroot_rootfs_wrkdir)/.config: $(buildroot_srcdir) $(buildroot_initramfs_tar)
  140. rm -rf $(dir $@)
  141. mkdir -p $(dir $@)
  142. cp $(buildroot_rootfs_config) $@
  143. $(MAKE) -C $< RISCV=$(RISCV) PATH=$(RVPATH) O=$(buildroot_rootfs_wrkdir) olddefconfig
  144. $(buildroot_rootfs_ext): $(buildroot_srcdir) $(buildroot_rootfs_wrkdir)/.config $(target_gcc) $(buildroot_rootfs_config)
  145. $(MAKE) -C $< RISCV=$(RISCV) PATH=$(RVPATH) O=$(buildroot_rootfs_wrkdir)
  146. .PHONY: buildroot_rootfs
  147. buildroot_rootfs: $(buildroot_rootfs_ext)
  148. cp $< $@
  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) ARCH=riscv olddefconfig
  162. ifeq (,$(filter rv%c,$(ISA)))
  163. sed 's/^.*CONFIG_RISCV_ISA_C.*$$/CONFIG_RISCV_ISA_C=n/' -i $@
  164. $(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
  165. endif
  166. ifeq ($(ISA),$(filter rv32%,$(ISA)))
  167. sed 's/^.*CONFIG_ARCH_RV32I.*$$/CONFIG_ARCH_RV32I=y/' -i $@
  168. sed 's/^.*CONFIG_ARCH_RV64I.*$$/CONFIG_ARCH_RV64I=n/' -i $@
  169. $(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
  170. endif
  171. $(uboot_wrkdir)/.config: $(uboot_defconfig)
  172. mkdir -p $(dir $@)
  173. cp -p $< $@
  174. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) ARCH=riscv olddefconfig
  175. $(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(target_gcc)
  176. $(MAKE) -C $< O=$(linux_wrkdir) \
  177. ARCH=riscv \
  178. CROSS_COMPILE=$(CROSS_COMPILE) \
  179. PATH=$(RVPATH) \
  180. vmlinux \
  181. HWBOARD_FLAG=$(HWBOARD_FLAG) \
  182. all \
  183. modules
  184. .PHONY: initrd
  185. initrd: $(initramfs)
  186. $(initramfs).d: $(buildroot_initramfs_sysroot)
  187. $(linux_srcdir)/usr/gen_initramfs_list.sh -l $(confdir)/initramfs.txt $(buildroot_initramfs_sysroot) > $@
  188. $(initramfs): $(buildroot_initramfs_sysroot) $(vmlinux)
  189. cd $(linux_wrkdir) && \
  190. $(linux_srcdir)/usr/gen_initramfs_list.sh \
  191. -o $@ -u $(shell id -u) -g $(shell id -g) \
  192. $(confdir)/initramfs.txt \
  193. $(buildroot_initramfs_sysroot)
  194. $(vmlinux_stripped): $(vmlinux)
  195. PATH=$(RVPATH) $(target)-strip -o $@ $<
  196. $(vmlinux_bin): $(vmlinux)
  197. PATH=$(RVPATH) $(target)-objcopy -O binary $< $@
  198. .PHONY: linux-menuconfig
  199. linux-menuconfig: $(linux_wrkdir)/.config
  200. $(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv menuconfig
  201. $(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv savedefconfig
  202. cp $(dir $<)defconfig $(linux_defconfig)
  203. ifeq ($(TARGET_BOARD),JH7110)
  204. sbi: $(uboot) $(vmlinux)
  205. rm -rf $(sbi_wrkdir)
  206. mkdir -p $(sbi_wrkdir)
  207. cd $(sbi_wrkdir) && O=$(sbi_wrkdir) CFLAGS="-mabi=$(ABI) -march=$(ISA)" ${MAKE} -C $(sbi_srcdir) CROSS_COMPILE=$(CROSS_COMPILE) \
  208. PLATFORM=starfive FW_PAYLOAD_PATH=$(uboot) FW_FDT_PATH=$(uboot_dtb_file)
  209. else
  210. sbi: $(uboot) $(vmlinux)
  211. rm -rf $(sbi_wrkdir)
  212. mkdir -p $(sbi_wrkdir)
  213. cd $(sbi_wrkdir) && O=$(sbi_wrkdir) CFLAGS="-mabi=$(ABI) -march=$(ISA)" ${MAKE} -C $(sbi_srcdir) CROSS_COMPILE=$(CROSS_COMPILE) \
  214. PLATFORM=starfive FW_PAYLOAD_PATH=$(uboot) FW_FDT_PATH=$(uboot_dtb_file)
  215. endif
  216. $(fit): sbi $(vmlinux_bin) $(uboot) $(its_file) ${initramfs}
  217. $(uboot_wrkdir)/tools/mkimage -f $(its_file) -A riscv -O linux -T flat_dt $@
  218. @if [ -f fsz.sh ]; then ./fsz.sh $(sbi_bin); fi
  219. $(libfesvr): $(fesvr_srcdir)
  220. rm -rf $(fesvr_wrkdir)
  221. mkdir -p $(fesvr_wrkdir)
  222. mkdir -p $(dir $@)
  223. cd $(fesvr_wrkdir) && $</configure \
  224. --prefix=$(dir $(abspath $(dir $@)))
  225. $(MAKE) -C $(fesvr_wrkdir)
  226. $(MAKE) -C $(fesvr_wrkdir) install
  227. touch -c $@
  228. $(spike): $(spike_srcdir) $(libfesvr)
  229. rm -rf $(spike_wrkdir)
  230. mkdir -p $(spike_wrkdir)
  231. mkdir -p $(dir $@)
  232. cd $(spike_wrkdir) && PATH=$(RVPATH) $</configure \
  233. --prefix=$(dir $(abspath $(dir $@))) \
  234. --with-fesvr=$(dir $(abspath $(dir $(libfesvr))))
  235. $(MAKE) PATH=$(RVPATH) -C $(spike_wrkdir)
  236. $(MAKE) -C $(spike_wrkdir) install
  237. touch -c $@
  238. $(qemu): $(qemu_srcdir)
  239. rm -rf $(qemu_wrkdir)
  240. mkdir -p $(qemu_wrkdir)
  241. mkdir -p $(dir $@)
  242. which pkg-config
  243. # pkg-config from buildroot blows up qemu configure
  244. cd $(qemu_wrkdir) && $</configure \
  245. --prefix=$(dir $(abspath $(dir $@))) \
  246. --target-list=riscv64-softmmu
  247. $(MAKE) -C $(qemu_wrkdir)
  248. $(MAKE) -C $(qemu_wrkdir) install
  249. touch -c $@
  250. .PHONY: uboot-menuconfig
  251. uboot-menuconfig: $(uboot_wrkdir)/.config
  252. $(MAKE) -C $(uboot_srcdir) O=$(dir $<) ARCH=riscv menuconfig
  253. $(MAKE) -C $(uboot_srcdir) O=$(dir $<) ARCH=riscv savedefconfig
  254. cp $(dir $<)defconfig $(uboot_defconfig)
  255. $(uboot): $(uboot_srcdir) $(target_gcc)
  256. rm -rf $(uboot_wrkdir)
  257. mkdir -p $(uboot_wrkdir)
  258. mkdir -p $(dir $@)
  259. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) $(uboot_config)
  260. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE)
  261. $(rootfs): $(buildroot_rootfs_ext)
  262. cp $< $@
  263. $(buildroot_initramfs_sysroot): $(buildroot_initramfs_sysroot_stamp)
  264. .PHONY: buildroot_initramfs_sysroot vmlinux bbl fit
  265. buildroot_initramfs_sysroot: $(buildroot_initramfs_sysroot)
  266. vmlinux: $(vmlinux)
  267. fit: $(fit)
  268. .PHONY: clean
  269. clean:
  270. rm -rf work/u-boot
  271. rm -rf work/opensbi
  272. rm work/vmlinux.bin
  273. rm work/hifive-unleashed-vfat.part
  274. rm work/image.fit
  275. rm work/initramfs.cpio.gz
  276. rm work/linux/vmlinux
  277. .PHONY: distclean
  278. distclean:
  279. rm -rf -- $(wrkdir) $(toolchain_dest)
  280. .PHONY: sim
  281. sim: $(spike) $(bbl_payload)
  282. $(spike) --isa=$(ISA) -p4 $(bbl_payload)
  283. .PHONY: qemu
  284. qemu: $(qemu) $(sbi) $(vmlinux) $(initramfs)
  285. $(qemu) -nographic -machine virt -bios $(bbl) -kernel $(vmlinux) -initrd $(initramfs) \
  286. -netdev user,id=net0 -device virtio-net-device,netdev=net0
  287. .PHONY: qemu-rootfs
  288. qemu-rootfs: $(qemu) $(bbl) $(vmlinux) $(initramfs) $(rootfs)
  289. $(qemu) -nographic -machine virt -bios $(bbl) -kernel $(vmlinux) -initrd $(initramfs) \
  290. -drive file=$(rootfs),format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
  291. -netdev user,id=net0 -device virtio-net-device,netdev=net0
  292. .PHONY: uboot
  293. uboot: $(uboot)
  294. # Relevant partition type codes
  295. BBL = 2E54B353-1271-4842-806F-E436D6AF6985
  296. VFAT = EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  297. LINUX = 0FC63DAF-8483-4772-8E79-3D69D8477DE4
  298. #FSBL = 5B193300-FC78-40CD-8002-E86C45580B47
  299. UBOOT = 5B193300-FC78-40CD-8002-E86C45580B47
  300. UBOOTENV = a09354ac-cd63-11e8-9aff-70b3d592f0fa
  301. UBOOTDTB = 070dd1a8-cd64-11e8-aa3d-70b3d592f0fa
  302. UBOOTFIT = 04ffcafa-cd65-11e8-b974-70b3d592f0fa
  303. flash.gpt: $(flash_image)
  304. ifeq ($(TARGET_BOARD),JH7110)
  305. VFAT_SIZE=263454
  306. $(vfat_image): $(fit) $(confdir)/jh7110_uEnv.txt
  307. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  308. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  309. rm $(flash_image); exit 1; fi
  310. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  311. /sbin/mkfs.vfat $(vfat_image)
  312. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::starfiveu.fit
  313. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/jh7110_uEnv.txt ::jh7110_uEnv.txt
  314. else ifeq ($(TARGET_BOARD),U74)
  315. VFAT_START=4096
  316. VFAT_END=270335
  317. VFAT_SIZE=266239
  318. UBOOT_START=270336
  319. UBOOT_END=272383
  320. UBOOT_SIZE=2047
  321. UENV_START=272384
  322. UENV_END=274431
  323. $(vfat_image): $(fit) $(confdir)/u74_uEnv.txt
  324. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  325. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  326. rm $(flash_image); exit 1; fi
  327. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  328. /sbin/mkfs.vfat $(vfat_image)
  329. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
  330. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/u74_uEnv.txt ::u74_uEnv.txt
  331. else
  332. VFAT_START=4096
  333. VFAT_END=269502
  334. VFAT_SIZE=263454
  335. UBOOT_START=2048
  336. UBOOT_END=4048
  337. UBOOT_SIZE=2000
  338. UENV_START=1024
  339. UENV_END=1099
  340. $(vfat_image): $(fit) $(confdir)/uEnv.txt
  341. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  342. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  343. rm $(flash_image); exit 1; fi
  344. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  345. /sbin/mkfs.vfat $(vfat_image)
  346. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
  347. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/uEnv.txt ::uEnv.txt
  348. endif
  349. $(flash_image): $(uboot) $(fit) $(vfat_image)
  350. dd if=/dev/zero of=$(flash_image) bs=1M count=32
  351. /sbin/sgdisk --clear \
  352. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  353. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  354. --new=3:$(UENV_START):$(UENV_END) --change-name=3:uboot-env --typecode=3:$(UBOOTENV) \
  355. $(flash_image)
  356. dd conv=notrunc if=$(vfat_image) of=$(flash_image) bs=512 seek=$(VFAT_START)
  357. dd conv=notrunc if=$(uboot) of=$(flash_image) bs=512 seek=$(UBOOT_START) count=$(UBOOT_SIZE)
  358. DEMO_END=11718750
  359. #$(demo_image): $(uboot) $(fit) $(vfat_image) $(ext_image)
  360. # dd if=/dev/zero of=$(flash_image) bs=512 count=$(DEMO_END)
  361. # /sbin/sgdisk --clear \
  362. # --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  363. # --new=3:$(UBOOT_START):$(UBOOT_END) --change-name=3:uboot --typecode=3:$(UBOOT) \
  364. # --new=2:264192:$(DEMO_END) --change-name=2:root --typecode=2:$(LINUX) \
  365. # --new=4:1024:1247 --change-name=4:uboot-env --typecode=4:$(UBOOTENV) \
  366. # $(flash_image)
  367. # dd conv=notrunc if=$(vfat_image) of=$(flash_image) bs=512 seek=$(VFAT_START)
  368. # dd conv=notrunc if=$(uboot) of=$(flash_image) bs=512 seek=$(UBOOT_START) count=$(UBOOT_SIZE)
  369. .PHONY: format-boot-loader
  370. format-boot-loader: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
  371. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  372. /sbin/sgdisk --clear \
  373. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  374. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  375. --new=3:$(UENV_START):$(UENV_END) --change-name=3:uboot-env --typecode=3:$(UBOOTENV) \
  376. --new=4:274432:0 --change-name=4:root --typecode=4:$(LINUX) \
  377. $(DISK)
  378. -/sbin/partprobe
  379. @sleep 1
  380. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  381. @$(eval PART1 := $(DISK)p1)
  382. @$(eval PART2 := $(DISK)p2)
  383. @$(eval PART3 := $(DISK)p3)
  384. @$(eval PART4 := $(DISK)p4)
  385. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  386. @$(eval PART1 := $(DISK)s1)
  387. @$(eval PART2 := $(DISK)s2)
  388. @$(eval PART3 := $(DISK)s3)
  389. @$(eval PART4 := $(DISK)s4)
  390. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  391. @$(eval PART1 := $(DISK)1)
  392. @$(eval PART2 := $(DISK)2)
  393. @$(eval PART3 := $(DISK)3)
  394. @$(eval PART4 := $(DISK)4)
  395. else
  396. @echo Error: Could not find bootloader partition for $(DISK)
  397. @exit 1
  398. endif
  399. dd if=$(uboot) of=$(PART2) bs=4096
  400. dd if=$(vfat_image) of=$(PART1) bs=4096
  401. DEMO_IMAGE := sifive-debian-demo-mar7.tar.xz
  402. DEMO_URL := https://github.com/tmagik/freedom-u-sdk/releases/download/hifiveu-2.0-alpha.1/
  403. format-rootfs-image: format-boot-loader
  404. @echo "Done setting up basic initramfs boot. We will now try to install"
  405. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  406. @echo "you can safely cancel here"
  407. /sbin/mke2fs -t ext4 $(PART4)
  408. -mkdir -p tmp-mnt
  409. -mkdir -p tmp-rootfs
  410. -sudo mount $(PART4) tmp-mnt && \
  411. sudo mount -o loop $(buildroot_rootfs_ext) tmp-rootfs&& \
  412. sudo cp -fr tmp-rootfs/* tmp-mnt/
  413. sudo umount tmp-mnt
  414. sudo umount tmp-rootfs
  415. format-demo-image: format-boot-loader
  416. @echo "Done setting up basic initramfs boot. We will now try to install"
  417. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  418. @echo "you can safely cancel here"
  419. /sbin/mke2fs -t ext4 $(PART4)
  420. -mkdir tmp-mnt
  421. -sudo mount $(PART4) tmp-mnt && cd tmp-mnt && \
  422. sudo wget $(DEMO_URL)$(DEMO_IMAGE) && \
  423. sudo tar -Jxvf $(DEMO_IMAGE)
  424. sudo umount tmp-mnt
  425. ROOT_BEGIN=272384
  426. # default size: 20GB
  427. ROOT_CLUSTER_NUM=$(shell echo $$((20*1024*1024*1024/512)))
  428. ROOT_END=$(shell echo $$(($(ROOT_BEGIN)+$(ROOT_CLUSTER_NUM))))
  429. format-nvdla-disk: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
  430. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  431. /sbin/sgdisk --clear \
  432. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  433. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  434. --new=3:$(ROOT_BEGIN):0 --change-name=3:root --typecode=3:$(LINUX) \
  435. $(DISK)
  436. -/sbin/partprobe
  437. @sleep 1
  438. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  439. @$(eval PART1 := $(DISK)p1)
  440. @$(eval PART2 := $(DISK)p2)
  441. @$(eval PART3 := $(DISK)p3)
  442. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  443. @$(eval PART1 := $(DISK)s1)
  444. @$(eval PART2 := $(DISK)s2)
  445. @$(eval PART3 := $(DISK)s3)
  446. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  447. @$(eval PART1 := $(DISK)1)
  448. @$(eval PART2 := $(DISK)2)
  449. @$(eval PART3 := $(DISK)3)
  450. else
  451. @echo Error: Could not find bootloader partition for $(DISK)
  452. @exit 1
  453. endif
  454. dd if=$(uboot) of=$(PART2) bs=4096
  455. dd if=$(vfat_image) of=$(PART1) bs=4096
  456. #usb config
  457. format-usb-disk: sbi $(uboot) $(fit) $(vfat_image)
  458. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  459. /sbin/sgdisk --clear \
  460. --new=1:0:+256M --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  461. --new=2:0:+1G --change-name=2:uboot --typecode=2:$(UBOOT) -g\
  462. $(DISK)
  463. -/sbin/partprobe
  464. @sleep 1
  465. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  466. @$(eval PART1 := $(DISK)p1)
  467. @$(eval PART2 := $(DISK)p2)
  468. # @$(eval PART3 := $(DISK)p3)
  469. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  470. @$(eval PART1 := $(DISK)s1)
  471. @$(eval PART2 := $(DISK)s2)
  472. # @$(eval PART3 := $(DISK)s3)
  473. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  474. @$(eval PART1 := $(DISK)1)
  475. @$(eval PART2 := $(DISK)2)
  476. # @$(eval PART3 := $(DISK)3)
  477. else
  478. @echo Error: Could not find bootloader partition for $(DISK)
  479. @exit 1
  480. endif
  481. dd if=$(uboot) of=$(PART2) bs=4096
  482. dd if=$(vfat_image) of=$(PART1) bs=4096
  483. DEB_IMAGE := debian_nvdla_20190506.tar.xz
  484. DEB_URL := https://github.com/sifive/freedom-u-sdk/releases/download/nvdla-demo-0.1
  485. format-nvdla-rootfs: format-nvdla-disk
  486. @echo "Done setting up basic initramfs boot. We will now try to install"
  487. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  488. @echo "you can safely cancel here"
  489. /sbin/mke2fs -t ext4 $(PART3)
  490. -mkdir -p tmp-mnt
  491. -mkdir -p tmp-rootfs
  492. -sudo mount $(PART3) tmp-mnt && \
  493. sudo mount -o loop $(buildroot_rootfs_ext) tmp-rootfs&& \
  494. sudo cp -fr tmp-rootfs/* tmp-mnt/
  495. sudo umount tmp-mnt
  496. sudo umount tmp-rootfs
  497. format-nvdla-root: format-nvdla-disk
  498. @echo "Done setting up basic initramfs boot. We will now try to install"
  499. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  500. @echo "you can safely cancel here"
  501. @test -e $(wrkdir)/$(DEB_IMAGE) || (wget -P $(wrkdir) $(DEB_URL)/$(DEB_IMAGE))
  502. /sbin/mke2fs -t ext4 $(PART3)
  503. -mkdir -p tmp-mnt
  504. -mount $(PART3) tmp-mnt && \
  505. echo "please wait until checkpoint reaches 489k" && \
  506. tar Jxf $(wrkdir)/$(DEB_IMAGE) -C tmp-mnt --checkpoint=1000
  507. umount tmp-mnt
  508. -include $(initramfs).d