b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2007-2021 OpenWrt.org |
| 3 | # Copyright (C) 2010 Vertical Communications |
| 4 | # |
| 5 | # This is free software, licensed under the GNU General Public License v2. |
| 6 | # See /LICENSE for more information. |
| 7 | # |
| 8 | |
| 9 | include $(TOPDIR)/rules.mk |
| 10 | include $(INCLUDE_DIR)/kernel.mk |
| 11 | include $(INCLUDE_DIR)/version.mk |
| 12 | include $(INCLUDE_DIR)/feeds.mk |
| 13 | |
| 14 | PKG_NAME:=base-files |
| 15 | PKG_FLAGS:=nonshared |
| 16 | PKG_RELEASE:=$(COMMITCOUNT) |
| 17 | |
| 18 | PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/ |
| 19 | PKG_BUILD_DEPENDS:=usign/host ucert/host |
| 20 | PKG_LICENSE:=GPL-2.0 |
| 21 | |
| 22 | # Extend depends from version.mk |
| 23 | PKG_CONFIG_DEPENDS += \ |
| 24 | CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE \ |
| 25 | CONFIG_NAND_SUPPORT \ |
| 26 | CONFIG_LEGACY_SDCARD_SUPPORT \ |
| 27 | CONFIG_EMMC_SUPPORT \ |
| 28 | CONFIG_CLEAN_IPKG \ |
| 29 | CONFIG_PER_FEED_REPO \ |
| 30 | $(foreach feed,$(FEEDS_AVAILABLE),CONFIG_FEED_$(feed)) |
| 31 | |
| 32 | include $(INCLUDE_DIR)/package.mk |
| 33 | |
| 34 | ifneq ($(DUMP),1) |
| 35 | STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell echo $(CONFIG_TARGET_INIT_PATH) | $(MKHASH) md5) |
| 36 | TARGET:=-$(BOARD) |
| 37 | endif |
| 38 | |
| 39 | define Package/base-files |
| 40 | SECTION:=base |
| 41 | CATEGORY:=Base system |
| 42 | DEPENDS:= \ |
| 43 | +netifd +libc +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:openwrt-keyring \ |
| 44 | +NAND_SUPPORT:ubi-utils +fstools +fwtool \ |
| 45 | +SELINUX:procd-selinux +!SELINUX:procd +USE_SECCOMP:procd-seccomp \ |
| 46 | +SELINUX:busybox-selinux +!SELINUX:busybox |
| 47 | TITLE:=Base filesystem for OpenWrt |
| 48 | URL:=http://openwrt.org/ |
| 49 | VERSION:=$(PKG_RELEASE)~$(lastword $(subst -, ,$(REVISION))) |
| 50 | endef |
| 51 | |
| 52 | define Package/base-files/conffiles |
| 53 | /etc/config/ |
| 54 | /etc/config/network |
| 55 | /etc/config/system |
| 56 | /etc/dropbear/ |
| 57 | /etc/ethers |
| 58 | /etc/group |
| 59 | /etc/hosts |
| 60 | /etc/inittab |
| 61 | /etc/iproute2/rt_protos |
| 62 | /etc/iproute2/rt_tables |
| 63 | /etc/passwd |
| 64 | /etc/profile |
| 65 | /etc/profile.d |
| 66 | /etc/protocols |
| 67 | /etc/rc.local |
| 68 | /etc/services |
| 69 | /etc/shadow |
| 70 | /etc/shells |
| 71 | /etc/shinit |
| 72 | /etc/sysctl.conf |
| 73 | /etc/sysupgrade.conf |
| 74 | $(call $(TARGET)/conffiles) |
| 75 | endef |
| 76 | |
| 77 | define Package/base-files/description |
| 78 | This package contains a base filesystem and system scripts for OpenWrt. |
| 79 | endef |
| 80 | |
| 81 | define ImageConfigOptions |
| 82 | mkdir -p $(1)/lib/preinit |
| 83 | echo 'pi_suppress_stderr="$(CONFIG_TARGET_PREINIT_SUPPRESS_STDERR)"' >$(1)/lib/preinit/00_preinit.conf |
| 84 | echo 'fs_failsafe_wait_timeout=$(if $(CONFIG_TARGET_PREINIT_TIMEOUT),$(CONFIG_TARGET_PREINIT_TIMEOUT),2)' >>$(1)/lib/preinit/00_preinit.conf |
| 85 | echo 'pi_init_path="$(TARGET_INIT_PATH)"' >>$(1)/lib/preinit/00_preinit.conf |
| 86 | echo 'pi_init_env=$(if $(CONFIG_TARGET_INIT_ENV),$(CONFIG_TARGET_INIT_ENV),"")' >>$(1)/lib/preinit/00_preinit.conf |
| 87 | echo 'pi_init_cmd=$(if $(CONFIG_TARGET_INIT_CMD),$(CONFIG_TARGET_INIT_CMD),"/sbin/init")' >>$(1)/lib/preinit/00_preinit.conf |
| 88 | echo 'pi_init_suppress_stderr="$(CONFIG_TARGET_INIT_SUPPRESS_STDERR)"' >>$(1)/lib/preinit/00_preinit.conf |
| 89 | echo 'pi_ifname=$(if $(CONFIG_TARGET_PREINIT_IFNAME),$(CONFIG_TARGET_PREINIT_IFNAME),"")' >>$(1)/lib/preinit/00_preinit.conf |
| 90 | echo 'pi_ip=$(if $(CONFIG_TARGET_PREINIT_IP),$(CONFIG_TARGET_PREINIT_IP),"192.168.1.1")' >>$(1)/lib/preinit/00_preinit.conf |
| 91 | echo 'pi_netmask=$(if $(CONFIG_TARGET_PREINIT_NETMASK),$(CONFIG_TARGET_PREINIT_NETMASK),"255.255.255.0")' >>$(1)/lib/preinit/00_preinit.conf |
| 92 | echo 'pi_broadcast=$(if $(CONFIG_TARGET_PREINIT_BROADCAST),$(CONFIG_TARGET_PREINIT_BROADCAST),"192.168.1.255")' >>$(1)/lib/preinit/00_preinit.conf |
| 93 | echo 'pi_preinit_net_messages="$(CONFIG_TARGET_PREINIT_SHOW_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf |
| 94 | echo 'pi_preinit_no_failsafe_netmsg="$(CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf |
| 95 | echo 'pi_preinit_no_failsafe="$(CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE)"' >>$(1)/lib/preinit/00_preinit.conf |
| 96 | ifeq ($(CONFIG_TARGET_DEFAULT_LAN_IP_FROM_PREINIT),y) |
| 97 | mkdir -p $(1)/etc/board.d |
| 98 | echo '. /lib/functions/uci-defaults.sh' >$(1)/etc/board.d/99-lan-ip |
| 99 | echo 'logger -t 99-lan-ip "setting custom default LAN IP"' >>$(1)/etc/board.d/99-lan-ip |
| 100 | echo 'board_config_update' >>$(1)/etc/board.d/99-lan-ip |
| 101 | echo 'json_select network' >>$(1)/etc/board.d/99-lan-ip |
| 102 | echo 'json_select lan' >>$(1)/etc/board.d/99-lan-ip |
| 103 | echo 'json_add_string ipaddr $(if $(CONFIG_TARGET_PREINIT_IP),$(CONFIG_TARGET_PREINIT_IP),"192.168.1.1")' >>$(1)/etc/board.d/99-lan-ip |
| 104 | echo 'json_add_string netmask $(if $(CONFIG_TARGET_PREINIT_NETMASK),$(CONFIG_TARGET_PREINIT_NETMASK),"255.255.255.0")' >>$(1)/etc/board.d/99-lan-ip |
| 105 | echo 'json_select ..' >>$(1)/etc/board.d/99-lan-ip |
| 106 | echo 'json_select ..' >>$(1)/etc/board.d/99-lan-ip |
| 107 | echo 'board_config_flush' >>$(1)/etc/board.d/99-lan-ip |
| 108 | endif |
| 109 | endef |
| 110 | |
| 111 | define Build/Prepare |
| 112 | mkdir -p $(PKG_BUILD_DIR) |
| 113 | endef |
| 114 | |
| 115 | define Build/Quilt |
| 116 | endef |
| 117 | |
| 118 | define Build/Compile/Default |
| 119 | |
| 120 | endef |
| 121 | Build/Compile = $(Build/Compile/Default) |
| 122 | |
| 123 | ifneq ($(CONFIG_USE_APK),) |
| 124 | ifndef CONFIG_BUILDBOT |
| 125 | define Package/base-files/install-key |
| 126 | mkdir -p $(1)/etc/apk/keys |
| 127 | $(CP) $(BUILD_KEY_APK_PUB) $(1)/etc/apk/keys/ |
| 128 | endef |
| 129 | endif |
| 130 | else |
| 131 | ifdef CONFIG_SIGNED_PACKAGES |
| 132 | define Build/Configure |
| 133 | [ -s $(BUILD_KEY) -a -s $(BUILD_KEY).pub ] || \ |
| 134 | $(STAGING_DIR_HOST)/bin/usign -G -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key" |
| 135 | |
| 136 | [ -s $(BUILD_KEY).ucert ] || \ |
| 137 | $(STAGING_DIR_HOST)/bin/ucert -I -c $(BUILD_KEY).ucert -p $(BUILD_KEY).pub -s $(BUILD_KEY) |
| 138 | |
| 139 | endef |
| 140 | |
| 141 | ifndef CONFIG_BUILDBOT |
| 142 | define Package/base-files/install-key |
| 143 | mkdir -p $(1)/etc/opkg/keys |
| 144 | $(CP) $(BUILD_KEY).pub $(1)/etc/opkg/keys/`$(STAGING_DIR_HOST)/bin/usign -F -p $(BUILD_KEY).pub` |
| 145 | endef |
| 146 | endif |
| 147 | endif |
| 148 | endif |
| 149 | |
| 150 | ifeq ($(CONFIG_NAND_SUPPORT),) |
| 151 | define Package/base-files/nand-support |
| 152 | rm -f $(1)/lib/upgrade/nand.sh |
| 153 | endef |
| 154 | endif |
| 155 | |
| 156 | ifeq ($(CONFIG_EMMC_SUPPORT),) |
| 157 | define Package/base-files/emmc-support |
| 158 | rm -f $(1)/lib/upgrade/emmc.sh |
| 159 | endef |
| 160 | endif |
| 161 | |
| 162 | ifeq ($(CONFIG_LEGACY_SDCARD_SUPPORT),) |
| 163 | define Package/base-files/legacy-sdcard-support |
| 164 | rm -f $(1)/lib/upgrade/legacy-sdcard.sh |
| 165 | endef |
| 166 | endif |
| 167 | |
| 168 | |
| 169 | define Package/base-files/install |
| 170 | $(CP) ./files/* $(1)/ |
| 171 | $(Package/base-files/install-key) |
| 172 | $(Package/base-files/nand-support) |
| 173 | $(Package/base-files/legacy-sdcard-support) |
| 174 | $(Package/base-files/emmc-support) |
| 175 | if [ -d $(GENERIC_PLATFORM_DIR)/base-files/. ]; then \ |
| 176 | $(CP) $(GENERIC_PLATFORM_DIR)/base-files/* $(1)/; \ |
| 177 | fi |
| 178 | if [ -d $(PLATFORM_DIR)/base-files/. ]; then \ |
| 179 | $(CP) $(PLATFORM_DIR)/base-files/* $(1)/; \ |
| 180 | fi |
| 181 | if [ -d ./profile-files/$(SUBTARGET)/$(PROFILE)/base-files/. ]; then \ |
| 182 | $(CP) ./profile-files/$(SUBTARGET)/$(PROFILE)/base-files/* $(1)/; \ |
| 183 | fi |
| 184 | ifeq ($(CONFIG_DSDS), y) |
| 185 | if [ -d ./profile-files/$(SUBTARGET)/$(PROFILE)/base-files/sbin/dsds/ ]; then \ |
| 186 | $(CP) ./profile-files/$(SUBTARGET)/$(PROFILE)/base-files/sbin/dsds/* $(1)/sbin/; \ |
| 187 | rm -rf $(1)/sbin/dsds; \ |
| 188 | fi |
| 189 | endif |
| 190 | $(if $(filter-out $(PLATFORM_DIR),$(PLATFORM_SUBDIR)), \ |
| 191 | if [ -d $(PLATFORM_SUBDIR)/base-files/. ]; then \ |
| 192 | $(CP) $(PLATFORM_SUBDIR)/base-files/* $(1)/; \ |
| 193 | fi; \ |
| 194 | if [ -d $(PLATFORM_SUBDIR)/base-files-$(PROFILE)/. ]; then \ |
| 195 | $(CP) $(PLATFORM_SUBDIR)/base-files-$(PROFILE)/* $(1)/; \ |
| 196 | fi; \ |
| 197 | if [ -d $(PLATFORM_SUBDIR)/$(PROFILE)/base-files/. ]; then \ |
| 198 | $(CP) $(PLATFORM_SUBDIR)/$(PROFILE)/base-files/* $(1)/; \ |
| 199 | fi \ |
| 200 | ) |
| 201 | |
| 202 | $(VERSION_SED_SCRIPT) \ |
| 203 | $(1)/etc/banner \ |
| 204 | $(1)/etc/device_info \ |
| 205 | $(1)/etc/openwrt_release \ |
| 206 | $(1)/etc/openwrt_version \ |
| 207 | $(1)/usr/lib/os-release |
| 208 | |
| 209 | |
| 210 | $(SED) "s#%PATH%#$(TARGET_INIT_PATH)#g" \ |
| 211 | $(1)/sbin/hotplug-call \ |
| 212 | $(1)/etc/preinit \ |
| 213 | $(1)/etc/profile |
| 214 | |
| 215 | mkdir -p \ |
| 216 | $(1)/CONTROL \ |
| 217 | $(1)/dev \ |
| 218 | $(1)/etc/config \ |
| 219 | $(1)/etc/crontabs \ |
| 220 | $(1)/etc/rc.d \ |
| 221 | $(1)/etc/profile.d \ |
| 222 | $(1)/overlay \ |
| 223 | $(1)/lib/firmware \ |
| 224 | $(1)/mnt \ |
| 225 | $(1)/proc \ |
| 226 | $(1)/tmp \ |
| 227 | $(1)/usr/lib \ |
| 228 | $(1)/usr/bin \ |
| 229 | $(1)/sys \ |
| 230 | $(1)/www |
| 231 | mkdir -p -m 750 \ |
| 232 | $(1)/root |
| 233 | |
| 234 | $(LN) /proc/mounts $(1)/etc/mtab |
| 235 | $(if $(LIB_SUFFIX),-$(LN) lib $(1)/lib$(LIB_SUFFIX)) |
| 236 | $(if $(LIB_SUFFIX),-$(LN) lib $(1)/usr/lib$(LIB_SUFFIX)) |
| 237 | |
| 238 | ifneq ($(CONFIG_TARGET_ROOTFS_PERSIST_VAR),y) |
| 239 | rm -f $(1)/var |
| 240 | $(LN) tmp $(1)/var |
| 241 | else |
| 242 | mkdir -p $(1)/var |
| 243 | $(LN) /tmp/run $(1)/var/run |
| 244 | endif |
| 245 | $(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/ |
| 246 | |
| 247 | chmod 0600 $(1)/etc/shadow |
| 248 | chmod 1777 $(1)/tmp |
| 249 | |
| 250 | $(call ImageConfigOptions,$(1)) |
| 251 | $(call Package/base-files/install-target,$(1)) |
| 252 | for conffile in $(1)/etc/config/*; do \ |
| 253 | if [ -f "$$$$conffile" ]; then \ |
| 254 | grep "$$$${conffile##$(1)}" $(1)/CONTROL/conffiles || \ |
| 255 | echo "$$$${conffile##$(1)}" >> $(1)/CONTROL/conffiles; \ |
| 256 | fi \ |
| 257 | done |
| 258 | |
| 259 | $(if $(CONFIG_INCLUDE_CONFIG), \ |
| 260 | echo -e "# Build configuration for board $(BOARD)/$(SUBTARGET)/$(PROFILE)\n" >$(1)/etc/build.config; \ |
| 261 | cat $(BIN_DIR)/config.buildinfo >>$(1)/etc/build.config; \ |
| 262 | cat $(BIN_DIR)/feeds.buildinfo >>$(1)/etc/build.feeds; \ |
| 263 | cat $(BIN_DIR)/version.buildinfo >>$(1)/etc/build.version) |
| 264 | |
| 265 | $(if $(CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE), \ |
| 266 | rm -f $(1)/etc/banner.failsafe,) |
| 267 | |
| 268 | $(if $(CONFIG_PACKAGE_tslib), \ |
| 269 | $(CP) ./profile-files/$(SUBTARGET)/extra/tslib_env.sh $(1)/etc/profile.d) |
| 270 | |
| 271 | ifneq ($(CONFIG_USE_APK),) |
| 272 | mkdir -p $(1)/etc/apk/ |
| 273 | $(call FeedSourcesAppendAPK,$(1)/etc/apk/repositories) |
| 274 | $(VERSION_SED_SCRIPT) $(1)/etc/apk/repositories |
| 275 | |
| 276 | rm -f $(1)/etc/uci-defaults/13_fix-group-user |
| 277 | rm -f $(1)/sbin/pkg_check |
| 278 | else |
| 279 | $(if $(CONFIG_CLEAN_IPKG),, \ |
| 280 | mkdir -p $(1)/etc/opkg; \ |
| 281 | $(call FeedSourcesAppendOPKG,$(1)/etc/opkg/distfeeds.conf); \ |
| 282 | $(VERSION_SED_SCRIPT) $(1)/etc/opkg/distfeeds.conf) |
| 283 | $(if $(CONFIG_IPK_FILES_CHECKSUMS),, \ |
| 284 | rm -f $(1)/sbin/pkg_check) |
| 285 | endif |
| 286 | endef |
| 287 | |
| 288 | ifneq ($(DUMP),1) |
| 289 | -include $(PLATFORM_DIR)/base-files.mk |
| 290 | -include $(PLATFORM_SUBDIR)/base-files.mk |
| 291 | endif |
| 292 | |
| 293 | $(eval $(call BuildPackage,base-files)) |