Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2012-2016 OpenWrt.org
  4. # Copyright (C) 2016 LEDE-project.org
  5. JFFS2_BLOCKSIZE = 128k
  6. include $(TOPDIR)/rules.mk
  7. include $(INCLUDE_DIR)/image.mk
  8. DEVICE_VARS += BOOT_SCRIPT UBOOT
  9. KERNEL_LOADADDR := 0x00008000
  10. define Build/boot-scr
  11. rm -f [email protected]
  12. sed \
  13. -e 's#@ROOT@#$(if $(1),$(1),$(IMG_PART_SIGNATURE))#g' \
  14. -e 's#@DTB@#$(firstword $(DEVICE_DTS))#g' \
  15. $(BOOT_SCRIPT).bootscript > [email protected]
  16. mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d [email protected] [email protected]
  17. endef
  18. define Build/boot-img
  19. rm -f [email protected]
  20. mkfs.fat -C [email protected] $$(( $(CONFIG_TARGET_KERNEL_PARTSIZE) * 1024 ))
  21. $(foreach dts,$(DEVICE_DTS), mcopy -i [email protected] $(KDIR)/image-$(dts).dtb ::$(dts).dtb;)
  22. mcopy -i [email protected] $(IMAGE_KERNEL) ::$(KERNEL_NAME)
  23. -mcopy -i [email protected] [email protected] ::boot.scr
  24. endef
  25. define Build/boot-img-ext4
  26. rm -fR [email protected]
  27. mkdir -p [email protected]
  28. $(foreach dts,$(DEVICE_DTS), $(CP) $(KDIR)/image-$(dts).dtb [email protected]/$(dts).dtb;)
  29. $(CP) $(IMAGE_KERNEL) [email protected]/$(KERNEL_NAME)
  30. -$(CP) [email protected] [email protected]/boot.scr
  31. make_ext4fs -J -L kernel -l $(CONFIG_TARGET_KERNEL_PARTSIZE)M \
  32. $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
  33. [email protected] [email protected]
  34. endef
  35. define Build/buffalo-kernel-jffs2
  36. rm -rf $(KDIR)/kernel_jffs2 [email protected]
  37. mkdir -p $(KDIR)/kernel_jffs2
  38. dd if=/dev/zero [email protected] bs=131008 count=1 conv=sync
  39. $(STAGING_DIR_HOST)/bin/mkimage \
  40. -T ramdisk -A $(LINUX_KARCH) -O linux -C gzip -n 'fake initrd' \
  41. -d [email protected] $(KDIR)/kernel_jffs2/initrd.buffalo
  42. cp $@ $(KDIR)/kernel_jffs2/uImage.buffalo
  43. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
  44. --little-endian -v --squash-uids -q -f -n -x lzma -x rtime -m none \
  45. --eraseblock=128KiB --pad=$(KERNEL_SIZE) -d $(KDIR)/kernel_jffs2 -o $@
  46. rm -rf $(KDIR)/kernel_jffs2 [email protected]
  47. endef
  48. define Build/buffalo-kernel-ubifs
  49. rm -rf $@-ubidir
  50. mkdir -p $@-ubidir
  51. mv $@ $@-ubidir/uImage.buffalo
  52. touch $@
  53. $(call Build/append-uImage-fakehdr, ramdisk)
  54. mv $@ $@-ubidir/initrd.buffalo
  55. $(STAGING_DIR_HOST)/bin/mkfs.ubifs $(KERNEL_UBIFS_OPTS) -r $@-ubidir $@
  56. endef
  57. # Some info about Ctera firmware:
  58. # 1. It's simple tar file (GNU standard), but it must have ".firm" suffix.
  59. # 2. It contains two images: kernel and romdisk. Both are required.
  60. # 3. Every image has header and trailer file.
  61. # 4. The struct of tar firmware is: header kernel trailer header romdisk trailer
  62. # 5. In header file are some strings used to describe image. It was decoded from
  63. # factory image.
  64. # 6. Version format in header file is restricted by Original FW.
  65. # 7. Trailer file contains MD5 sum string of header and image file.
  66. # 8. Firmware file must have <=24MB size.
  67. define Build/ctera-firmware
  68. mkdir -p [email protected]
  69. # Prepare header and trailer file for kernel
  70. echo "# CTera firmware information file" > [email protected]/header
  71. echo "image_type=kernel" >> [email protected]/header
  72. echo "arch=ARM" >> [email protected]/header
  73. echo "board=2Drive_A" >> [email protected]/header
  74. echo "version=5.5.165.61499" >> [email protected]/header
  75. echo "kernel_cmd=console=ttyS0,115200 earlycon" >> [email protected]/header
  76. echo "date=$$(date $(if $(SOURCE_DATE_EPOCH),-d@$(SOURCE_DATE_EPOCH)))" \
  77. >> [email protected]/header
  78. cp $@ [email protected]/kernel
  79. echo "MD5=$$(cat [email protected]/header [email protected]/kernel | $(MKHASH) md5)" \
  80. > [email protected]/trailer
  81. tar $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  82. -H gnu -C [email protected] -cf [email protected] header kernel trailer
  83. # Prepare header and trailer file for fake romdisk
  84. echo "# CTera firmware information file" > [email protected]/header
  85. echo "image_type=romdisk" >> [email protected]/header
  86. echo "initrd=yes" >> [email protected]/header
  87. echo "arch=ARM" >> [email protected]/header
  88. echo "board=2Drive_A" >> [email protected]/header
  89. echo "version=5.5.165.61499" >> [email protected]/header
  90. echo "date=$$(date $(if $(SOURCE_DATE_EPOCH),-d@$(SOURCE_DATE_EPOCH)))" \
  91. >> [email protected]/header
  92. rm -f $@
  93. touch $@
  94. $(call Build/append-uImage-fakehdr, ramdisk)
  95. cp $@ [email protected]/romdisk
  96. echo "MD5=$$(cat [email protected]/header [email protected]/romdisk | $(MKHASH) md5)" \
  97. > [email protected]/trailer
  98. tar $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  99. -H gnu -C [email protected] -rf [email protected] header romdisk trailer
  100. mv [email protected] $@
  101. rm -rf [email protected]
  102. endef
  103. define Build/sdcard-img
  104. SIGNATURE="$(IMG_PART_SIGNATURE)" \
  105. ./gen_mvebu_sdcard_img.sh $@ \
  106. $(if $(UBOOT),$(STAGING_DIR_IMAGE)/$(UBOOT)) \
  107. c $(CONFIG_TARGET_KERNEL_PARTSIZE) [email protected] \
  108. 83 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS)
  109. endef
  110. define Build/sdcard-img-ext4
  111. SIGNATURE="$(IMG_PART_SIGNATURE)" \
  112. ./gen_mvebu_sdcard_img.sh $@ \
  113. $(if $(UBOOT),$(STAGING_DIR_IMAGE)/$(UBOOT)) \
  114. 83 $(CONFIG_TARGET_KERNEL_PARTSIZE) [email protected] \
  115. 83 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS)
  116. endef
  117. define Build/uDPU-firmware
  118. (rm -fR $@-fw; mkdir -p $@-fw)
  119. $(CP) $(BIN_DIR)/$(DEVICE_IMG_PREFIX)-initramfs.itb $@-fw/recovery.itb
  120. $(CP) [email protected] $@-fw/boot.scr
  121. $(TAR) -cvzp --numeric-owner --owner=0 --group=0 --sort=name \
  122. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  123. -f $@-fw/rootfs.tgz -C $(TARGET_DIR) .
  124. $(TAR) -cvzp --numeric-owner --owner=0 --group=0 --sort=name \
  125. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  126. -f $@-fw/boot.tgz -C [email protected] .
  127. $(TAR) -cvzp --numeric-owner --owner=0 --group=0 --sort=name \
  128. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  129. -f $(KDIR_TMP)/$(DEVICE_IMG_PREFIX)-firmware.tgz -C $@-fw .
  130. endef
  131. define Device/Default
  132. PROFILES := Default
  133. DEVICE_DTS = $$(SOC)-$(lastword $(subst _, ,$(1)))
  134. DEVICE_DTS_DIR := $(DTS_DIR)
  135. BOARD_NAME = $$(DEVICE_DTS)
  136. KERNEL_NAME := zImage
  137. KERNEL := kernel-bin | append-dtb | uImage none
  138. IMAGES := sysupgrade.bin
  139. IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  140. UBINIZE_OPTS := -E 5
  141. UBOOT :=
  142. BOOT_SCRIPT :=
  143. endef
  144. define Device/Default-arm64
  145. BOOT_SCRIPT := generic-arm64
  146. DEVICE_DTS_DIR := $(DTS_DIR)/marvell
  147. IMAGES := sdcard.img.gz
  148. IMAGE/sdcard.img.gz := boot-scr | boot-img-ext4 | sdcard-img-ext4 | gzip | append-metadata
  149. KERNEL_NAME := Image
  150. KERNEL := kernel-bin
  151. endef
  152. define Device/NAND-128K
  153. BLOCKSIZE := 128k
  154. PAGESIZE := 2048
  155. SUBPAGESIZE := 512
  156. VID_HDR_OFFSET := 2048
  157. endef
  158. define Device/NAND-256K
  159. BLOCKSIZE := 256k
  160. PAGESIZE := 4096
  161. endef
  162. define Device/NAND-512K
  163. BLOCKSIZE := 512k
  164. PAGESIZE := 4096
  165. endef
  166. include $(SUBTARGET).mk
  167. $(eval $(call BuildImage))