imagebuilder.patch 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. --- a/include/image.mk
  2. +++ b/include/image.mk
  3. @@ -717,7 +717,7 @@ define Device/Build/kernel
  4. endef
  5. define Device/Build/image
  6. - GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
  7. + GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(findstring img,$(2)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
  8. $$(_TARGET): $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
  9. $(BUILD_DIR)/json_info_files/$(call DEVICE_IMG_NAME,$(1),$(2)).json, \
  10. $(BIN_DIR)/$(call DEVICE_IMG_NAME,$(1),$(2))$$(GZ_SUFFIX))
  11. @@ -755,6 +755,7 @@ define Device/Build/image
  12. FILE_TYPE=$(word 1,$(subst ., ,$(2))) \
  13. FILE_FILESYSTEM="$(1)" \
  14. DEVICE_IMG_PREFIX="$(DEVICE_IMG_PREFIX)" \
  15. + IMAGE_SIZE="$(shell echo $$(($(call exp_units,$(IMAGE_SIZE)))))" \
  16. DEVICE_VENDOR="$(DEVICE_VENDOR)" \
  17. DEVICE_MODEL="$(DEVICE_MODEL)" \
  18. DEVICE_VARIANT="$(DEVICE_VARIANT)" \
  19. @@ -861,6 +862,7 @@ define Device/DumpInfo
  20. Target-Profile: DEVICE_$(1)
  21. Target-Profile-Name: $(DEVICE_DISPLAY)
  22. Target-Profile-Packages: $(DEVICE_PACKAGES)
  23. +Target-Profile-ImageSize: $(shell echo $$(( $(call exp_units,$(IMAGE_SIZE)) / 1024 )))
  24. Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
  25. Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
  26. $(if $(BROKEN),Target-Profile-Broken: $(BROKEN))
  27. --- a/scripts/json_add_image_info.py
  28. +++ b/scripts/json_add_image_info.py
  29. @@ -72,6 +72,7 @@ def get_titles():
  30. "device_packages": getenv("DEVICE_PACKAGES").split(),
  31. "supported_devices": getenv("SUPPORTED_DEVICES").split(),
  32. "titles": get_titles(),
  33. + "image_size": getenv("IMAGE_SIZE"),
  34. }
  35. },
  36. }
  37. --- a/scripts/target-metadata.pl
  38. +++ b/scripts/target-metadata.pl
  39. @@ -437,6 +437,7 @@ ()
  40. print "PROFILE_NAMES = ".join(" ", @profile_ids_unique)."\n";
  41. foreach my $profile (@{$cur->{profiles}}) {
  42. print $profile->{id}.'_NAME:='.$profile->{name}."\n";
  43. + print $profile->{id}.'_IMAGE_SIZE:='.$profile->{image_size}."\n";
  44. print $profile->{id}.'_HAS_IMAGE_METADATA:='.$profile->{has_image_metadata}."\n";
  45. if (defined($profile->{supported_devices}) and @{$profile->{supported_devices}} > 0) {
  46. print $profile->{id}.'_SUPPORTED_DEVICES:='.join(' ', @{$profile->{supported_devices}})."\n";
  47. --- a/scripts/metadata.pm
  48. +++ b/scripts/metadata.pm
  49. @@ -150,6 +150,7 @@ sub parse_target_metadata($) {
  50. push @{$target->{profiles}}, $profile;
  51. };
  52. /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
  53. + /^Target-Profile-ImageSize:\s*(.*)\s*/ and $profile->{image_size} = $1;
  54. /^Target-Profile-hasImageMetadata:\s*(\d+)\s*$/ and $profile->{has_image_metadata} = $1;
  55. /^Target-Profile-SupportedDevices:\s*(.+)\s*$/ and $profile->{supported_devices} = [ split(/\s+/, $1) ];
  56. /^Target-Profile-Priority:\s*(\d+)\s*$/ and do {
  57. --- a/target/imagebuilder/Makefile
  58. +++ b/target/imagebuilder/Makefile
  59. @@ -39,7 +39,8 @@ $(BIN_DIR)/$(IB_NAME).tar.zst: clean
  60. ./files/Makefile \
  61. $(TMP_DIR)/.targetinfo \
  62. $(TMP_DIR)/.packageinfo \
  63. - $(PKG_BUILD_DIR)/
  64. + $(TOPDIR)/files \
  65. + $(PKG_BUILD_DIR)/ || true
  66. $(INSTALL_DIR) $(PKG_BUILD_DIR)/packages
  67. @@ -52,12 +53,13 @@ ifneq ($(CONFIG_USE_APK),)
  68. $(INSTALL_DATA) ./files/README.apk.md $(PKG_BUILD_DIR)/packages/README.md
  69. else
  70. - ifeq ($(CONFIG_IB_STANDALONE),)
  71. echo '## Remote package repositories' >> $(PKG_BUILD_DIR)/repositories.conf
  72. $(call FeedSourcesAppendOPKG,$(PKG_BUILD_DIR)/repositories.conf)
  73. $(VERSION_SED_SCRIPT) $(PKG_BUILD_DIR)/repositories.conf
  74. - endif
  75. + $(SED) 's/^src\/gz \(.*\) https.*ai\/\(.*packages.*\)/src \1 file:\/\/www\/wwwroot\/dl.openwrt.ai\/\2/' $(PKG_BUILD_DIR)/repositories.conf
  76. + $(SED) 's/^src\/gz \(.*\) https.*ai\/\(.*targets.*\)/src \1 file:\/\/www\/wwwroot\/dl.openwrt.ai\/\2/' $(PKG_BUILD_DIR)/repositories.conf
  77. + $(SED) '/openwrt_core/d' $(PKG_BUILD_DIR)/repositories.conf
  78. # create an empty package index so `opkg` doesn't report an error
  79. touch $(PKG_BUILD_DIR)/packages/Packages
  80. --- a/target/imagebuilder/files/Makefile
  81. +++ b/target/imagebuilder/files/Makefile
  82. @@ -148,6 +148,33 @@ BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
  83. # "-pkgname" in the package list means remove "pkgname" from the package list
  84. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  85. BUILD_PACKAGES:=$(USER_PACKAGES) $(BUILD_PACKAGES)
  86. +IMAGE_SIZE_VALUE := $($(USER_PROFILE)_IMAGE_SIZE)
  87. +ifdef IMAGE_SIZE_VALUE
  88. + ifeq ($(shell test $(IMAGE_SIZE_VALUE) -le 35840 && echo true),true)
  89. + SMALL_FLASH := true
  90. + endif
  91. + ifeq ($(shell test $(IMAGE_SIZE_VALUE) -le 20480 && echo true),true)
  92. + XSMALL_FLASH := true
  93. + endif
  94. +endif
  95. +ifneq ($(findstring usb,$(BUILD_PACKAGES)),)
  96. + ifneq ($(XSMALL_FLASH),true)
  97. + BUILD_PACKAGES += automount luci-app-diskman
  98. + endif
  99. +endif
  100. +ifeq ($(SMALL_FLASH),true)
  101. + ifeq ($(shell grep -q small_flash $(TOPDIR)/repositories.conf || echo "not_found"),not_found)
  102. + $(shell echo "`grep kwrt_kiddin9 $(TOPDIR)/repositories.conf | sed -e 's/kiddin9/small_flash/g'`" >>$(TOPDIR)/repositories.conf)
  103. + endif
  104. + ifneq ($(findstring /data/bcache/,$(BIN_DIR)),)
  105. + BUILD_PACKAGES += -luci-app-istorex -luci-theme-argon -htop -bash -openssh-sftp-server -luci-nginx luci-ssl
  106. + endif
  107. +else
  108. + $(shell sed -i "/small_flash/d" $(TOPDIR)/repositories.conf)
  109. +endif
  110. +define add_zh_cn_packages
  111. +$(eval BUILD_PACKAGES += $(foreach pkg,$(BUILD_PACKAGES),$(if $(and $(filter luci-app-%,$(pkg)),$(shell $(OPKG) list | grep -q "^luci-i18n-$(patsubst luci-app-%,%,$(pkg))-zh-cn" && echo 1)),luci-i18n-$(patsubst luci-app-%,%,$(pkg))-zh-cn)))
  112. +endef
  113. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  114. PACKAGES:=
  115. @@ -155,7 +182,6 @@ _call_image: staging_dir/host/.prereq-build
  116. echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
  117. echo 'Packages: $(BUILD_PACKAGES)'
  118. echo
  119. - rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
  120. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
  121. $(MAKE) package_reload
  122. $(MAKE) package_install
  123. @@ -163,6 +189,7 @@ _call_image: staging_dir/host/.prereq-build
  124. $(MAKE) -s build_image
  125. $(MAKE) -s json_overview_image_info
  126. $(MAKE) -s checksum
  127. + rm -rf $(KERNEL_BUILD_DIR)/tmp $(KERNEL_BUILD_DIR)/root.* $(TARGET_DIR) $(TARGET_DIR_ORIG)
  128. _call_manifest: FORCE
  129. rm -rf $(TARGET_DIR)
  130. @@ -230,9 +257,17 @@ package_install: FORCE
  131. @echo
  132. @echo Installing packages...
  133. ifeq ($(CONFIG_USE_APK),)
  134. + $(eval $(call add_zh_cn_packages))
  135. $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/libc_*.ipk $(PACKAGE_DIR)/libc_*.ipk))
  136. $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/kernel_*.ipk $(PACKAGE_DIR)/kernel_*.ipk))
  137. - $(OPKG) install $(BUILD_PACKAGES)
  138. + $(OPKG) install --force-maintainer $(BUILD_PACKAGES) luci-i18n-base-zh-cn || true
  139. + $(if $(USER_FILES), \
  140. + find $(USER_FILES) -name "*.ipk" -print0 | \
  141. + while IFS= read -r -d '' ipk; do \
  142. + $(OPKG) install "$$ipk" && rm -f "$$ipk" || true; \
  143. + done; \
  144. + )
  145. + $(OPKG) install --force-maintainer --force-reinstall my-default-settings 2>/dev/null
  146. else
  147. $(APK) add --no-scripts $(firstword $(wildcard $(LINUX_DIR)/libc-*.apk $(PACKAGE_DIR)/libc-*.apk))
  148. $(APK) add --no-scripts $(firstword $(wildcard $(LINUX_DIR)/kernel-*.apk $(PACKAGE_DIR)/kernel-*.apk))
  149. @@ -260,16 +295,19 @@ else
  150. )
  151. endif
  152. $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
  153. + $(if $(SMALL_FLASH), \
  154. + $(shell echo "`grep kwrt_kiddin9 $(TOPDIR)/repositories.conf | sed -e 's/kiddin9/small_flash/g'`" >>$(BUILD_DIR)/root-*/etc/opkg/distfeeds.conf) \
  155. + )
  156. build_image: FORCE
  157. @echo
  158. @echo Building images...
  159. rm -rf $(BUILD_DIR)/json_info_files/
  160. if [ -d "target/linux/feeds/$(BOARD)" ]; then \
  161. - $(NO_TRACE_MAKE) -C target/linux/feeds/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
  162. + nice $(NO_TRACE_MAKE) -C target/linux/feeds/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
  163. $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)"); \
  164. else \
  165. - $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
  166. + nice $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
  167. $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)"); \
  168. fi