Makefile 23 KB

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