Makefile 17 KB

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