blob: b8f4d2e7490e36f60520f4bba52798f20584a88b [file] [log] [blame]
Ethan Yonker6bb26b52016-01-10 22:26:51 -06001TWRP_TOOLBOX_PATH := $(call my-dir)
Matt Mower92084af2015-02-19 13:19:47 -06002LOCAL_PATH := system/core/toolbox
Dees Troy8d66f8b2013-10-08 14:04:55 +00003include $(CLEAR_VARS)
4
Ethan Yonkerf1179622016-08-25 15:32:21 -05005OUR_TOOLS :=
6
7ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
8 OUR_TOOLS := \
9 start \
10 stop
11endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050012
13ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
14 OUR_TOOLS += \
15 getprop \
16 setprop
17endif
Dees Troy8d66f8b2013-10-08 14:04:55 +000018
Matt Mower81742fb2014-09-01 14:40:52 -050019# If busybox does not have SELinux support, provide these tools with toolbox.
20# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true.
Matt Mower87413642017-01-17 21:14:46 -060021TOOLS_FOR_SELINUX := \
22 ls
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050023
Matt Mower87413642017-01-17 21:14:46 -060024ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
25 TOOLS_FOR_SELINUX += \
26 load_policy \
27 getenforce \
28 chcon \
29 restorecon \
30 runcon \
31 getsebool \
32 setsebool
33endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050034
Matt Mower87413642017-01-17 21:14:46 -060035OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000036
Matt Mower87413642017-01-17 21:14:46 -060037# toolbox setenforce is used during init, so it needs to be included here
38# symlink is omitted at the very end if busybox already provides this
39ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
40 OUR_TOOLS += setenforce
Matt Mower92084af2015-02-19 13:19:47 -060041endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060042
Ethan Yonker5c933692014-04-04 11:26:32 -050043ifeq ($(TW_USE_TOOLBOX), true)
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050044 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
45 # These are the only toolbox tools in M. The rest are now in toybox.
Matt Mower92084af2015-02-19 13:19:47 -060046 BSD_TOOLS := \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050047 $(if $(filter $(PLATFORM_SDK_VERSION), 23 24), du)
Matt Mower92084af2015-02-19 13:19:47 -060048
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050049 OUR_TOOLS := \
Ethan Yonker95e80072017-08-24 21:45:50 -050050 $(if $(shell test $(PLATFORM_SDK_VERSION) -lt 26; iftop),) \
51 $(if $(shell test $(PLATFORM_SDK_VERSION) -lt 26; ioctl),) \
52 $(if $(shell test $(PLATFORM_SDK_VERSION) -lt 26; nandread),) \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050053 newfs_msdos \
Ethan Yonker95e80072017-08-24 21:45:50 -050054 $(if $(shell test $(PLATFORM_SDK_VERSION) -lt 26; prlimit),) \
55 $(if $(shell test $(PLATFORM_SDK_VERSION) -lt 26; sendevent),) \
56 $(if $(shell test $(PLATFORM_SDK_VERSION) -lt 26; start),) \
57 $(if $(shell test $(PLATFORM_SDK_VERSION) -lt 26; stop),) \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050058
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050059 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23))
60 BSD_TOOLS += \
61 dd \
62
Hashcode57332152016-12-20 01:30:49 +010063 OUR_TOOLS += \
64 df \
65 ionice \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050066 log \
Hashcode57332152016-12-20 01:30:49 +010067 ls \
68 lsof \
69 mount \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050070 ps \
Hashcode57332152016-12-20 01:30:49 +010071 renice \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050072 top \
Hashcode57332152016-12-20 01:30:49 +010073 uptime \
74 watchprops
75 endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050076 else
77 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
78 OUR_TOOLS += \
79 mknod \
80 nohup
81 BSD_TOOLS := \
82 cat \
83 chown \
84 cp \
85 dd \
86 du \
87 grep \
88 kill \
89 ln \
90 mv \
91 printenv \
92 rm \
93 rmdir \
94 sleep \
95 sync
96 else
97 OUR_TOOLS += \
98 cat \
99 chown \
100 dd \
101 du \
102 kill \
103 ln \
104 mv \
105 printenv \
106 rm \
107 rmdir \
108 setconsole \
109 sleep \
110 sync
111 endif
112
113 OUR_TOOLS += \
114 chmod \
115 clear \
116 cmp \
117 date \
118 df \
119 dmesg \
120 getevent \
121 hd \
122 id \
123 ifconfig \
124 iftop \
125 insmod \
126 ioctl \
127 ionice \
128 log \
129 lsmod \
130 lsof \
131 md5 \
132 mkdir \
133 mkswap \
134 mount \
135 nandread \
136 netstat \
137 newfs_msdos \
138 notify \
139 ps \
140 readlink \
141 renice \
142 rmmod \
143 route \
144 schedtop \
145 sendevent \
146 smd \
147 swapoff \
148 swapon \
149 top \
150 touch \
151 umount \
152 uptime \
153 vmstat \
154 watchprops \
155 wipe
Matt Mower92084af2015-02-19 13:19:47 -0600156 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500157endif
158
Matt Mower92084af2015-02-19 13:19:47 -0600159ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
160 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
161 OUR_TOOLS += r
162 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600163endif
164
Dees Troy8d66f8b2013-10-08 14:04:55 +0000165LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600166 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600167 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000168
Matt Mower92084af2015-02-19 13:19:47 -0600169ifneq ($(wildcard system/core/toolbox/dynarray.c),)
170 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600171endif
172
Matt Mower92084af2015-02-19 13:19:47 -0600173ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
174 LOCAL_SRC_FILES += \
175 pwcache.c \
176 upstream-netbsd/lib/libc/gen/getbsize.c \
177 upstream-netbsd/lib/libc/gen/humanize_number.c \
178 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
179 upstream-netbsd/lib/libc/string/swab.c \
180 upstream-netbsd/lib/libutil/raise_default_signal.c
181endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000182
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500183ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600184 LOCAL_CFLAGS += \
185 -std=gnu99 \
186 -Werror -Wno-unused-parameter \
187 -I$(LOCAL_PATH)/upstream-netbsd/include \
188 -include bsd-compatibility.h
189endif
190
191ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
192 LOCAL_C_INCLUDES += external/openssl/include
193else
194 LOCAL_C_INCLUDES += bionic/libc/bionic
195endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000196
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600197LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000198
Matt Mower92084af2015-02-19 13:19:47 -0600199ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
200 ifeq ($(TW_USE_TOOLBOX), true)
201 LOCAL_SHARED_LIBRARIES += libcrypto
202 endif
203else
204 LOCAL_SHARED_LIBRARIES += \
205 libc \
206 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000207endif
208
Matt Mower87413642017-01-17 21:14:46 -0600209LOCAL_SHARED_LIBRARIES += libselinux
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600210
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500211ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600212 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
213 # The linker strips out all the unused library code in the normal case.
214 LOCAL_STATIC_LIBRARIES := libusbhost
215 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
216endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600217
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500218ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600219 # Rule to make getprop and setprop in M trees where toybox normally
220 # provides these tools. Toybox does not allow for easy dynamic
221 # configuration, so we would have to include the entire toybox binary
222 # which takes up more space than is necessary so long as we are still
223 # including busybox.
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500224ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600225 LOCAL_SRC_FILES += \
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600226 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500227 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \
228 ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600229 OUR_TOOLS += getprop setprop
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500230endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600231endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500232ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
233 # Rule for making start and stop in N trees
234 LOCAL_SRC_FILES += \
235 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
236 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
237 OUR_TOOLS += start stop
238endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600239
Dees Troy8d66f8b2013-10-08 14:04:55 +0000240LOCAL_MODULE := toolbox_recovery
241LOCAL_MODULE_STEM := toolbox
242LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600243LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000244
Matt Mower92084af2015-02-19 13:19:47 -0600245# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000246include $(BUILD_EXECUTABLE)
247
248$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
249
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500250ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600251 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
252else
253 ALL_TOOLS := $(OUR_TOOLS)
254endif
255
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100256TOOLS_H := $(intermediates)/tools.h
257$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
258$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
259$(TOOLS_H): $(LOCAL_PATH)/Android.mk
260$(TOOLS_H):
261 $(transform-generated-source)
262
Matt Mower87413642017-01-17 21:14:46 -0600263# toolbox setenforce is used during init in non-symlink form, so it was
264# required to be included as part of the suite above. if busybox already
265# provides setenforce, we can omit the toolbox symlink
266TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
267ALL_TOOLS := $(TEMP_TOOLS)
Matt Mower92084af2015-02-19 13:19:47 -0600268
Matt Mower92084af2015-02-19 13:19:47 -0600269# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600270SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000271$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
272$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
273 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
274 @mkdir -p $(dir $@)
275 @rm -rf $@
276 $(hide) ln -sf $(TOOLBOX_BINARY) $@
277
Matt Mower031163b2014-11-01 15:13:03 -0500278include $(CLEAR_VARS)
279LOCAL_MODULE := toolbox_symlinks
280LOCAL_MODULE_TAGS := optional
281LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
282include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600283
Dees Troyb47f28b2014-12-11 17:20:59 +0000284ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600285 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
286 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
287 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
288 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000289endif
290
Ethan Yonker75bf0412014-11-21 13:54:27 -0600291SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600292ALL_TOOLS :=
293BSD_TOOLS :=
294OUR_TOOLS :=
295TEMP_TOOLS :=
296TOOLS_FOR_SELINUX :=