Makefile 23 KB

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