OpenWRT集成busybox配置项的流程
来源 https://www.openwrt.pro/post-613.html
1、研究背景
我们在开发的过程中可能需要移植OpenWRT上没有的软件包,而这些软件包又比较特殊。例如,像busybox那样自带kconfig配置文件供生成菜单配置界面的软件包。我们可以直接在这个软件包根目录下执行make menuconfig来配置我们需要的功能,保存配置后在这个软件包的源码根目录下直接执行make命令即可编译该软件包。
但是,想将这样的软件包集成到OpenWRT中,就需要把这些配置项都集成到OpenWRT的配置中。考虑到在OpenWRT中,busybox就是一个很典型的集成案例。所以,我们在集成这样的软件包时就可以参考它的集成方式。
下面,我们就以busybox为例进行说明,源码摘自github,如下:
https://github.com/openwrt/openwrt/tree/master/package/utils/busybox
2、OpenWRT如何集成busybox的配置项
busybox本身也自带了很多配置选项,但实际上我们却可以在OpenWRT总的配置项中对其进行配置,而不需要进入busybox目录单独对其做进行配置。
通过查看busybox包的顶层Makefile,可以发现,OpenWRT是这样集成busybox的配置项的。不改动busybox原来的配置项,而是针对busybox每个配置项都另外生成一个对应的配置项,用于集成到OpenWRT中。
这些配置项被定义在openwrt/package/utils/busybox/config目录中。并通过 openwrt/package/utils/busybox/Config.in文件连接到OpenWRT总的配置项中。
接下来,我们就结合代码(openwrt/package/utils/busybox/Makefile)来分析一下这个OpenWRT集成busybox配置项的过程,代码如下所示:
1 # SPDX-License-Identifier: GPL-2.0-or-later 2 # 3 # Copyright (C) 2006-2021 OpenWrt.org 4 5 include $(TOPDIR)/rules.mk 6 7 PKG_NAME:=busybox 8 PKG_VERSION:=1.33.1 9 PKG_RELEASE:=$(AUTORELEASE) 10 PKG_FLAGS:=essential 11 12 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 13 PKG_SOURCE_URL:=https://www.busybox.net/downloads \ 14 http://sources.buildroot.net 15 PKG_HASH:=12cec6bd2b16d8a9446dd16130f2b92982f1819f6e1c5f5887b6db03f5660d28 16 17 PKG_BUILD_DEPENDS:=BUSYBOX_CONFIG_PAM:libpam 18 PKG_BUILD_PARALLEL:=1 19 PKG_CHECK_FORMAT_SECURITY:=0 20 21 PKG_LICENSE:=GPL-2.0 22 PKG_LICENSE_FILES:=LICENSE archival/libarchive/bz/LICENSE 23 PKG_CPE_ID:=cpe:/a:busybox:busybox 24 25 BUSYBOX_SYM=$(if $(CONFIG_BUSYBOX_CUSTOM),CONFIG,DEFAULT) 26 BUSYBOX_IF_ENABLED=$(if $(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_$(1)),$(2)) 27 28 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SUID),) 29 PKG_FILE_MODES:=/bin/busybox:root:root:4755 30 endif 31 32 include $(INCLUDE_DIR)/package.mk 33 34 ifeq ($(DUMP),) 35 STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell grep '^CONFIG_BUSYBOX_' $(TOPDIR)/.config | $(MKHASH) md5) 36 endif 37 38 # All files provided by busybox will serve as fallback alternatives by opkg. 39 # There should be no need to enumerate ALTERNATIVES entries here 40 define Package/busybox/Default 41 SECTION:=base 42 CATEGORY:=Base system 43 MAINTAINER:=Felix Fietkau <[email protected]> 44 TITLE:=Core utilities for embedded Linux 45 URL:=http://busybox.net/ 46 DEPENDS:=+BUSYBOX_CONFIG_PAM:libpam +BUSYBOX_CONFIG_NTPD:jsonfilter 47 USERID:=ntp=123:ntp=123 48 endef 49 50 define Package/busybox 51 $(call Package/busybox/Default) 52 CONFLICTS:=busybox-selinux 53 VARIANT:=default 54 endef 55 56 define Package/busybox-selinux 57 $(call Package/busybox/Default) 58 TITLE += with SELinux support 59 DEPENDS += +libselinux 60 VARIANT:=selinux 61 PROVIDES:=busybox 62 endef 63 64 define Package/busybox/description 65 The Swiss Army Knife of embedded Linux. 66 It slices, it dices, it makes Julian Fries. 67 endef 68 69 define Package/busybox/config 70 source "$(SOURCE)/Config.in" 71 endef 72 73 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOG)$(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOGD_CFG),) 74 define Package/busybox/conffiles/syslog 75 /etc/syslog.conf 76 endef 77 endif 78 79 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_CROND),) 80 define Package/busybox/conffiles/crond 81 /etc/crontabs/ 82 endef 83 endif 84 85 define Package/busybox/conffiles 86 $(Package/busybox/conffiles/syslog) 87 $(Package/busybox/conffiles/crond) 88 endef 89 90 Package/busybox-selinux/conffiles = $(Package/busybox/conffiles) 91 92 ifndef CONFIG_USE_MUSL 93 LDLIBS:=m crypt 94 endif 95 96 LDLIBS += $(call BUSYBOX_IF_ENABLED,PAM,pam pam_misc pthread) 97 98 ifeq ($(CONFIG_USE_GLIBC),y) 99 LDLIBS += $(call BUSYBOX_IF_ENABLED,NSLOOKUP,resolv) 100 endif 101 102 ifeq ($(BUILD_VARIANT),selinux) 103 LDLIBS += selinux sepol 104 endif 105 106 TARGET_CFLAGS += -flto 107 TARGET_LDFLAGS += -flto=jobserver -fuse-linker-plugin 108 109 MAKE_VARS := 110 MAKE_FLAGS += \ 111 EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \ 112 EXTRA_LDFLAGS="$(TARGET_LDFLAGS)" \ 113 LDLIBS="$(LDLIBS)" \ 114 LD="$(TARGET_CC)" \ 115 SKIP_STRIP=y 116 ifneq ($(findstring c,$(OPENWRT_VERBOSE)),) 117 MAKE_FLAGS += V=1 118 endif 119 120 define Build/Configure 121 rm -f $(PKG_BUILD_DIR)/.config 122 touch $(PKG_BUILD_DIR)/.config 123 ifeq ($(DEVICE_TYPE),nas) 124 echo "CONFIG_HDPARM=y" >> $(PKG_BUILD_DIR)/.config 125 endif 126 ifeq ($(BUILD_VARIANT),selinux) 127 cat $(TOPDIR)/$(SOURCE)/selinux.config >> $(PKG_BUILD_DIR)/.config 128 endif 129 grep 'CONFIG_BUSYBOX_$(BUSYBOX_SYM)' $(TOPDIR)/.config | sed -e "s,\\(# \)\\?CONFIG_BUSYBOX_$(BUSYBOX_SYM)_\\(.*\\),\\1CONFIG_\\2,g" >> $(PKG_BUILD_DIR)/.config 130 yes 'n' | $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS) oldconfig 131 endef 132 133 define Build/Compile 134 $(call Build/Compile/Default, \ 135 CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \ 136 all install \ 137 ) 138 endef 139 140 define Package/busybox/install 141 $(INSTALL_DIR) $(1)/etc/init.d 142 $(INSTALL_DIR) $(1)/usr/sbin 143 $(CP) $(PKG_INSTALL_DIR)/* $(1)/ 144 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOG)$(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOGD_CFG),) 145 touch $(1)/etc/syslog.conf 146 endif 147 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_CROND),) 148 $(INSTALL_BIN) ./files/cron $(1)/etc/init.d/cron 149 $(INSTALL_DIR) $(1)/etc/crontabs 150 endif 151 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_NTPD),) 152 $(INSTALL_BIN) ./files/sysntpd $(1)/etc/init.d/sysntpd 153 $(INSTALL_BIN) ./files/ntpd-hotplug $(1)/usr/sbin/ntpd-hotplug 154 $(INSTALL_DIR) $(1)/etc/capabilities $(1)/usr/share/acl.d 155 $(INSTALL_DATA) ./files/ntpd.capabilities $(1)/etc/capabilities/ntpd.json 156 $(INSTALL_DATA) ./files/ntpd_acl.json $(1)/usr/share/acl.d/ntpd.json 157 endif 158 -rm -rf $(1)/lib64 159 endef 160 161 Package/busybox-selinux/install = $(Package/busybox/install) 162 163 $(eval $(call BuildPackage,busybox)) 164 $(eval $(call BuildPackage,busybox-selinux))
从该Makefile的第69~71行可以看出,对于OpenWRT而言,busybox的配置项就来源于$(SOURCE)/Config.in文件。
接下来,我们看下openwrt/package/utils/busybox/Config.in这个busybox总的配置文件。代码如下所示:
1 if PACKAGE_busybox || PACKAGE_busybox-selinux 2 3 config BUSYBOX_CUSTOM 4 bool "Customize busybox options" 5 default n 6 help 7 Enabling this allows full customization of busybox settings. 8 Note that there are many options here that can result in a build 9 that doesn't work properly. Enabling customization will mark your 10 build as "tainted" for the purpose of bug reports. 11 See the variables written to /etc/openwrt_release 12 13 Unless you know what you are doing, you should leave this as 'n' 14 15 source "Config-defaults.in" 16 17 if BUSYBOX_CUSTOM 18 source "config/Config.in" 19 endif 20 21 endif
可以看到,配置文件Config.in中定义了一个名为BUSYBOX_CUSTOM的配置项。当没有选中该配置项的时候,只导入默认配置文件”Config-default.in”中的配置。当我们选中该配置项的时,就再导入config目录下对应于busybox原生配置项的配置文件,进而允许用户自定义busybox的全部功能。
我们暂且看Config.in文件中自定义配置的内容。此时,Config.in只导入了Config-defaults.in文件中的配置项。打开Config-defaults.in这个文件可以看到,里面定义了一系列以BUSYBOX_DEFAULT开头的配置项。具体的代码如下所示:
1 # 2 # For a description of the syntax of this configuration file, 3 # see docs/Kconfig-language.txt. 4 # 5 6 7 config BUSYBOX_CONFIG_HAVE_DOT_CONFIG 8 bool 9 default BUSYBOX_DEFAULT_HAVE_DOT_CONFIG 10 11 menu "Settings" 12 13 config BUSYBOX_CONFIG_DESKTOP 14 bool "Enable compatibility for full-blown desktop systems (8kb)" 15 default BUSYBOX_DEFAULT_DESKTOP 16 help 17 Enable applet options and features which are not essential. 18 Many applet options have dedicated config options to (de)select them 19 under that applet; this options enables those options which have no 20 individual config item for them. 21 22 Select this if you plan to use busybox on full-blown desktop machine 23 with common Linux distro, which needs higher level of command-line 24 compatibility. 25 26 If you are preparing your build to be used on an embedded box 27 where you have tighter control over the entire set of userspace 28 tools, you can unselect this option for smaller code size. 29 30 config BUSYBOX_CONFIG_EXTRA_COMPAT 31 bool "Provide compatible behavior for rare corner cases (bigger code)" 32 default BUSYBOX_DEFAULT_EXTRA_COMPAT 33 help 34 This option makes grep, sed etc handle rare corner cases 35 (embedded NUL bytes and such). This makes code bigger and uses 36 some GNU extensions in libc. You probably only need this option 37 if you plan to run busybox on desktop. 38 39 config BUSYBOX_CONFIG_FEDORA_COMPAT 40 bool "Building for Fedora distribution" 41 default BUSYBOX_DEFAULT_FEDORA_COMPAT 42 help 43 This option makes some tools behave like they do on Fedora. 44 45 At the time of this writing (2017-08) this only affects uname: 46 normally, uname -p (processor) and uname -i (platform) 47 are shown as "unknown", but with this option uname -p 48 shows the same string as uname -m (machine type), 49 and so does uname -i unless machine type is i486/i586/i686 - 50 then uname -i shows "i386". 51 52 config BUSYBOX_CONFIG_INCLUDE_SUSv2 53 bool "Enable obsolete features removed before SUSv3" 54 default BUSYBOX_DEFAULT_INCLUDE_SUSv2 55 help 56 This option will enable backwards compatibility with SuSv2, 57 specifically, old-style numeric options ('command -1 <file>') 58 will be supported in head, tail, and fold. (Note: should 59 affect renice too.) 60 61 config BUSYBOX_CONFIG_LONG_OPTS 62 bool "Support --long-options" 63 default BUSYBOX_DEFAULT_LONG_OPTS 64 help 65 Enable this if you want busybox applets to use the gnu --long-option 66 style, in addition to single character -a -b -c style options. 67 68 config BUSYBOX_CONFIG_SHOW_USAGE 69 bool "Show applet usage messages" 70 default BUSYBOX_DEFAULT_SHOW_USAGE 71 help 72 Enabling this option, applets will show terse help messages 73 when invoked with wrong arguments. 74 If you do not want to show any (helpful) usage message when 75 issuing wrong command syntax, you can say 'N' here, 76 saving approximately 7k. 77 78 config BUSYBOX_CONFIG_FEATURE_VERBOSE_USAGE 79 bool "Show verbose applet usage messages" 80 default BUSYBOX_DEFAULT_FEATURE_VERBOSE_USAGE 81 depends on BUSYBOX_CONFIG_SHOW_USAGE 82 help 83 All applets will show verbose help messages when invoked with --help. 84 This will add a lot of text to the binary. 85 86 config BUSYBOX_CONFIG_FEATURE_COMPRESS_USAGE 87 bool "Store applet usage messages in compressed form" 88 default BUSYBOX_DEFAULT_FEATURE_COMPRESS_USAGE 89 depends on BUSYBOX_CONFIG_SHOW_USAGE 90 help 91 Store usage messages in .bz2 compressed form, uncompress them 92 on-the-fly when "APPLET --help" is run. 93 94 If you have a really tiny busybox with few applets enabled (and 95 bunzip2 isn't one of them), the overhead of the decompressor might 96 be noticeable. Also, if you run executables directly from ROM 97 and have very little memory, this might not be a win. Otherwise, 98 you probably want this. 99 100 config BUSYBOX_CONFIG_LFS 101 bool 102 default BUSYBOX_DEFAULT_LFS 103 help 104 If you need to work with large files, enable this option. 105 This will have no effect if your kernel or your C 106 library lacks large file support for large files. Some of the 107 programs that can benefit from large file support include dd, gzip, 108 cp, mount, tar. 109 110 config BUSYBOX_CONFIG_PAM 111 bool "Support PAM (Pluggable Authentication Modules)" 112 default BUSYBOX_DEFAULT_PAM 113 help 114 Use PAM in some applets (currently login and httpd) instead 115 of direct access to password database. 116 117 config BUSYBOX_CONFIG_FEATURE_DEVPTS 118 bool "Use the devpts filesystem for Unix98 PTYs" 119 default BUSYBOX_DEFAULT_FEATURE_DEVPTS 120 help 121 Enable if you want to use Unix98 PTY support. If enabled, 122 busybox will use /dev/ptmx for the master side of the pseudoterminal 123 and /dev/pts/<number> for the slave side. Otherwise, BSD style 124 /dev/ttyp<number> will be used. To use this option, you should have 125 devpts mounted. 126 127 config BUSYBOX_CONFIG_FEATURE_UTMP 128 bool "Support utmp file" 129 default BUSYBOX_DEFAULT_FEATURE_UTMP 130 help 131 The file /var/run/utmp is used to track who is currently logged in. 132 With this option on, certain applets (getty, login, telnetd etc) 133 will create and delete entries there. 134 "who" applet requires this option. 135 136 config BUSYBOX_CONFIG_FEATURE_WTMP 137 bool "Support wtmp file" 138 default BUSYBOX_DEFAULT_FEATURE_WTMP 139 depends on BUSYBOX_CONFIG_FEATURE_UTMP 140 help 141 The file /var/run/wtmp is used to track when users have logged into 142 and logged out of the system. 143 With this option on, certain applets (getty, login, telnetd etc) 144 will append new entries there. 145 "last" applet requires this option. 146 147 config BUSYBOX_CONFIG_FEATURE_PIDFILE 148 bool "Support writing pidfiles" 149 default BUSYBOX_DEFAULT_FEATURE_PIDFILE 150 help 151 This option makes some applets (e.g. crond, syslogd, inetd) write 152 a pidfile at the configured PID_FILE_PATH. It has no effect 153 on applets which require pidfiles to run. 154 155 config BUSYBOX_CONFIG_PID_FILE_PATH 156 string "Directory for pidfiles" 157 default BUSYBOX_DEFAULT_PID_FILE_PATH 158 depends on BUSYBOX_CONFIG_FEATURE_PIDFILE || BUSYBOX_CONFIG_FEATURE_CROND_SPECIAL_TIMES 159 help 160 This is the default path where pidfiles are created. Applets which 161 allow you to set the pidfile path on the command line will override 162 this value. The option has no effect on applets that require you to 163 specify a pidfile path. When crond has the 'Support special times' 164 option enabled, the 'crond.reboot' file is also stored here. 165 166 config BUSYBOX_CONFIG_BUSYBOX 167 bool "Include busybox applet" 168 default BUSYBOX_DEFAULT_BUSYBOX 169 help 170 The busybox applet provides general help message and allows 171 the included applets to be listed. It also provides 172 optional --install command to create applet links. If you unselect 173 this option, running busybox without any arguments will give 174 just a cryptic error message: 175 176 $ busybox 177 busybox: applet not found 178 179 Running "busybox APPLET [ARGS...]" will still work, of course. 180 181 config BUSYBOX_CONFIG_FEATURE_SHOW_SCRIPT 182 bool "Support --show SCRIPT" 183 default BUSYBOX_DEFAULT_FEATURE_SHOW_SCRIPT 184 depends on BUSYBOX_CONFIG_BUSYBOX 185 186 config BUSYBOX_CONFIG_FEATURE_INSTALLER 187 bool "Support --install [-s] to install applet links at runtime" 188 default BUSYBOX_DEFAULT_FEATURE_INSTALLER 189 depends on BUSYBOX_CONFIG_BUSYBOX 190 help 191 Enable 'busybox --install [-s]' support. This will allow you to use 192 busybox at runtime to create hard links or symlinks for all the 193 applets that are compiled into busybox. 194 195 config BUSYBOX_CONFIG_INSTALL_NO_USR 196 bool "Don't use /usr" 197 default BUSYBOX_DEFAULT_INSTALL_NO_USR 198 help 199 Disable use of /usr. "busybox --install" and "make install" 200 will install applets only to /bin and /sbin, 201 never to /usr/bin or /usr/sbin. 202 203 config BUSYBOX_CONFIG_FEATURE_SUID 204 bool "Drop SUID state for most applets" 205 default BUSYBOX_DEFAULT_FEATURE_SUID 206 help 207 With this option you can install the busybox binary belonging 208 to root with the suid bit set, enabling some applets to perform 209 root-level operations even when run by ordinary users 210 (for example, mounting of user mounts in fstab needs this). 211 212 With this option enabled, busybox drops privileges for applets 213 that don't need root access, before entering their main() function. 214 215 If you are really paranoid and don't want even initial busybox code 216 to run under root for every applet, build two busybox binaries with 217 different applets in them (and the appropriate symlinks pointing 218 to each binary), and only set the suid bit on the one that needs it. 219 220 Some applets which require root rights (need suid bit on the binary 221 or to be run by root) and will refuse to execute otherwise: 222 crontab, login, passwd, su, vlock, wall. 223 224 The applets which will use root rights if they have them 225 (via suid bit, or because run by root), but would try to work 226 without root right nevertheless: 227 findfs, ping[6], traceroute[6], mount. 228 229 Note that if you DO NOT select this option, but DO make busybox 230 suid root, ALL applets will run under root, which is a huge 231 security hole (think "cp /some/file /etc/passwd"). 232 233 config BUSYBOX_CONFIG_FEATURE_SUID_CONFIG 234 bool "Enable SUID configuration via /etc/busybox.conf" 235 default BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG 236 depends on BUSYBOX_CONFIG_FEATURE_SUID 237 help 238 Allow the SUID/SGID state of an applet to be determined at runtime 239 by checking /etc/busybox.conf. (This is sort of a poor man's sudo.) 240 The format of this file is as follows: 241 242 APPLET = [Ssx-][Ssx-][x-] [USER.GROUP] 243 244 s: USER or GROUP is allowed to execute APPLET. 245 APPLET will run under USER or GROUP 246 (regardless of who's running it). 247 S: USER or GROUP is NOT allowed to execute APPLET. 248 APPLET will run under USER or GROUP. 249 This option is not very sensical. 250 x: USER/GROUP/others are allowed to execute APPLET. 251 No UID/GID change will be done when it is run. 252 -: USER/GROUP/others are not allowed to execute APPLET. 253 254 An example might help: 255 256 |[SUID] 257 |su = ssx root.0 # applet su can be run by anyone and runs with 258 | # euid=0,egid=0 259 |su = ssx # exactly the same 260 | 261 |mount = sx- root.disk # applet mount can be run by root and members 262 | # of group disk (but not anyone else) 263 | # and runs with euid=0 (egid is not changed) 264 | 265 |cp = --- # disable applet cp for everyone 266 267 The file has to be owned by user root, group root and has to be 268 writeable only by root: 269 (chown 0.0 /etc/busybox.conf; chmod 600 /etc/busybox.conf) 270 The busybox executable has to be owned by user root, group 271 root and has to be setuid root for this to work: 272 (chown 0.0 /bin/busybox; chmod 4755 /bin/busybox) 273 274 Robert 'sandman' Griebl has more information here: 275 <url: http://www.softforge.de/bb/suid.html >. 276 277 config BUSYBOX_CONFIG_FEATURE_SUID_CONFIG_QUIET 278 bool "Suppress warning message if /etc/busybox.conf is not readable" 279 default BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG_QUIET 280 depends on BUSYBOX_CONFIG_FEATURE_SUID_CONFIG 281 help 282 /etc/busybox.conf should be readable by the user needing the SUID, 283 check this option to avoid users to be notified about missing 284 permissions. 285 286 config BUSYBOX_CONFIG_FEATURE_PREFER_APPLETS 287 bool "exec prefers applets" 288 default BUSYBOX_DEFAULT_FEATURE_PREFER_APPLETS 289 help 290 This is an experimental option which directs applets about to 291 call 'exec' to try and find an applicable busybox applet before 292 searching the PATH. This is typically done by exec'ing 293 /proc/self/exe. 294 295 This may affect shell, find -exec, xargs and similar applets. 296 They will use applets even if /bin/APPLET -> busybox link 297 is missing (or is not a link to busybox). However, this causes 298 problems in chroot jails without mounted /proc and with ps/top 299 (command name can be shown as 'exe' for applets started this way). 300 301 config BUSYBOX_CONFIG_BUSYBOX_EXEC_PATH 302 string "Path to busybox executable" 303 default BUSYBOX_DEFAULT_BUSYBOX_EXEC_PATH 304 help 305 When applets need to run other applets, busybox 306 sometimes needs to exec() itself. When the /proc filesystem is 307 mounted, /proc/self/exe always points to the currently running 308 executable. If you haven't got /proc, set this to wherever you 309 want to run busybox from. 310 311 config BUSYBOX_CONFIG_SELINUX 312 bool "Support NSA Security Enhanced Linux" 313 default BUSYBOX_DEFAULT_SELINUX 314 help 315 Enable support for SELinux in applets ls, ps, and id. Also provide 316 the option of compiling in SELinux applets. 317 318 If you do not have a complete SELinux userland installed, this stuff 319 will not compile. Specifially, libselinux 1.28 or better is 320 directly required by busybox. If the installation is located in a 321 non-standard directory, provide it by invoking make as follows: 322 323 CFLAGS=-I<libselinux-include-path> \ 324 LDFLAGS=-L<libselinux-lib-path> \ 325 make 326 327 Most people will leave this set to 'N'. 328 329 config BUSYBOX_CONFIG_FEATURE_CLEAN_UP 330 bool "Clean up all memory before exiting (usually not needed)" 331 default BUSYBOX_DEFAULT_FEATURE_CLEAN_UP 332 help 333 As a size optimization, busybox normally exits without explicitly 334 freeing dynamically allocated memory or closing files. This saves 335 space since the OS will clean up for us, but it can confuse debuggers 336 like valgrind, which report tons of memory and resource leaks. 337 338 Don't enable this unless you have a really good reason to clean 339 things up manually. 340 341 config BUSYBOX_CONFIG_FEATURE_SYSLOG_INFO 342 bool "Support LOG_INFO level syslog messages" 343 default BUSYBOX_DEFAULT_FEATURE_SYSLOG_INFO 344 depends on BUSYBOX_CONFIG_FEATURE_SYSLOG 345 help 346 Applets which send their output to syslog use either LOG_INFO or 347 LOG_ERR log levels, but by disabling this option all messages will 348 be logged at the LOG_ERR level, saving just under 200 bytes. 349 350 # These are auto-selected by other options 351 352 config BUSYBOX_CONFIG_FEATURE_SYSLOG 353 bool #No description makes it a hidden option 354 default BUSYBOX_DEFAULT_FEATURE_SYSLOG 355 #help 356 #This option is auto-selected when you select any applet which may 357 #send its output to syslog. You do not need to select it manually. 358 359 comment 'Build Options' 360 361 config BUSYBOX_CONFIG_STATIC 362 bool "Build static binary (no shared libs)" 363 default BUSYBOX_DEFAULT_STATIC 364 help 365 If you want to build a static binary, which does not use 366 or require any shared libraries, enable this option. 367 Static binaries are larger, but do not require functioning 368 dynamic libraries to be present, which is important if used 369 as a system rescue tool. 370 371 config BUSYBOX_CONFIG_PIE 372 bool "Build position independent executable" 373 default BUSYBOX_DEFAULT_PIE 374 depends on !BUSYBOX_CONFIG_STATIC 375 help 376 Hardened code option. PIE binaries are loaded at a different 377 address at each invocation. This has some overhead, 378 particularly on x86-32 which is short on registers. 379 380 Most people will leave this set to 'N'. 381 382 config BUSYBOX_CONFIG_NOMMU 383 bool "Force NOMMU build" 384 default BUSYBOX_DEFAULT_NOMMU 385 help 386 Busybox tries to detect whether architecture it is being 387 built against supports MMU or not. If this detection fails, 388 or if you want to build NOMMU version of busybox for testing, 389 you may force NOMMU build here. 390 391 Most people will leave this set to 'N'. 392 393 # PIE can be made to work with BUILD_LIBBUSYBOX, but currently 394 # build system does not support that 395 config BUSYBOX_CONFIG_BUILD_LIBBUSYBOX 396 bool "Build shared libbusybox" 397 default BUSYBOX_DEFAULT_BUILD_LIBBUSYBOX 398 depends on !BUSYBOX_CONFIG_FEATURE_PREFER_APPLETS && !BUSYBOX_CONFIG_PIE && !BUSYBOX_CONFIG_STATIC 399 help 400 Build a shared library libbusybox.so.N.N.N which contains all 401 busybox code. 402 403 This feature allows every applet to be built as a really tiny 404 separate executable linked against the library: 405 |$ size 0_lib/l* 406 | text data bss dec hex filename 407 | 939 212 28 1179 49b 0_lib/last 408 | 939 212 28 1179 49b 0_lib/less 409 | 919138 8328 1556 929022 e2cfe 0_lib/libbusybox.so.1.N.M 410 411 This is useful on NOMMU systems which are not capable 412 of sharing executables, but are capable of sharing code 413 in dynamic libraries. 414 415 config BUSYBOX_CONFIG_FEATURE_LIBBUSYBOX_STATIC 416 bool "Pull in all external references into libbusybox" 417 default BUSYBOX_DEFAULT_FEATURE_LIBBUSYBOX_STATIC 418 depends on BUSYBOX_CONFIG_BUILD_LIBBUSYBOX 419 help 420 Make libbusybox library independent, not using or requiring 421 any other shared libraries. 422 423 config BUSYBOX_CONFIG_FEATURE_INDIVIDUAL 424 bool "Produce a binary for each applet, linked against libbusybox" 425 default BUSYBOX_DEFAULT_FEATURE_INDIVIDUAL 426 depends on BUSYBOX_CONFIG_BUILD_LIBBUSYBOX 427 help 428 If your CPU architecture doesn't allow for sharing text/rodata 429 sections of running binaries, but allows for runtime dynamic 430 libraries, this option will allow you to reduce memory footprint 431 when you have many different applets running at once. 432 433 If your CPU architecture allows for sharing text/rodata, 434 having single binary is more optimal. 435 436 Each applet will be a tiny program, dynamically linked 437 against libbusybox.so.N.N.N. 438 439 You need to have a working dynamic linker. 440 441 config BUSYBOX_CONFIG_FEATURE_SHARED_BUSYBOX 442 bool "Produce additional busybox binary linked against libbusybox" 443 default BUSYBOX_DEFAULT_FEATURE_SHARED_BUSYBOX 444 depends on BUSYBOX_CONFIG_BUILD_LIBBUSYBOX 445 help 446 Build busybox, dynamically linked against libbusybox.so.N.N.N. 447 448 You need to have a working dynamic linker. 449 450 ### config BUILD_AT_ONCE 451 ### bool "Compile all sources at once" 452 ### default n 453 ### help 454 ### Normally each source-file is compiled with one invocation of 455 ### the compiler. 456 ### If you set this option, all sources are compiled at once. 457 ### This gives the compiler more opportunities to optimize which can 458 ### result in smaller and/or faster binaries. 459 ### 460 ### Setting this option will consume alot of memory, e.g. if you 461 ### enable all applets with all features, gcc uses more than 300MB 462 ### RAM during compilation of busybox. 463 ### 464 ### This option is most likely only beneficial for newer compilers 465 ### such as gcc-4.1 and above. 466 ### 467 ### Say 'N' unless you know what you are doing. 468 469 config BUSYBOX_CONFIG_CROSS_COMPILER_PREFIX 470 string "Cross compiler prefix" 471 default BUSYBOX_DEFAULT_CROSS_COMPILER_PREFIX 472 help 473 If you want to build busybox with a cross compiler, then you 474 will need to set this to the cross-compiler prefix, for example, 475 "i386-uclibc-". 476 477 Note that CROSS_COMPILE environment variable or 478 "make CROSS_COMPILE=xxx ..." will override this selection. 479 480 Native builds leave this empty. 481 482 config BUSYBOX_CONFIG_SYSROOT 483 string "Path to sysroot" 484 default BUSYBOX_DEFAULT_SYSROOT 485 help 486 If you want to build busybox with a cross compiler, then you 487 might also need to specify where /usr/include and /usr/lib 488 will be found. 489 490 For example, busybox can be built against an installed 491 Android NDK, platform version 9, for ARM ABI with 492 493 CONFIG_SYSROOT=/opt/android-ndk/platforms/android-9/arch-arm 494 495 Native builds leave this empty. 496 497 config BUSYBOX_CONFIG_EXTRA_CFLAGS 498 string "Additional CFLAGS" 499 default BUSYBOX_DEFAULT_EXTRA_CFLAGS 500 help 501 Additional CFLAGS to pass to the compiler verbatim. 502 503 config BUSYBOX_CONFIG_EXTRA_LDFLAGS 504 string "Additional LDFLAGS" 505 default BUSYBOX_DEFAULT_EXTRA_LDFLAGS 506 help 507 Additional LDFLAGS to pass to the linker verbatim. 508 509 config BUSYBOX_CONFIG_EXTRA_LDLIBS 510 string "Additional LDLIBS" 511 default BUSYBOX_DEFAULT_EXTRA_LDLIBS 512 help 513 Additional LDLIBS to pass to the linker with -l. 514 515 config BUSYBOX_CONFIG_USE_PORTABLE_CODE 516 bool "Avoid using GCC-specific code constructs" 517 default BUSYBOX_DEFAULT_USE_PORTABLE_CODE 518 help 519 Use this option if you are trying to compile busybox with 520 compiler other than gcc. 521 If you do use gcc, this option may needlessly increase code size. 522 523 config BUSYBOX_CONFIG_STACK_OPTIMIZATION_386 524 bool "Use -mpreferred-stack-boundary=2 on i386 arch" 525 default BUSYBOX_DEFAULT_STACK_OPTIMIZATION_386 526 help 527 This option makes for smaller code, but some libc versions 528 do not work with it (they use SSE instructions without 529 ensuring stack alignment). 530 531 config BUSYBOX_CONFIG_STATIC_LIBGCC 532 bool "Use -static-libgcc" 533 default BUSYBOX_DEFAULT_STATIC_LIBGCC 534 help 535 This option instructs gcc to link in a static version of its 536 support library, libgcc. This means that the binary will require 537 one fewer dynamic library at run time. 538 539 comment 'Installation Options ("make install" behavior)' 540 541 choice 542 prompt "What kind of applet links to install" 543 default BUSYBOX_CONFIG_INSTALL_APPLET_SYMLINKS 544 help 545 Choose what kind of links to applets are created by "make install". 546 547 config BUSYBOX_CONFIG_INSTALL_APPLET_SYMLINKS 548 bool "as soft-links" 549 help 550 Install applets as soft-links to the busybox binary. This needs some 551 free inodes on the filesystem, but might help with filesystem 552 generators that can't cope with hard-links. 553 554 config BUSYBOX_CONFIG_INSTALL_APPLET_HARDLINKS 555 bool "as hard-links" 556 help 557 Install applets as hard-links to the busybox binary. This might 558 count on a filesystem with few inodes. 559 560 config BUSYBOX_CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS 561 bool "as script wrappers" 562 help 563 Install applets as script wrappers that call the busybox binary. 564 565 config BUSYBOX_CONFIG_INSTALL_APPLET_DONT 566 bool "not installed" 567 help 568 Do not install applet links. Useful when you plan to use 569 busybox --install for installing links, or plan to use 570 a standalone shell and thus don't need applet links. 571 572 endchoice 573 574 choice 575 prompt "/bin/sh applet link" 576 default BUSYBOX_CONFIG_INSTALL_SH_APPLET_SYMLINK 577 depends on BUSYBOX_CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS 578 help 579 Choose how you install /bin/sh applet link. 580 581 config BUSYBOX_CONFIG_INSTALL_SH_APPLET_SYMLINK 582 bool "as soft-link" 583 help 584 Install /bin/sh applet as soft-link to the busybox binary. 585 586 config BUSYBOX_CONFIG_INSTALL_SH_APPLET_HARDLINK 587 bool "as hard-link" 588 help 589 Install /bin/sh applet as hard-link to the busybox binary. 590 591 config BUSYBOX_CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER 592 bool "as script wrapper" 593 help 594 Install /bin/sh applet as script wrapper that calls 595 the busybox binary. 596 597 endchoice 598 599 config BUSYBOX_CONFIG_PREFIX 600 string "Destination path for 'make install'" 601 default BUSYBOX_DEFAULT_PREFIX 602 help 603 Where "make install" should install busybox binary and links. 604 605 comment 'Debugging Options' 606 607 config BUSYBOX_CONFIG_DEBUG 608 bool "Build with debug information" 609 default BUSYBOX_DEFAULT_DEBUG 610 help 611 Say Y here to compile with debug information. 612 This increases the size of the binary considerably, and 613 should only be used when doing development. 614 615 This adds -g option to gcc command line. 616 617 Most people should answer N. 618 619 config BUSYBOX_CONFIG_DEBUG_PESSIMIZE 620 bool "Disable compiler optimizations" 621 default BUSYBOX_DEFAULT_DEBUG_PESSIMIZE 622 depends on BUSYBOX_CONFIG_DEBUG 623 help 624 The compiler's optimization of source code can eliminate and reorder 625 code, resulting in an executable that's hard to understand when 626 stepping through it with a debugger. This switches it off, resulting 627 in a much bigger executable that more closely matches the source 628 code. 629 630 This replaces -Os/-O2 with -O0 in gcc command line. 631 632 config BUSYBOX_CONFIG_DEBUG_SANITIZE 633 bool "Enable runtime sanitizers (ASAN/LSAN/USAN/etc...)" 634 default BUSYBOX_DEFAULT_DEBUG_SANITIZE 635 help 636 Say Y here if you want to enable runtime sanitizers. These help 637 catch bad memory accesses (e.g. buffer overflows), but will make 638 the executable larger and slow down runtime a bit. 639 640 This adds -fsanitize=foo options to gcc command line. 641 642 If you aren't developing/testing busybox, say N here. 643 644 config BUSYBOX_CONFIG_UNIT_TEST 645 bool "Build unit tests" 646 default BUSYBOX_DEFAULT_UNIT_TEST 647 help 648 Say Y here if you want to build unit tests (both the framework and 649 test cases) as an applet. This results in bigger code, so you 650 probably don't want this option in production builds. 651 652 config BUSYBOX_CONFIG_WERROR 653 bool "Abort compilation on any warning" 654 default BUSYBOX_DEFAULT_WERROR 655 help 656 This adds -Werror to gcc command line. 657 658 Most people should answer N. 659 660 config BUSYBOX_CONFIG_WARN_SIMPLE_MSG 661 bool "Warn about single parameter bb_xx_msg calls" 662 default BUSYBOX_DEFAULT_WARN_SIMPLE_MSG 663 help 664 This will cause warnings to be shown for any instances of 665 bb_error_msg(), bb_error_msg_and_die(), bb_perror_msg(), 666 bb_perror_msg_and_die(), bb_herror_msg() or bb_herror_msg_and_die() 667 being called with a single parameter. In these cases the equivalent 668 bb_simple_xx_msg function should be used instead. 669 Note that use of STRERROR_FMT may give false positives. 670 671 If you aren't developing busybox, say N here. 672 673 choice 674 prompt "Additional debugging library" 675 default BUSYBOX_CONFIG_NO_DEBUG_LIB 676 help 677 Using an additional debugging library will make busybox become 678 considerably larger and will cause it to run more slowly. You 679 should always leave this option disabled for production use. 680 681 dmalloc support: 682 ---------------- 683 This enables compiling with dmalloc ( http://dmalloc.com/ ) 684 which is an excellent public domain mem leak and malloc problem 685 detector. To enable dmalloc, before running busybox you will 686 want to properly set your environment, for example: 687 export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile 688 The 'debug=' value is generated using the following command 689 dmalloc -p log-stats -p log-non-free -p log-bad-space \ 690 -p log-elapsed-time -p check-fence -p check-heap \ 691 -p check-lists -p check-blank -p check-funcs -p realloc-copy \ 692 -p allow-free-null 693 694 Electric-fence support: 695 ----------------------- 696 This enables compiling with Electric-fence support. Electric 697 fence is another very useful malloc debugging library which uses 698 your computer's virtual memory hardware to detect illegal memory 699 accesses. This support will make busybox be considerably larger 700 and run slower, so you should leave this option disabled unless 701 you are hunting a hard to find memory problem. 702 703 704 config BUSYBOX_CONFIG_NO_DEBUG_LIB 705 bool "None" 706 707 config BUSYBOX_CONFIG_DMALLOC 708 bool "Dmalloc" 709 710 config BUSYBOX_CONFIG_EFENCE 711 bool "Electric-fence" 712 713 endchoice 714 715 source "libbb/Config.in" 716 717 endmenu 718 719 comment "Applets" 720 721 source "archival/Config.in" 722 source "coreutils/Config.in" 723 source "console-tools/Config.in" 724 source "debianutils/Config.in" 725 source "klibc-utils/Config.in" 726 source "editors/Config.in" 727 source "findutils/Config.in" 728 source "init/Config.in" 729 source "loginutils/Config.in" 730 source "e2fsprogs/Config.in" 731 source "modutils/Config.in" 732 source "util-linux/Config.in" 733 source "miscutils/Config.in" 734 source "networking/Config.in" 735 source "printutils/Config.in" 736 source "mailutils/Config.in" 737 source "procps/Config.in" 738 source "runit/Config.in" 739 source "selinux/Config.in" 740 source "shell/Config.in" 741 source "sysklogd/Config.in"
其实,这些配置项就是busybox原本对应的所有配置项。只是名字不同而已。最后,在Makefile中会将这些配置项转换为busybox本身的配置文件。openwrt/package/utils/busybox/Makefile代码如下所示:
120 define Build/Configure 121 rm -f $(PKG_BUILD_DIR)/.config 122 touch $(PKG_BUILD_DIR)/.config 123 ifeq ($(DEVICE_TYPE),nas) 124 echo "CONFIG_HDPARM=y" >> $(PKG_BUILD_DIR)/.config 125 endif 126 ifeq ($(BUILD_VARIANT),selinux) 127 cat $(TOPDIR)/$(SOURCE)/selinux.config >> $(PKG_BUILD_DIR)/.config 128 endif 129 grep 'CONFIG_BUSYBOX_$(BUSYBOX_SYM)' $(TOPDIR)/.config | sed -e "s,\\(# \)\\?CONFIG_BUSYBOX_$(BUSYBOX_SYM)_\\(.*\\),\\1CONFIG_\\2,g" >> $(PKG_BUILD_DIR)/.config 130 yes 'n' | $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS) oldconfig 131 endef
其中,$(BUSYBOX_SYM)这个变量也是在Makefile中赋值的。这个变量被定义在openwrt/package/utils/busybox/Makefile文件的第25行中,具体如下所示:
25 BUSYBOX_SYM=$(if $(CONFIG_BUSYBOX_CUSTOM),CONFIG,DEFAULT)
这样一来我们就清楚了。在busybox的Makefile中,未选中CONFIG_BUSYBOX_CUSTOM的情况下,BUSYBOX_SYM的值为DEFAULT,则将CONFIG_BUSYBOX_DEFAULT_xxx筛选出来,处理为busybox最终的配置项,而这些CONFIG_BUSYBOX_DEFAULT_xxx是在Config-defaults.in文件中配置好的。
在选中了CONFIG_BUSYBOX_CUSTOM的情况下,则最终将CONFIG_BUSYBOX_CONFIG_xxx筛选出来使用。
接下来,我们就来看一下自定义的情况。自定义的情况其实也很清晰,就是引入了config目录下的配置项。这些配置项,跟busybox源码中的布局和内容完全一致,区别只是配置项的名字均以BUSYBOX_CONFIG开头,且默认值均为对应的以BUSYBOX_DEFAULT_开头的配置项。而这些BUSYBOX_DEFAULT_开头的配置项都是在Config-default.in中配置的。例如 openwrt/package/utils/busybox/config/init/Config.in文件中的例子:
1 # DO NOT EDIT. This file is generated from Config.src 2 # 3 # For a description of the syntax of this configuration file, 4 # see docs/Kconfig-language.txt. 5 # 6 7 menu "Init Utilities" 8 9 config BUSYBOX_CONFIG_BOOTCHARTD 10 bool "bootchartd (10 kb)" 11 default BUSYBOX_DEFAULT_BOOTCHARTD 12 help 13 bootchartd is commonly used to profile the boot process 14 for the purpose of speeding it up. In this case, it is started 15 by the kernel as the init process. This is configured by adding 16 the init=/sbin/bootchartd option to the kernel command line. 17 18 It can also be used to monitor the resource usage of a specific 19 application or the running system in general. In this case, 20 bootchartd is started interactively by running bootchartd start 21 and stopped using bootchartd stop. 22 23 config BUSYBOX_CONFIG_FEATURE_BOOTCHARTD_BLOATED_HEADER 24 bool "Compatible, bloated header" 25 default BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_BLOATED_HEADER 26 depends on BUSYBOX_CONFIG_BOOTCHARTD 27 help 28 Create extended header file compatible with "big" bootchartd. 29 "Big" bootchartd is a shell script and it dumps some 30 "convenient" info into the header, such as: 31 title = Boot chart for `hostname` (`date`) 32 system.uname = `uname -srvm` 33 system.release = `cat /etc/DISTRO-release` 34 system.cpu = `grep '^model name' /proc/cpuinfo | head -1` ($cpucount) 35 system.kernel.options = `cat /proc/cmdline` 36 This data is not mandatory for bootchart graph generation, 37 and is considered bloat. Nevertheless, this option 38 makes bootchartd applet to dump a subset of it. 39 40 config BUSYBOX_CONFIG_FEATURE_BOOTCHARTD_CONFIG_FILE 41 bool "Support bootchartd.conf" 42 default BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_CONFIG_FILE 43 depends on BUSYBOX_CONFIG_BOOTCHARTD 44 help 45 Enable reading and parsing of $PWD/bootchartd.conf 46 and /etc/bootchartd.conf files. 47 config BUSYBOX_CONFIG_HALT 48 bool "halt (4 kb)" 49 default BUSYBOX_DEFAULT_HALT 50 help 51 Stop all processes and halt the system. 52 53 config BUSYBOX_CONFIG_POWEROFF 54 bool "poweroff (4 kb)" 55 default BUSYBOX_DEFAULT_POWEROFF 56 help 57 Stop all processes and power off the system. 58 59 config BUSYBOX_CONFIG_REBOOT 60 bool "reboot (4 kb)" 61 default BUSYBOX_DEFAULT_REBOOT 62 help 63 Stop all processes and reboot the system. 64 65 config BUSYBOX_CONFIG_FEATURE_WAIT_FOR_INIT 66 bool "Before signaling init, make sure it is ready for it" 67 default BUSYBOX_DEFAULT_FEATURE_WAIT_FOR_INIT 68 depends on BUSYBOX_CONFIG_HALT || BUSYBOX_CONFIG_POWEROFF || BUSYBOX_CONFIG_REBOOT 69 help 70 In rare cases, poweroff may be commanded by firmware to OS 71 even before init process exists. On Linux, this spawns 72 "/sbin/poweroff" very early. This option adds code 73 which checks that init is ready to receive poweroff 74 commands. Code size increase of ~80 bytes. 75 76 config BUSYBOX_CONFIG_FEATURE_CALL_TELINIT 77 bool "Call telinit on shutdown and reboot" 78 default BUSYBOX_DEFAULT_FEATURE_CALL_TELINIT 79 depends on (BUSYBOX_CONFIG_HALT || BUSYBOX_CONFIG_POWEROFF || BUSYBOX_CONFIG_REBOOT) && !BUSYBOX_CONFIG_INIT 80 help 81 Call an external program (normally telinit) to facilitate 82 a switch to a proper runlevel. 83 84 This option is only available if you selected halt and friends, 85 but did not select init. 86 87 config BUSYBOX_CONFIG_TELINIT_PATH 88 string "Path to telinit executable" 89 default BUSYBOX_DEFAULT_TELINIT_PATH 90 depends on BUSYBOX_CONFIG_FEATURE_CALL_TELINIT 91 help 92 When busybox halt and friends have to call external telinit 93 to facilitate proper shutdown, this path is to be used when 94 locating telinit executable. 95 config BUSYBOX_CONFIG_INIT 96 bool "init (10 kb)" 97 default BUSYBOX_DEFAULT_INIT 98 select BUSYBOX_CONFIG_FEATURE_SYSLOG 99 help 100 init is the first program run when the system boots. 101 102 config BUSYBOX_CONFIG_LINUXRC 103 bool "linuxrc: support running init from initrd (not initramfs)" 104 default BUSYBOX_DEFAULT_LINUXRC 105 select BUSYBOX_CONFIG_FEATURE_SYSLOG 106 help 107 Legacy support for running init under the old-style initrd. Allows 108 the name linuxrc to act as init, and it doesn't assume init is PID 1. 109 110 This does not apply to initramfs, which runs /init as PID 1 and 111 requires no special support. 112 113 config BUSYBOX_CONFIG_FEATURE_USE_INITTAB 114 bool "Support reading an inittab file" 115 default BUSYBOX_DEFAULT_FEATURE_USE_INITTAB 116 depends on BUSYBOX_CONFIG_INIT || BUSYBOX_CONFIG_LINUXRC 117 help 118 Allow init to read an inittab file when the system boot. 119 120 config BUSYBOX_CONFIG_FEATURE_KILL_REMOVED 121 bool "Support killing processes that have been removed from inittab" 122 default BUSYBOX_DEFAULT_FEATURE_KILL_REMOVED 123 depends on BUSYBOX_CONFIG_FEATURE_USE_INITTAB 124 help 125 When respawn entries are removed from inittab and a SIGHUP is 126 sent to init, this option will make init kill the processes 127 that have been removed. 128 129 config BUSYBOX_CONFIG_FEATURE_KILL_DELAY 130 int "How long to wait between TERM and KILL (0 - send TERM only)" if FEATURE_KILL_REMOVED 131 range 0 1024 132 default BUSYBOX_DEFAULT_FEATURE_KILL_DELAY 133 depends on BUSYBOX_CONFIG_FEATURE_KILL_REMOVED 134 help 135 With nonzero setting, init sends TERM, forks, child waits N 136 seconds, sends KILL and exits. Setting it too high is unwise 137 (child will hang around for too long and could actually kill 138 the wrong process!) 139 140 config BUSYBOX_CONFIG_FEATURE_INIT_SCTTY 141 bool "Run commands with leading dash with controlling tty" 142 default BUSYBOX_DEFAULT_FEATURE_INIT_SCTTY 143 depends on BUSYBOX_CONFIG_INIT || BUSYBOX_CONFIG_LINUXRC 144 help 145 If this option is enabled, init will try to give a controlling 146 tty to any command which has leading hyphen (often it's "-/bin/sh"). 147 More precisely, init will do "ioctl(STDIN_FILENO, TIOCSCTTY, 0)". 148 If device attached to STDIN_FILENO can be a ctty but is not yet 149 a ctty for other session, it will become this process' ctty. 150 This is not the traditional init behavour, but is often what you want 151 in an embedded system where the console is only accessed during 152 development or for maintenance. 153 NB: using cttyhack applet may work better. 154 155 config BUSYBOX_CONFIG_FEATURE_INIT_SYSLOG 156 bool "Enable init to write to syslog" 157 default BUSYBOX_DEFAULT_FEATURE_INIT_SYSLOG 158 depends on BUSYBOX_CONFIG_INIT || BUSYBOX_CONFIG_LINUXRC 159 help 160 If selected, some init messages are sent to syslog. 161 Otherwise, they are sent to VT #5 if linux virtual tty is detected 162 (if not, no separate logging is done). 163 164 config BUSYBOX_CONFIG_FEATURE_INIT_QUIET 165 bool "Be quiet on boot (no 'init started:' message)" 166 default BUSYBOX_DEFAULT_FEATURE_INIT_QUIET 167 depends on BUSYBOX_CONFIG_INIT || BUSYBOX_CONFIG_LINUXRC 168 169 config BUSYBOX_CONFIG_FEATURE_INIT_COREDUMPS 170 bool "Support dumping core for child processes (debugging only)" 171 default BUSYBOX_DEFAULT_FEATURE_INIT_COREDUMPS # not Y because this is a debug option 172 depends on BUSYBOX_CONFIG_INIT || BUSYBOX_CONFIG_LINUXRC 173 help 174 If this option is enabled and the file /.init_enable_core 175 exists, then init will call setrlimit() to allow unlimited 176 core file sizes. If this option is disabled, processes 177 will not generate any core files. 178 179 config BUSYBOX_CONFIG_INIT_TERMINAL_TYPE 180 string "Initial terminal type" 181 default BUSYBOX_DEFAULT_INIT_TERMINAL_TYPE 182 depends on BUSYBOX_CONFIG_INIT || BUSYBOX_CONFIG_LINUXRC 183 help 184 This is the initial value set by init for the TERM environment 185 variable. This variable is used by programs which make use of 186 extended terminal capabilities. 187 188 Note that on Linux, init attempts to detect serial terminal and 189 sets TERM to "vt102" if one is found. 190 191 config BUSYBOX_CONFIG_FEATURE_INIT_MODIFY_CMDLINE 192 bool "Clear init's command line" 193 default BUSYBOX_DEFAULT_FEATURE_INIT_MODIFY_CMDLINE 194 depends on BUSYBOX_CONFIG_INIT || BUSYBOX_CONFIG_LINUXRC 195 help 196 When launched as PID 1 and after parsing its arguments, init 197 wipes all the arguments but argv[0] and rewrites argv[0] to 198 contain only "init", so that its command line appears solely as 199 "init" in tools such as ps. 200 If this option is set to Y, init will keep its original behavior, 201 otherwise, all the arguments including argv[0] will be preserved, 202 be they parsed or ignored by init. 203 The original command-line used to launch init can then be 204 retrieved in /proc/1/cmdline on Linux, for example. 205 206 endmenu
也就是说,当用户需要自定义的时候引入了BUSYBOX_CONFIG_xxx的配置项。但是,其默认值还是用以前已经配置好的。此时,要自定义的话就在这个基础上进行修改即可。
最终用户的配置就体现在BUSYBOX_CONFIG_xxx的配置项上。如前面介绍的那样,在选中了CONFIG_BUSYBOX_CUSTOM的情况下,BUSYBOX_SYM的值为CONFIG,则将CONFIG_BUSYBOX_CONFIG_xxx筛选出来,处理为busybox最终的配置项。
3、配置项文件的生成
搞清楚了如何集成之后,接下来的问题就是,这些BUSYBOX_DEFAULT_xxx 和 BUSYBOX_CONFIG_xxx 的配置文件,是怎么来的,如此多的配置项,肯定不可能时手工修改的,必然有自动化处理。
是的,这些BUSYBOX_CONFIG_xxx配置项,就是从busybox本身的配置项生成而来。而这些BUSYBOX_DEFAULT_xxx的默认配置值,其实就是从一份配置好的busybox.config文件生成而来。在busybox的包中,就提供了两个脚本 convert_defaults.pl 和 convert_menuconfig.pl,用来生成配置项和默认配置值
4、使软件包随配置项改变而重新编译
一般软件包在编译过一次之后,如果源码没有改动,则下次make无须重新编译。
但对于busybox这种包,源码未变,配置改变了的话,也是需要重新编译的。现在的问题在于,用户修改配置项,是在openwrt的.config修改,根本不会改动到busybox这个目录下的文件。
那么busybox包就需要有一个方法,来监控配置项的变动。如果配置项变化,则需要重新编译。如何监控呢?从makefile中也可以找到答案,正如openwrt/package/utils/busybox/Makefile文件中如下代码那样。
34 ifeq ($(DUMP),) 35 STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell grep '^CONFIG_BUSYBOX_' $(TOPDIR)/.config | $(MKHASH) md5) 36 endif
此处设置了STAMP_CONFIGURED变量,这个变量的值,是将.config中所有CONFIG_BUSYBOX_滤出,再做md5得到的值。一旦这些配置项发生变化,则md5的值会改变,STAMP_CONFIGURED的值也会改变。编译包的时候,就能判断出需要重新编译。
具体的,STAMP_CONFIGURED值是在package.mk中使用。这里还有其他的类似变量,只要改变了,就说明需要重新执行对应的操作。如STAMP_CONFIGURED,STAMP_BUILT,STAMP_INSTALLED等。
这个配置项,也会在软件包的编译目录体现出来。如果没有对其赋值,则在编译目录下,可看到名字类似 .configured_yyy 的隐藏文件。
对其进行赋值之后,这个文件的形式会变成 .configured_yyy_622f380fff06dde988852308f044653b 这种形式,后面跟着的就是由配置项生产的md5值。
5、总结
弄清楚OpenWRT集成busybox配置的套路之后,修改一下convert_defaults.pl 和 convert_menuconfig.pl文件,就可以套用到其他软件包上了。
============= End
标签:集成,busybox,help,BUSYBOX,DEFAULT,CONFIG,config,OpenWRT From: https://www.cnblogs.com/lsgxeva/p/17930019.html