Makefile 22 KB

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