distro_buildroot_image.mk 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # disk tools
  2. MKFS_VFAT ?= mkfs.vfat
  3. MKFS_EXT4 ?= mkfs.ext4
  4. PARTPROBE ?= partprobe
  5. SGDISK ?= sgdisk
  6. # Relevant partition type codes
  7. BBL = 2E54B353-1271-4842-806F-E436D6AF6985
  8. VFAT = EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  9. LINUX = 0FC63DAF-8483-4772-8E79-3D69D8477DE4
  10. #FSBL = 5B193300-FC78-40CD-8002-E86C45580B47
  11. UBOOT = 5B193300-FC78-40CD-8002-E86C45580B47
  12. UBOOTENV = a09354ac-cd63-11e8-9aff-70b3d592f0fa
  13. UBOOTDTB = 070dd1a8-cd64-11e8-aa3d-70b3d592f0fa
  14. UBOOTFIT = 04ffcafa-cd65-11e8-b974-70b3d592f0fa
  15. flash.gpt: $(flash_image)
  16. ifeq ($(TARGET_BOARD),U74)
  17. VFAT_START=4096
  18. VFAT_END=270335
  19. VFAT_SIZE=266239
  20. UBOOT_START=270336
  21. UBOOT_END=272383
  22. UBOOT_SIZE=2047
  23. UENV_START=272384
  24. UENV_END=274431
  25. $(vfat_image): $(fit) $(confdir)/u74_uEnv.txt
  26. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  27. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  28. rm $(flash_image); exit 1; fi
  29. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  30. $(MKFS_VFAT) $(vfat_image)
  31. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
  32. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/u74_uEnv.txt ::u74_uEnv.txt
  33. else
  34. VFAT_START=4096
  35. VFAT_END=269502
  36. VFAT_SIZE=263454
  37. UBOOT_START=2048
  38. UBOOT_END=4048
  39. UBOOT_SIZE=2000
  40. UENV_START=1024
  41. UENV_END=1099
  42. $(vfat_image): $(fit) $(confdir)/uEnv.txt
  43. @if [ `du --apparent-size --block-size=512 $(uboot) | cut -f 1` -ge $(UBOOT_SIZE) ]; then \
  44. echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
  45. rm $(flash_image); exit 1; fi
  46. dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
  47. $(MKFS_VFAT) $(vfat_image)
  48. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
  49. PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/uEnv.txt ::uEnv.txt
  50. endif
  51. $(flash_image): $(uboot) $(fit) $(vfat_image)
  52. dd if=/dev/zero of=$(flash_image) bs=1M count=32
  53. $(SGDISK) --clear -g \
  54. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  55. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  56. --new=3:$(UENV_START):$(UENV_END) --change-name=3:uboot-env --typecode=3:$(UBOOTENV) \
  57. $(flash_image)
  58. dd conv=notrunc if=$(vfat_image) of=$(flash_image) bs=512 seek=$(VFAT_START)
  59. dd conv=notrunc if=$(uboot) of=$(flash_image) bs=512 seek=$(UBOOT_START) count=$(UBOOT_SIZE)
  60. DEMO_END=11718750
  61. #$(demo_image): $(uboot) $(fit) $(vfat_image) $(ext_image)
  62. # dd if=/dev/zero of=$(flash_image) bs=512 count=$(DEMO_END)
  63. # $(SGDISK) --clear -g \
  64. # --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  65. # --new=3:$(UBOOT_START):$(UBOOT_END) --change-name=3:uboot --typecode=3:$(UBOOT) \
  66. # --new=2:264192:$(DEMO_END) --change-name=2:root --typecode=2:$(LINUX) \
  67. # --new=4:1024:1247 --change-name=4:uboot-env --typecode=4:$(UBOOTENV) \
  68. # $(flash_image)
  69. # dd conv=notrunc if=$(vfat_image) of=$(flash_image) bs=512 seek=$(VFAT_START)
  70. # dd conv=notrunc if=$(uboot) of=$(flash_image) bs=512 seek=$(UBOOT_START) count=$(UBOOT_SIZE)
  71. .PHONY: format-boot-loader
  72. format-boot-loader: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
  73. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  74. $(SGDISK) --clear -g \
  75. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  76. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  77. --new=3:$(UENV_START):$(UENV_END) --change-name=3:uboot-env --typecode=3:$(UBOOTENV) \
  78. --new=4:274432:0 --change-name=4:root --typecode=4:$(LINUX) \
  79. $(DISK)
  80. -$(PARTPROBE)
  81. @sleep 1
  82. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  83. @$(eval PART1 := $(DISK)p1)
  84. @$(eval PART2 := $(DISK)p2)
  85. @$(eval PART3 := $(DISK)p3)
  86. @$(eval PART4 := $(DISK)p4)
  87. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  88. @$(eval PART1 := $(DISK)s1)
  89. @$(eval PART2 := $(DISK)s2)
  90. @$(eval PART3 := $(DISK)s3)
  91. @$(eval PART4 := $(DISK)s4)
  92. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  93. @$(eval PART1 := $(DISK)1)
  94. @$(eval PART2 := $(DISK)2)
  95. @$(eval PART3 := $(DISK)3)
  96. @$(eval PART4 := $(DISK)4)
  97. else
  98. @echo Error: Could not find bootloader partition for $(DISK)
  99. @exit 1
  100. endif
  101. dd if=$(uboot) of=$(PART2) bs=4096
  102. dd if=$(vfat_image) of=$(PART1) bs=4096
  103. DEMO_IMAGE := sifive-debian-demo-mar7.tar.xz
  104. DEMO_URL := https://github.com/tmagik/freedom-u-sdk/releases/download/hifiveu-2.0-alpha.1/
  105. format-rootfs-image: format-boot-loader
  106. @echo "Done setting up basic initramfs boot. We will now try to install"
  107. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  108. @echo "you can safely cancel here"
  109. $(MKFS_EXT4) $(PART4)
  110. -mkdir -p tmp-mnt
  111. -mkdir -p tmp-rootfs
  112. -sudo mount $(PART4) tmp-mnt && \
  113. sudo mount -o loop $(buildroot_rootfs_ext) tmp-rootfs&& \
  114. sudo cp -fr tmp-rootfs/* tmp-mnt/
  115. sudo umount tmp-mnt
  116. sudo umount tmp-rootfs
  117. format-demo-image: format-boot-loader
  118. @echo "Done setting up basic initramfs boot. We will now try to install"
  119. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  120. @echo "you can safely cancel here"
  121. $(MKFS_EXT4) $(PART4)
  122. -mkdir tmp-mnt
  123. -sudo mount $(PART4) tmp-mnt && cd tmp-mnt && \
  124. sudo wget $(DEMO_URL)$(DEMO_IMAGE) && \
  125. sudo tar -xvpf $(DEMO_IMAGE)
  126. sudo umount tmp-mnt
  127. # default size: 16GB
  128. DISK_IMAGE_SIZE ?= 16
  129. ROOT_BEGIN=272384
  130. ROOT_CLUSTER_NUM=$(shell echo $$(($(DISK_IMAGE_SIZE)*1024*1024*1024/512)))
  131. ROOT_END=$(shell echo $$(($(ROOT_BEGIN)+$(ROOT_CLUSTER_NUM))))
  132. format-nvdla-disk: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
  133. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  134. sudo $(SGDISK) --clear -g \
  135. --new=1:$(VFAT_START):$(VFAT_END) --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  136. --new=2:$(UBOOT_START):$(UBOOT_END) --change-name=2:uboot --typecode=2:$(UBOOT) \
  137. --new=3:$(ROOT_BEGIN):0 --change-name=3:root --typecode=3:$(LINUX) \
  138. $(DISK)
  139. -$(PARTPROBE)
  140. @sleep 3
  141. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  142. @$(eval PART1 := $(DISK)p1)
  143. @$(eval PART2 := $(DISK)p2)
  144. @$(eval PART3 := $(DISK)p3)
  145. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  146. @$(eval PART1 := $(DISK)s1)
  147. @$(eval PART2 := $(DISK)s2)
  148. @$(eval PART3 := $(DISK)s3)
  149. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  150. @$(eval PART1 := $(DISK)1)
  151. @$(eval PART2 := $(DISK)2)
  152. @$(eval PART3 := $(DISK)3)
  153. else
  154. @echo Error: Could not find bootloader partition for $(DISK)
  155. @exit 1
  156. endif
  157. sudo dd if=$(uboot) of=$(PART2) bs=4096
  158. sudo dd if=$(vfat_image) of=$(PART1) bs=4096
  159. #usb config
  160. format-usb-disk: sbi $(uboot) $(fit) $(vfat_image)
  161. @test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
  162. sudo $(SGDISK) --clear -g \
  163. --new=1:0:+256M --change-name=1:"Vfat Boot" --typecode=1:$(VFAT) \
  164. --new=2:0:+1G --change-name=2:uboot --typecode=2:$(UBOOT) -g\
  165. $(DISK)
  166. -$(PARTPROBE)
  167. @sleep 3
  168. ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
  169. @$(eval PART1 := $(DISK)p1)
  170. @$(eval PART2 := $(DISK)p2)
  171. # @$(eval PART3 := $(DISK)p3)
  172. else ifeq ($(DISK)s1,$(wildcard $(DISK)s1))
  173. @$(eval PART1 := $(DISK)s1)
  174. @$(eval PART2 := $(DISK)s2)
  175. # @$(eval PART3 := $(DISK)s3)
  176. else ifeq ($(DISK)1,$(wildcard $(DISK)1))
  177. @$(eval PART1 := $(DISK)1)
  178. @$(eval PART2 := $(DISK)2)
  179. # @$(eval PART3 := $(DISK)3)
  180. else
  181. @echo Error: Could not find bootloader partition for $(DISK)
  182. @exit 1
  183. endif
  184. sudo dd if=$(uboot) of=$(PART2) bs=4096
  185. sudo dd if=$(vfat_image) of=$(PART1) bs=4096
  186. DEB_IMAGE := debian_nvdla_20190506.tar.xz
  187. DEB_URL := https://github.com/sifive/freedom-u-sdk/releases/download/nvdla-demo-0.1
  188. format-nvdla-rootfs: format-nvdla-disk
  189. @echo "Done setting up basic initramfs boot. We will now try to install"
  190. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  191. @echo "you can safely cancel here"
  192. sudo $(MKFS_EXT4) -F $(PART3)
  193. -mkdir -p tmp-mnt
  194. -mkdir -p tmp-rootfs
  195. -sudo mount $(PART3) tmp-mnt && \
  196. sudo mount -o loop $(buildroot_rootfs_ext) tmp-rootfs&& \
  197. sudo cp -fr tmp-rootfs/* tmp-mnt/
  198. sudo umount tmp-mnt
  199. sudo umount tmp-rootfs
  200. format-nvdla-root: format-nvdla-disk
  201. @echo "Done setting up basic initramfs boot. We will now try to install"
  202. @echo "a Debian snapshot to the Linux partition, which requires sudo"
  203. @echo "you can safely cancel here"
  204. @test -e $(wrkdir)/$(DEB_IMAGE) || (wget -P $(wrkdir) $(DEB_URL)/$(DEB_IMAGE))
  205. sudo $(MKFS_EXT4) $(PART3)
  206. -mkdir -p tmp-mnt
  207. -sudo mount $(PART3) tmp-mnt && \
  208. echo "please wait until checkpoint reaches 489k" && \
  209. sudo tar xpf $(wrkdir)/$(DEB_IMAGE) -C tmp-mnt --checkpoint=1000
  210. sudo umount tmp-mnt