Makefile 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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:/usr/sbin:/sbin:$(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 CROSS_COMPILE=$(CROSS_COMPILE) 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 CROSS_COMPILE=$(CROSS_COMPILE) 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 CROSS_COMPILE=$(CROSS_COMPILE) 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) $(buildroot_initramfs_sysroot)
  145. $(MAKE) -C $< O=$(linux_wrkdir) \
  146. ARCH=riscv \
  147. CROSS_COMPILE=$(CROSS_COMPILE) \
  148. PATH=$(RVPATH) \
  149. vmlinux \
  150. all \
  151. modules
  152. $(MAKE) -C $< O=$(linux_wrkdir) \
  153. ARCH=riscv \
  154. CROSS_COMPILE=$(CROSS_COMPILE) \
  155. PATH=$(RVPATH) \
  156. INSTALL_MOD_PATH=$(buildroot_initramfs_sysroot) \
  157. modules_install
  158. .PHONY: initrd
  159. initrd: $(initramfs)
  160. $(initramfs).d: $(buildroot_initramfs_sysroot)
  161. $(linux_srcdir)/usr/gen_initramfs_list.sh -l $(confdir)/initramfs.txt $(buildroot_initramfs_sysroot) > $@
  162. $(initramfs): $(buildroot_initramfs_sysroot) $(vmlinux)
  163. cd $(linux_wrkdir) && \
  164. $(linux_srcdir)/usr/gen_initramfs_list.sh \
  165. -o $@ -u $(shell id -u) -g $(shell id -g) \
  166. $(confdir)/initramfs.txt \
  167. $(buildroot_initramfs_sysroot)
  168. $(vmlinux_stripped): $(vmlinux)
  169. PATH=$(RVPATH) $(target)-strip -o $@ $<
  170. $(vmlinux_bin): $(vmlinux)
  171. PATH=$(RVPATH) $(target)-objcopy -O binary $< $@
  172. .PHONY: linux-menuconfig
  173. linux-menuconfig: $(linux_wrkdir)/.config
  174. $(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
  175. $(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) savedefconfig
  176. cp $(dir $<)defconfig $(linux_defconfig)
  177. sbi: $(uboot) $(vmlinux)
  178. rm -rf $(sbi_wrkdir)
  179. mkdir -p $(sbi_wrkdir)
  180. cd $(sbi_wrkdir) && O=$(sbi_wrkdir) CFLAGS="-mabi=$(ABI) -march=$(ISA)" ${MAKE} -C $(sbi_srcdir) CROSS_COMPILE=$(CROSS_COMPILE) \
  181. PLATFORM=starfive/vic7100 FW_PAYLOAD_PATH=$(uboot) FW_PAYLOAD_FDT_PATH=$(uboot_dtb_file)
  182. $(fit): sbi $(vmlinux_bin) $(uboot) $(its_file) ${initramfs}
  183. $(uboot_wrkdir)/tools/mkimage -f $(its_file) -A riscv -O linux -T flat_dt $@
  184. @if [ -f fsz.sh ]; then ./fsz.sh $(sbi_bin); fi
  185. $(libfesvr): $(fesvr_srcdir)
  186. rm -rf $(fesvr_wrkdir)
  187. mkdir -p $(fesvr_wrkdir)
  188. mkdir -p $(dir $@)
  189. cd $(fesvr_wrkdir) && $</configure \
  190. --prefix=$(dir $(abspath $(dir $@)))
  191. $(MAKE) -C $(fesvr_wrkdir)
  192. $(MAKE) -C $(fesvr_wrkdir) install
  193. touch -c $@
  194. $(spike): $(spike_srcdir) $(libfesvr)
  195. rm -rf $(spike_wrkdir)
  196. mkdir -p $(spike_wrkdir)
  197. mkdir -p $(dir $@)
  198. cd $(spike_wrkdir) && PATH=$(RVPATH) $</configure \
  199. --prefix=$(dir $(abspath $(dir $@))) \
  200. --with-fesvr=$(dir $(abspath $(dir $(libfesvr))))
  201. $(MAKE) PATH=$(RVPATH) -C $(spike_wrkdir)
  202. $(MAKE) -C $(spike_wrkdir) install
  203. touch -c $@
  204. $(qemu): $(qemu_srcdir)
  205. rm -rf $(qemu_wrkdir)
  206. mkdir -p $(qemu_wrkdir)
  207. mkdir -p $(dir $@)
  208. which pkg-config
  209. # pkg-config from buildroot blows up qemu configure
  210. cd $(qemu_wrkdir) && $</configure \
  211. --prefix=$(dir $(abspath $(dir $@))) \
  212. --target-list=riscv64-softmmu
  213. $(MAKE) -C $(qemu_wrkdir)
  214. $(MAKE) -C $(qemu_wrkdir) install
  215. touch -c $@
  216. .PHONY: uboot-menuconfig
  217. uboot-menuconfig: $(uboot_wrkdir)/.config
  218. $(MAKE) -C $(uboot_srcdir) O=$(dir $<) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
  219. cp $(uboot_wrkdir)/.config $(uboot_defconfig)
  220. $(uboot): $(uboot_srcdir) $(target_gcc)
  221. rm -rf $(uboot_wrkdir)
  222. mkdir -p $(uboot_wrkdir)
  223. mkdir -p $(dir $@)
  224. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE) $(uboot_config)
  225. $(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE)
  226. $(rootfs): $(buildroot_rootfs_ext)
  227. cp $< $@
  228. $(buildroot_initramfs_sysroot): $(buildroot_initramfs_sysroot_stamp)
  229. .PHONY: buildroot_initramfs_sysroot vmlinux bbl fit
  230. buildroot_initramfs_sysroot: $(buildroot_initramfs_sysroot)
  231. vmlinux: $(vmlinux)
  232. fit: $(fit)
  233. .PHONY: clean
  234. clean:
  235. rm -rf work/HiFive_U-Boot
  236. rm -rf work/opensbi
  237. rm work/vmlinux.bin
  238. rm work/hifive-unleashed-vfat.part
  239. rm work/image.fit
  240. rm work/initramfs.cpio.gz
  241. rm work/linux/vmlinux
  242. .PHONY: distclean
  243. distclean:
  244. rm -rf -- $(wrkdir) $(toolchain_dest)
  245. .PHONY: sim
  246. sim: $(spike) $(bbl_payload)
  247. $(spike) --isa=$(ISA) -p4 $(bbl_payload)
  248. .PHONY: qemu
  249. qemu: $(qemu) $(sbi) $(vmlinux) $(initramfs)
  250. $(qemu) -nographic -machine virt -bios $(bbl) -kernel $(vmlinux) -initrd $(initramfs) \
  251. -netdev user,id=net0 -device virtio-net-device,netdev=net0
  252. .PHONY: qemu-rootfs
  253. qemu-rootfs: $(qemu) $(bbl) $(vmlinux) $(initramfs) $(rootfs)
  254. $(qemu) -nographic -machine virt -bios $(bbl) -kernel $(vmlinux) -initrd $(initramfs) \
  255. -drive file=$(rootfs),format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
  256. -netdev user,id=net0 -device virtio-net-device,netdev=net0
  257. .PHONY: uboot
  258. uboot: $(uboot)
  259. # disk tools
  260. MKFS_VFAT ?= mkfs.vfat
  261. MKFS_EXT4 ?= mkfs.ext4
  262. PARTPROBE ?= partprobe
  263. SGDISK ?= sgdisk
  264. # Relevant partition type codes
  265. BBL = 2E54B353-1271-4842-806F-E436D6AF6985
  266. VFAT = EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  267. LINUX = 0FC63DAF-8483-4772-8E79-3D69D8477DE4
  268. #FSBL = 5B193300-FC78-40CD-8002-E86C45580B47
  269. UBOOT = 5B193300-FC78-40CD-8002-E86C45580B47
  270. UBOOTENV = a09354ac-cd63-11e8-9aff-70b3d592f0fa
  271. UBOOTDTB = 070dd1a8-cd64-11e8-aa3d-70b3d592f0fa
  272. UBOOTFIT = 04ffcafa-cd65-11e8-b974-70b3d592f0fa
  273. flash.gpt: $(flash_image)
  274. ifeq ($(TARGET_BOARD),U74)
  275. VFAT_START=4096
  276. VFAT_END=270335
  277. VFAT_SIZE=266239
  278. UBOOT_START=270336
  279. UBOOT_END=272383
  280. UBOOT_SIZE=2047
  281. UENV_START=272384
  282. UENV_END=274431
  283. $(vfat_image): $(fit) $(confdir)/u74_uEnv.txt
  284. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  285. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  286. rm $(flash_image); exit 1; fi
  287. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  288. $(MKFS_VFAT) $(vfat_image)
  289. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
  290. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/u74_uEnv.txt ::u74_uEnv.txt
  291. else
  292. VFAT_START=4096
  293. VFAT_END=269502
  294. VFAT_SIZE=263454
  295. UBOOT_START=2048
  296. UBOOT_END=4048
  297. UBOOT_SIZE=2000
  298. UENV_START=1024
  299. UENV_END=1099
  300. $(vfat_image): $(fit) $(confdir)/uEnv.txt
  301. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  302. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  303. rm $(flash_image); exit 1; fi
  304. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  305. $(MKFS_VFAT) $(vfat_image)
  306. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
  307. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/uEnv.txt ::uEnv.txt
  308. endif
  309. $(flash_image): $(uboot) $(fit) $(vfat_image)
  310. dd if=/dev/zero of=$(flash_image) bs=1M count=32
  311. $(SGDISK) --clear -g \
  312. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  313. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  314. --new=3:$(UENV_START):$(UENV_END) --change-name=3:uboot-env --typecode=3:$(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. DEMO_END=11718750
  319. #$(demo_image): $(uboot) $(fit) $(vfat_image) $(ext_image)
  320. # dd if=/dev/zero of=$(flash_image) bs=512 count=$(DEMO_END)
  321. # $(SGDISK) --clear -g \
  322. # --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  323. # --new=3:$(UBOOT_START):$(UBOOT_END) --change-name=3:uboot --typecode=3:$(UBOOT) \
  324. # --new=2:264192:$(DEMO_END) --change-name=2:root --typecode=2:$(LINUX) \
  325. # --new=4:1024:1247 --change-name=4:uboot-env --typecode=4:$(UBOOTENV) \
  326. # $(flash_image)
  327. # dd conv=notrunc if=$(vfat_image) of=$(flash_image) bs=512 seek=$(VFAT_START)
  328. # dd conv=notrunc if=$(uboot) of=$(flash_image) bs=512 seek=$(UBOOT_START) count=$(UBOOT_SIZE)
  329. .PHONY: format-boot-loader
  330. format-boot-loader: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
  331. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  332. $(SGDISK) --clear -g \
  333. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  334. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  335. --new=3:$(UENV_START):$(UENV_END) --change-name=3:uboot-env --typecode=3:$(UBOOTENV) \
  336. --new=4:274432:0 --change-name=4:root --typecode=4:$(LINUX) \
  337. $(DISK)
  338. -$(PARTPROBE)
  339. @sleep 1
  340. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  341. @$(eval PART1 := $(DISK)p1)
  342. @$(eval PART2 := $(DISK)p2)
  343. @$(eval PART3 := $(DISK)p3)
  344. @$(eval PART4 := $(DISK)p4)
  345. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  346. @$(eval PART1 := $(DISK)s1)
  347. @$(eval PART2 := $(DISK)s2)
  348. @$(eval PART3 := $(DISK)s3)
  349. @$(eval PART4 := $(DISK)s4)
  350. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  351. @$(eval PART1 := $(DISK)1)
  352. @$(eval PART2 := $(DISK)2)
  353. @$(eval PART3 := $(DISK)3)
  354. @$(eval PART4 := $(DISK)4)
  355. else
  356. @echo Error: Could not find bootloader partition for $(DISK)
  357. @exit 1
  358. endif
  359. dd if=$(uboot) of=$(PART2) bs=4096
  360. dd if=$(vfat_image) of=$(PART1) bs=4096
  361. DEMO_IMAGE := sifive-debian-demo-mar7.tar.xz
  362. DEMO_URL := https://github.com/tmagik/freedom-u-sdk/releases/download/hifiveu-2.0-alpha.1/
  363. format-rootfs-image: format-boot-loader
  364. @echo "Done setting up basic initramfs boot. We will now try to install"
  365. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  366. @echo "you can safely cancel here"
  367. $(MKFS_EXT4) $(PART4)
  368. -mkdir -p tmp-mnt
  369. -mkdir -p tmp-rootfs
  370. -sudo mount $(PART4) tmp-mnt && \
  371. sudo mount -o loop $(buildroot_rootfs_ext) tmp-rootfs&& \
  372. sudo cp -fr tmp-rootfs/* tmp-mnt/
  373. sudo umount tmp-mnt
  374. sudo umount tmp-rootfs
  375. format-demo-image: format-boot-loader
  376. @echo "Done setting up basic initramfs boot. We will now try to install"
  377. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  378. @echo "you can safely cancel here"
  379. $(MKFS_EXT4) $(PART4)
  380. -mkdir tmp-mnt
  381. -sudo mount $(PART4) tmp-mnt && cd tmp-mnt && \
  382. sudo wget $(DEMO_URL)$(DEMO_IMAGE) && \
  383. sudo tar -xvpf $(DEMO_IMAGE)
  384. sudo umount tmp-mnt
  385. # default size: 16GB
  386. DISK_IMAGE_SIZE ?= 16
  387. ROOT_BEGIN=272384
  388. ROOT_CLUSTER_NUM=$(shell echo $$(($(DISK_IMAGE_SIZE)*1024*1024*1024/512)))
  389. ROOT_END=$(shell echo $$(($(ROOT_BEGIN)+$(ROOT_CLUSTER_NUM))))
  390. format-nvdla-disk: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
  391. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  392. sudo $(SGDISK) --clear -g \
  393. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  394. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  395. --new=3:$(ROOT_BEGIN):0 --change-name=3:root --typecode=3:$(LINUX) \
  396. $(DISK)
  397. -$(PARTPROBE)
  398. @sleep 3
  399. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  400. @$(eval PART1 := $(DISK)p1)
  401. @$(eval PART2 := $(DISK)p2)
  402. @$(eval PART3 := $(DISK)p3)
  403. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  404. @$(eval PART1 := $(DISK)s1)
  405. @$(eval PART2 := $(DISK)s2)
  406. @$(eval PART3 := $(DISK)s3)
  407. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  408. @$(eval PART1 := $(DISK)1)
  409. @$(eval PART2 := $(DISK)2)
  410. @$(eval PART3 := $(DISK)3)
  411. else
  412. @echo Error: Could not find bootloader partition for $(DISK)
  413. @exit 1
  414. endif
  415. sudo dd if=$(uboot) of=$(PART2) bs=4096
  416. sudo dd if=$(vfat_image) of=$(PART1) bs=4096
  417. #usb config
  418. format-usb-disk: sbi $(uboot) $(fit) $(vfat_image)
  419. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  420. sudo $(SGDISK) --clear -g \
  421. --new=1:0:+256M --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  422. --new=2:0:+1G --change-name=2:uboot --typecode=2:$(UBOOT) -g\
  423. $(DISK)
  424. -$(PARTPROBE)
  425. @sleep 3
  426. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  427. @$(eval PART1 := $(DISK)p1)
  428. @$(eval PART2 := $(DISK)p2)
  429. # @$(eval PART3 := $(DISK)p3)
  430. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  431. @$(eval PART1 := $(DISK)s1)
  432. @$(eval PART2 := $(DISK)s2)
  433. # @$(eval PART3 := $(DISK)s3)
  434. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  435. @$(eval PART1 := $(DISK)1)
  436. @$(eval PART2 := $(DISK)2)
  437. # @$(eval PART3 := $(DISK)3)
  438. else
  439. @echo Error: Could not find bootloader partition for $(DISK)
  440. @exit 1
  441. endif
  442. sudo dd if=$(uboot) of=$(PART2) bs=4096
  443. sudo dd if=$(vfat_image) of=$(PART1) bs=4096
  444. DEB_IMAGE := debian_nvdla_20190506.tar.xz
  445. DEB_URL := https://github.com/sifive/freedom-u-sdk/releases/download/nvdla-demo-0.1
  446. format-nvdla-rootfs: format-nvdla-disk
  447. @echo "Done setting up basic initramfs boot. We will now try to install"
  448. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  449. @echo "you can safely cancel here"
  450. sudo $(MKFS_EXT4) $(PART3)
  451. -mkdir -p tmp-mnt
  452. -mkdir -p tmp-rootfs
  453. -sudo mount $(PART3) tmp-mnt && \
  454. sudo mount -o loop $(buildroot_rootfs_ext) tmp-rootfs&& \
  455. sudo cp -fr tmp-rootfs/* tmp-mnt/
  456. sudo umount tmp-mnt
  457. sudo umount tmp-rootfs
  458. format-nvdla-root: format-nvdla-disk
  459. @echo "Done setting up basic initramfs boot. We will now try to install"
  460. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  461. @echo "you can safely cancel here"
  462. @test -e $(wrkdir)/$(DEB_IMAGE) || (wget -P $(wrkdir) $(DEB_URL)/$(DEB_IMAGE))
  463. sudo $(MKFS_EXT4) $(PART3)
  464. -mkdir -p tmp-mnt
  465. -sudo mount $(PART3) tmp-mnt && \
  466. echo "please wait until checkpoint reaches 489k" && \
  467. sudo tar xpf $(wrkdir)/$(DEB_IMAGE) -C tmp-mnt --checkpoint=1000
  468. sudo umount tmp-mnt
  469. -include $(initramfs).d