imagebuilder.patch 7.8 KB

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