Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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@#$(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. # Some info about Ctera firmware:
  49. # 1. It's simple tar file (GNU standard), but it must have ".firm" suffix.
  50. # 2. It contains two images: kernel and romdisk. Both are required.
  51. # 3. Every image has header and trailer file.
  52. # 4. The struct of tar firmware is: header kernel trailer header romdisk trailer
  53. # 5. In header file are some strings used to describe image. It was decoded from
  54. # factory image.
  55. # 6. Version format in header file is restricted by Original FW.
  56. # 7. Trailer file contains MD5 sum string of header and image file.
  57. # 8. Firmware file must have <=24MB size.
  58. define Build/ctera-firmware
  59. mkdir -p [email protected]
  60. # Prepare header and trailer file for kernel
  61. echo "# CTera firmware information file" > [email protected]/header
  62. echo "image_type=kernel" >> [email protected]/header
  63. echo "arch=ARM" >> [email protected]/header
  64. echo "board=2Drive_A" >> [email protected]/header
  65. echo "version=5.5.165.61499" >> [email protected]/header
  66. echo "kernel_cmd=console=ttyS0,115200 earlycon" >> [email protected]/header
  67. echo "date=$$(date $(if $(SOURCE_DATE_EPOCH),-d@$(SOURCE_DATE_EPOCH)))" \
  68. >> [email protected]/header
  69. cp $@ [email protected]/kernel
  70. echo "MD5=$$(cat [email protected]/header [email protected]/kernel | $(MKHASH) md5)" \
  71. > [email protected]/trailer
  72. tar $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  73. -H gnu -C [email protected] -cf [email protected] header kernel trailer
  74. # Prepare header and trailer file for fake romdisk
  75. echo "# CTera firmware information file" > [email protected]/header
  76. echo "image_type=romdisk" >> [email protected]/header
  77. echo "initrd=yes" >> [email protected]/header
  78. echo "arch=ARM" >> [email protected]/header
  79. echo "board=2Drive_A" >> [email protected]/header
  80. echo "version=5.5.165.61499" >> [email protected]/header
  81. echo "date=$$(date $(if $(SOURCE_DATE_EPOCH),-d@$(SOURCE_DATE_EPOCH)))" \
  82. >> [email protected]/header
  83. rm -f $@
  84. touch $@
  85. $(call Build/append-uImage-fakehdr, ramdisk)
  86. cp $@ [email protected]/romdisk
  87. echo "MD5=$$(cat [email protected]/header [email protected]/romdisk | $(MKHASH) md5)" \
  88. > [email protected]/trailer
  89. tar $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  90. -H gnu -C [email protected] -rf [email protected] header romdisk trailer
  91. mv [email protected] $@
  92. rm -rf [email protected]
  93. endef
  94. define Build/sdcard-img
  95. SIGNATURE="$(IMG_PART_SIGNATURE)" \
  96. ./gen_mvebu_sdcard_img.sh $@ \
  97. $(if $(UBOOT),$(STAGING_DIR_IMAGE)/$(UBOOT)) \
  98. c $(CONFIG_TARGET_KERNEL_PARTSIZE) [email protected] \
  99. 83 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS)
  100. endef
  101. define Build/sdcard-img-ext4
  102. SIGNATURE="$(IMG_PART_SIGNATURE)" \
  103. ./gen_mvebu_sdcard_img.sh $@ \
  104. $(if $(UBOOT),$(STAGING_DIR_IMAGE)/$(UBOOT)) \
  105. 83 $(CONFIG_TARGET_KERNEL_PARTSIZE) [email protected] \
  106. 83 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS)
  107. endef
  108. define Build/omnia-medkit-initramfs
  109. $(TAR) -c -T /dev/null -f $@
  110. rm -rf $(dir $(IMAGE_KERNEL))boot
  111. mkdir -p $(dir $(IMAGE_KERNEL))boot/boot/
  112. cp $(KDIR)/zImage-initramfs $(dir $(IMAGE_KERNEL))boot/boot/zImage
  113. cp $(KDIR)/image-$(DEVICE_DTS).dtb $(dir $(IMAGE_KERNEL))boot/boot/dtb
  114. $(TAR) -rp --numeric-owner --owner=0 --group=0 --sort=name \
  115. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  116. --file=$@ -C $(dir $(IMAGE_KERNEL))boot/ .
  117. endef
  118. define Build/uDPU-firmware
  119. (rm -fR $@-fw; mkdir -p $@-fw)
  120. $(CP) $(BIN_DIR)/$(DEVICE_IMG_PREFIX)-initramfs.itb $@-fw/recovery.itb
  121. $(CP) [email protected] $@-fw/boot.scr
  122. $(TAR) -cvzp --numeric-owner --owner=0 --group=0 --sort=name \
  123. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  124. -f $@-fw/rootfs.tgz -C $(TARGET_DIR) .
  125. $(TAR) -cvzp --numeric-owner --owner=0 --group=0 --sort=name \
  126. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  127. -f $@-fw/boot.tgz -C [email protected] .
  128. $(TAR) -cvzp --numeric-owner --owner=0 --group=0 --sort=name \
  129. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  130. -f $(KDIR_TMP)/$(DEVICE_IMG_PREFIX)-firmware.tgz -C $@-fw .
  131. endef
  132. define Device/Default
  133. PROFILES := Default
  134. DEVICE_DTS = $$(SOC)-$(lastword $(subst _, ,$(1)))
  135. DEVICE_DTS_DIR := $(DTS_DIR)
  136. BOARD_NAME = $$(DEVICE_DTS)
  137. KERNEL_NAME := zImage
  138. KERNEL := kernel-bin | append-dtb | uImage none
  139. IMAGES := sysupgrade.bin
  140. IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  141. UBINIZE_OPTS := -E 5
  142. UBOOT :=
  143. BOOT_SCRIPT :=
  144. endef
  145. define Device/Default-arm64
  146. BOOT_SCRIPT := generic-arm64
  147. DEVICE_DTS_DIR := $(DTS_DIR)/marvell
  148. IMAGES := sdcard.img.gz
  149. IMAGE/sdcard.img.gz := boot-scr | boot-img-ext4 | sdcard-img-ext4 | gzip | append-metadata
  150. KERNEL_NAME := Image
  151. KERNEL := kernel-bin
  152. endef
  153. define Device/NAND-128K
  154. BLOCKSIZE := 128k
  155. PAGESIZE := 2048
  156. SUBPAGESIZE := 512
  157. VID_HDR_OFFSET := 2048
  158. endef
  159. define Device/NAND-256K
  160. BLOCKSIZE := 256k
  161. PAGESIZE := 4096
  162. endef
  163. define Device/NAND-512K
  164. BLOCKSIZE := 512k
  165. PAGESIZE := 4096
  166. endef
  167. include $(SUBTARGET).mk
  168. $(eval $(call BuildImage))