common-sercomm.mk 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. DEVICE_VARS += SERCOMM_KERNEL_OFFSET SERCOMM_ROOTFS_OFFSET
  2. DEVICE_VARS += SERCOMM_KERNEL2_OFFSET SERCOMM_ROOTFS2_OFFSET
  3. define Build/sercomm-append-tail
  4. printf 16 | dd seek=$$((0x90)) of=$@ bs=1 conv=notrunc 2>/dev/null
  5. printf 11223344556677889900112233445566 | \
  6. sed 's/../\\x&/g' | xargs -d . printf >> $@
  7. endef
  8. define Build/sercomm-crypto
  9. $(TOPDIR)/scripts/sercomm-crypto.py \
  10. --input-file $@ \
  11. --key-file [email protected] \
  12. --output-file [email protected] \
  13. --version $(SERCOMM_SWVER)
  14. $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
  15. -in $@ \
  16. -out [email protected] \
  17. -K `cat [email protected]` \
  18. -iv 00000000000000000000000000000000
  19. dd [email protected] >> [email protected] 2>/dev/null
  20. mv [email protected] $@
  21. rm -f [email protected] [email protected]
  22. endef
  23. define Build/sercomm-factory-cpj
  24. dd bs=$$((0x1fff00)) count=1 if=$@ [email protected] conv=notrunc \
  25. 2>/dev/null
  26. dd bs=$$((0x1fff00)) skip=1 if=$@ [email protected] conv=notrunc \
  27. 2>/dev/null
  28. cp [email protected] [email protected]
  29. $(TOPDIR)/scripts/sercomm-kernel-header.py \
  30. --kernel-image [email protected] \
  31. --kernel-offset $(SERCOMM_KERNEL_OFFSET) \
  32. --rootfs-image [email protected] \
  33. --rootfs-offset $(SERCOMM_ROOTFS_OFFSET) \
  34. --output-header [email protected]
  35. $(TOPDIR)/scripts/sercomm-kernel-header.py \
  36. --kernel-image [email protected] \
  37. --kernel-offset $(SERCOMM_KERNEL2_OFFSET) \
  38. --rootfs-image [email protected] \
  39. --rootfs-offset $(SERCOMM_ROOTFS2_OFFSET) \
  40. --output-header [email protected]
  41. cat [email protected] [email protected] > [email protected]
  42. cat [email protected] [email protected] > [email protected]
  43. rm [email protected] [email protected] [email protected]
  44. $(call Build/sercomm-part-tag-common,kernel [email protected])
  45. $(call Build/sercomm-part-tag-common,kernel2 [email protected])
  46. $(call Build/sercomm-part-tag-common,rootfs [email protected])
  47. $(call Build/sercomm-part-tag-common,rootfs2 [email protected])
  48. cat [email protected] [email protected] [email protected] [email protected] > $@
  49. rm [email protected] [email protected] [email protected] [email protected]
  50. endef
  51. define Build/sercomm-factory-cqr
  52. $(TOPDIR)/scripts/sercomm-pid.py \
  53. --hw-version $(SERCOMM_HWVER) \
  54. --hw-id $(SERCOMM_HWID) \
  55. --sw-version $(SERCOMM_SWVER) \
  56. --pid-file [email protected] \
  57. --extra-padding-size 0x190
  58. printf $$(stat -c%s $(IMAGE_KERNEL)) | \
  59. dd seek=$$((0x70)) [email protected] bs=1 conv=notrunc 2>/dev/null
  60. printf $$(($$(stat -c%s $@)-$$(stat -c%s $(IMAGE_KERNEL))-$$((0x200)))) | \
  61. dd seek=$$((0x80)) [email protected] bs=1 conv=notrunc 2>/dev/null
  62. dd if=$@ >> [email protected] 2>/dev/null
  63. mv [email protected] $@
  64. endef
  65. define Build/sercomm-kernel
  66. $(TOPDIR)/scripts/sercomm-kernel-header.py \
  67. --kernel-image $@ \
  68. --kernel-offset $(SERCOMM_KERNEL_OFFSET) \
  69. --rootfs-offset $(SERCOMM_ROOTFS_OFFSET) \
  70. --output-header [email protected]
  71. dd if=$@ >> [email protected] 2>/dev/null
  72. mv [email protected] $@
  73. endef
  74. define Build/sercomm-kernel-factory
  75. $(TOPDIR)/scripts/sercomm-kernel-header.py \
  76. --kernel-image $@ \
  77. --kernel-offset $(SERCOMM_KERNEL_OFFSET) \
  78. --rootfs-offset $(SERCOMM_ROOTFS_OFFSET) \
  79. --output-header [email protected]
  80. $(TOPDIR)/scripts/sercomm-kernel-header.py \
  81. --kernel-image $@ \
  82. --kernel-offset $(SERCOMM_KERNEL2_OFFSET) \
  83. --rootfs-offset $(SERCOMM_ROOTFS2_OFFSET) \
  84. --output-header [email protected]
  85. cat [email protected] [email protected] > [email protected]
  86. dd if=$@ >> [email protected] 2>/dev/null
  87. mv [email protected] $@
  88. endef
  89. define Build/sercomm-mkhash
  90. dd bs=$$((0x400)) skip=1 if=$@ conv=notrunc 2>/dev/null | \
  91. $(MKHASH) md5 | awk '{print $$1}' | tr -d '\n' | \
  92. dd seek=$$((0x1e0)) of=$@ bs=1 conv=notrunc 2>/dev/null
  93. endef
  94. define Build/sercomm-part-tag
  95. $(call Build/sercomm-part-tag-common,$(word 1,$(1)) $@)
  96. endef
  97. define Build/sercomm-part-tag-common
  98. $(eval file=$(word 2,$(1)))
  99. $(TOPDIR)/scripts/sercomm-partition-tag.py \
  100. --input-file $(file) \
  101. --output-file $(file).tmp \
  102. --part-name $(word 1,$(1)) \
  103. --part-version $(SERCOMM_SWVER)
  104. mv $(file).tmp $(file)
  105. endef
  106. define Build/sercomm-payload
  107. $(TOPDIR)/scripts/sercomm-pid.py \
  108. --hw-version $(SERCOMM_HWVER) \
  109. --hw-id $(SERCOMM_HWID) \
  110. --sw-version $(SERCOMM_SWVER) \
  111. --pid-file [email protected] \
  112. --extra-padding-size 0x10 \
  113. --extra-padding-first-byte 0x0a
  114. $(TOPDIR)/scripts/sercomm-payload.py \
  115. --input-file $@ \
  116. --output-file [email protected] \
  117. --pid-file [email protected]
  118. mv [email protected] $@
  119. rm [email protected]
  120. endef
  121. define Build/sercomm-pid-setbit
  122. printf 1 | dd seek=$$(($(1))) of=$@ bs=1 conv=notrunc 2>/dev/null
  123. endef
  124. define Build/sercomm-prepend-tagged-kernel
  125. $(CP) $(IMAGE_KERNEL) $(IMAGE_KERNEL).tagged
  126. $(call Build/sercomm-part-tag-common,$(word 1,$(1)) \
  127. $(IMAGE_KERNEL).tagged)
  128. dd if=$@ >> $(IMAGE_KERNEL).tagged 2>/dev/null
  129. mv $(IMAGE_KERNEL).tagged $@
  130. endef
  131. define Build/sercomm-reset-slot1-chksum
  132. printf "\xff\xff\xff\xff" | \
  133. dd of=$@ seek=$$((0x118)) bs=1 conv=notrunc 2>/dev/null
  134. endef
  135. define Build/sercomm-sysupgrade-cpj
  136. dd bs=$$((0x1fff00)) count=1 if=$@ [email protected] conv=notrunc \
  137. 2>/dev/null
  138. dd bs=$$((0x1fff00)) skip=1 if=$@ [email protected] conv=notrunc \
  139. 2>/dev/null
  140. $(TOPDIR)/scripts/sercomm-kernel-header.py \
  141. --kernel-image [email protected] \
  142. --kernel-offset $(SERCOMM_KERNEL_OFFSET) \
  143. --rootfs-image [email protected] \
  144. --rootfs-offset $(SERCOMM_ROOTFS_OFFSET) \
  145. --output-header [email protected]
  146. cat [email protected] [email protected] [email protected] > $@
  147. rm [email protected] [email protected] [email protected]
  148. endef
  149. define Device/sercomm
  150. $(Device/nand)
  151. LOADER_TYPE := bin
  152. IMAGES += factory.img
  153. endef
  154. define Device/sercomm_cpj
  155. SOC := mt7620a
  156. DEVICE_VENDOR := Rostelecom
  157. DEVICE_ALT0_VENDOR := Sercomm
  158. IMAGE_SIZE := 7743k
  159. SERCOMM_HWID := CPJ
  160. SERCOMM_HWVER := 10000
  161. SERCOMM_SWVER := 1001
  162. SERCOMM_KERNEL_OFFSET := 0x70100
  163. SERCOMM_ROOTFS_OFFSET := 0x270000
  164. SERCOMM_KERNEL2_OFFSET := 0x800100
  165. SERCOMM_ROOTFS2_OFFSET := 0xa00000
  166. IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
  167. sercomm-sysupgrade-cpj | pad-rootfs | check-size | \
  168. append-metadata
  169. ARTIFACTS := initramfs-factory.img
  170. DEVICE_PACKAGES := kmod-mt76x2
  171. endef
  172. define Device/sercomm_cxx_dxx
  173. $(Device/sercomm)
  174. KERNEL_SIZE := 6144k
  175. KERNEL_LOADADDR := 0x81001000
  176. LZMA_TEXT_START := 0x82800000
  177. SERCOMM_KERNEL_OFFSET := 0x400100
  178. SERCOMM_ROOTFS_OFFSET := 0x1000000
  179. endef
  180. define Device/sercomm_cxx
  181. $(Device/sercomm_cxx_dxx)
  182. SERCOMM_KERNEL2_OFFSET := 0xa00100
  183. SERCOMM_ROOTFS2_OFFSET := 0x3000000
  184. KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | lzma -a0 | \
  185. uImage lzma
  186. IMAGE/sysupgrade.bin := append-kernel | sercomm-kernel | \
  187. sysupgrade-tar kernel=$$$$@ | append-metadata
  188. IMAGE/factory.img := append-kernel | sercomm-kernel-factory | \
  189. append-ubi | sercomm-factory-cqr | sercomm-mkhash
  190. endef
  191. define Device/sercomm_dxx
  192. $(Device/sercomm_cxx_dxx)
  193. KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | lzma -a0 | \
  194. uImage lzma | sercomm-kernel
  195. KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel | \
  196. lzma -a0 | uImage lzma
  197. IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  198. IMAGE/factory.img := append-ubi | check-size | \
  199. sercomm-part-tag rootfs | sercomm-prepend-tagged-kernel kernel | \
  200. gzip | sercomm-payload | sercomm-crypto
  201. endef
  202. define Device/sercomm_s1500
  203. $(Device/sercomm)
  204. SERCOMM_KERNEL_OFFSET := 0x1700100
  205. SERCOMM_ROOTFS_OFFSET := 0x1f00000
  206. SERCOMM_KERNEL2_OFFSET := 0x1b00100
  207. KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | lzma -a0 | \
  208. uImage lzma
  209. KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel | \
  210. lzma -a0 | uImage lzma
  211. IMAGE/sysupgrade.bin := append-kernel | sercomm-kernel | \
  212. sysupgrade-tar kernel=$$$$@ | append-metadata
  213. DEVICE_PACKAGES := kmod-mt76x2 kmod-usb3
  214. endef