Makefile 16 KB

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