blob: 92674385098053e366c2d1e04dfd214db5db8137 [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.
bigbiff bigbiff6af36a42019-04-23 20:05:28 -040046 BSD_TOOLS :=
Matt Mower92084af2015-02-19 13:19:47 -060047
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050048 OUR_TOOLS := \
Ivan Kutepovff9d0972018-03-21 23:05:39 +030049 newfs_msdos
50
51 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 26; echo $$?),0)
52 OUR_TOOLS += \
53 iftop \
54 ioctl \
55 nandread \
56 prlimit \
57 sendevent \
58 start \
59 stop
60 endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050061
bigbiff bigbiff6af36a42019-04-23 20:05:28 -040062 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050063 BSD_TOOLS += \
64 dd \
bigbiff bigbiff6af36a42019-04-23 20:05:28 -040065 du \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050066
Hashcode57332152016-12-20 01:30:49 +010067 OUR_TOOLS += \
68 df \
69 ionice \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050070 log \
Hashcode57332152016-12-20 01:30:49 +010071 ls \
72 lsof \
73 mount \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050074 ps \
Hashcode57332152016-12-20 01:30:49 +010075 renice \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050076 top \
Hashcode57332152016-12-20 01:30:49 +010077 uptime \
78 watchprops
79 endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050080 else
81 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
82 OUR_TOOLS += \
83 mknod \
84 nohup
85 BSD_TOOLS := \
86 cat \
87 chown \
88 cp \
89 dd \
90 du \
91 grep \
92 kill \
93 ln \
94 mv \
95 printenv \
96 rm \
97 rmdir \
98 sleep \
99 sync
100 else
101 OUR_TOOLS += \
102 cat \
103 chown \
104 dd \
105 du \
106 kill \
107 ln \
108 mv \
109 printenv \
110 rm \
111 rmdir \
112 setconsole \
113 sleep \
114 sync
115 endif
116
117 OUR_TOOLS += \
118 chmod \
119 clear \
120 cmp \
121 date \
122 df \
123 dmesg \
124 getevent \
125 hd \
126 id \
127 ifconfig \
128 iftop \
129 insmod \
130 ioctl \
131 ionice \
132 log \
133 lsmod \
134 lsof \
135 md5 \
136 mkdir \
137 mkswap \
138 mount \
139 nandread \
140 netstat \
141 newfs_msdos \
142 notify \
143 ps \
144 readlink \
145 renice \
146 rmmod \
147 route \
148 schedtop \
149 sendevent \
150 smd \
151 swapoff \
152 swapon \
153 top \
154 touch \
155 umount \
156 uptime \
157 vmstat \
158 watchprops \
159 wipe
Matt Mower92084af2015-02-19 13:19:47 -0600160 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500161endif
162
Ethan Yonker58f21322018-08-24 11:17:36 -0500163ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
164 # Special rules for 9.0
165 OUR_TOOLS += getevent
166 LOCAL_C_INCLUDES += $(TWRP_TOOLBOX_PATH)
167 LOCAL_WHOLE_STATIC_LIBRARIES += libtoolbox_dd
bigbiff bigbiff6af36a42019-04-23 20:05:28 -0400168
Ethan Yonker58f21322018-08-24 11:17:36 -0500169 ifneq ($(TW_USE_TOOLBOX), true)
170 OUR_TOOLS += newfs_msdos
171 endif
172endif
173
Matt Mower92084af2015-02-19 13:19:47 -0600174ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
175 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
176 OUR_TOOLS += r
177 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600178endif
179
Dees Troy8d66f8b2013-10-08 14:04:55 +0000180LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600181 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600182 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000183
Matt Mower92084af2015-02-19 13:19:47 -0600184ifneq ($(wildcard system/core/toolbox/dynarray.c),)
185 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600186endif
187
Matt Mower92084af2015-02-19 13:19:47 -0600188ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
189 LOCAL_SRC_FILES += \
190 pwcache.c \
191 upstream-netbsd/lib/libc/gen/getbsize.c \
192 upstream-netbsd/lib/libc/gen/humanize_number.c \
193 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
194 upstream-netbsd/lib/libc/string/swab.c \
195 upstream-netbsd/lib/libutil/raise_default_signal.c
196endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000197
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500198ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600199 LOCAL_CFLAGS += \
200 -std=gnu99 \
201 -Werror -Wno-unused-parameter \
202 -I$(LOCAL_PATH)/upstream-netbsd/include \
203 -include bsd-compatibility.h
204endif
205
206ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
207 LOCAL_C_INCLUDES += external/openssl/include
208else
209 LOCAL_C_INCLUDES += bionic/libc/bionic
210endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000211
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600212LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000213
Matt Mower92084af2015-02-19 13:19:47 -0600214ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
215 ifeq ($(TW_USE_TOOLBOX), true)
216 LOCAL_SHARED_LIBRARIES += libcrypto
217 endif
218else
219 LOCAL_SHARED_LIBRARIES += \
220 libc \
221 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000222endif
223
Matt Mower87413642017-01-17 21:14:46 -0600224LOCAL_SHARED_LIBRARIES += libselinux
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600225
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500226ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600227 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
228 # The linker strips out all the unused library code in the normal case.
229 LOCAL_STATIC_LIBRARIES := libusbhost
230 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
231endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600232
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500233ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600234 # Rule to make getprop and setprop in M trees where toybox normally
235 # provides these tools. Toybox does not allow for easy dynamic
236 # configuration, so we would have to include the entire toybox binary
237 # which takes up more space than is necessary so long as we are still
238 # including busybox.
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500239ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600240 LOCAL_SRC_FILES += \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500241 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \
242 ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker58f21322018-08-24 11:17:36 -0500243 OUR_TOOLS += setprop
244 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; echo $$?),0)
245 # Special rules for <= 8.1
246 LOCAL_SRC_FILES += \
247 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c
248 OUR_TOOLS += getprop
249 endif
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500250endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600251endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500252ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
Ethan Yonker58f21322018-08-24 11:17:36 -0500253 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; echo $$?),0)
Ethan Yonkerf1179622016-08-25 15:32:21 -0500254 # Rule for making start and stop in N trees
255 LOCAL_SRC_FILES += \
256 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
257 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
258 OUR_TOOLS += start stop
Ethan Yonker58f21322018-08-24 11:17:36 -0500259 endif
260endif
261ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
262 LOCAL_SRC_FILES += getprop.cpp
263 LOCAL_SHARED_LIBRARIES += libbase
264 LOCAL_STATIC_LIBRARIES += libpropertyinfoparser
265 LOCAL_CPPFLAGS += -std=c++17
266 OUR_TOOLS += getprop
Ethan Yonkerf1179622016-08-25 15:32:21 -0500267endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600268
Dees Troy8d66f8b2013-10-08 14:04:55 +0000269LOCAL_MODULE := toolbox_recovery
270LOCAL_MODULE_STEM := toolbox
271LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600272LOCAL_MODULE_TAGS := optional
Ethan Yonker58f21322018-08-24 11:17:36 -0500273LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-const-variable
Dees Troy8d66f8b2013-10-08 14:04:55 +0000274
Matt Mower92084af2015-02-19 13:19:47 -0600275# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000276include $(BUILD_EXECUTABLE)
277
278$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
279
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500280ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600281 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
282else
283 ALL_TOOLS := $(OUR_TOOLS)
284endif
285
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100286TOOLS_H := $(intermediates)/tools.h
287$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
288$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100289$(TOOLS_H):
290 $(transform-generated-source)
291
lambdadroidead0f492019-05-12 11:48:04 +0200292# toolbox setenforce is used during init in non-symlink form, so it was
293# required to be included as part of the suite above. if busybox already
294# provides setenforce, we can omit the toolbox symlink
295TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
296ALL_TOOLS := $(TEMP_TOOLS)
297
298# Make /sbin/toolbox launchers for each tool
299SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
300$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
301$(SYMLINKS): $(LOCAL_INSTALLED_MODULE)
302 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
303 @mkdir -p $(dir $@)
304 @rm -rf $@
305 $(hide) ln -sf $(TOOLBOX_BINARY) $@
306
307include $(CLEAR_VARS)
308LOCAL_MODULE := toolbox_symlinks
309LOCAL_MODULE_TAGS := optional
310LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
311include $(BUILD_PHONY_PACKAGE)
312
313ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
314 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
315 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
316 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
317 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
318endif
bigbiff bigbiff6af36a42019-04-23 20:05:28 -0400319
320ifeq ($(TW_USE_TOOLBOX), true)
321 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
322 include $(CLEAR_VARS)
323 LOCAL_MODULE := dd_twrp
324 LOCAL_MODULE_STEM := dd
325 LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
326 LOCAL_MODULE_TAGS := optional
327 LOCAL_CFLAGS := -include bsd-compatibility.h -DNO_CONV -Wno-unused-parameter
328 LOCAL_C_INCLUDES := system/core/toolbox/upstream-netbsd/include/ system/core/toolbox/upstream-netbsd/bin/dd system/core/toolbox
329
330 LOCAL_SHARED_LIBRARIES := \
331 libcutils \
332
333 LOCAL_SRC_FILES += \
334 upstream-netbsd/bin/dd/args.c \
335 upstream-netbsd/bin/dd/conv.c \
336 upstream-netbsd/bin/dd/dd.c \
337 upstream-netbsd/bin/dd/dd_hostops.c \
338 upstream-netbsd/bin/dd/misc.c \
339 upstream-netbsd/bin/dd/position.c \
340 upstream-netbsd/lib/libc/gen/getbsize.c \
341 upstream-netbsd/lib/libc/gen/humanize_number.c \
342 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
343 upstream-netbsd/lib/libc/string/swab.c \
344 upstream-netbsd/lib/libutil/raise_default_signal.c
345
346 include $(BUILD_EXECUTABLE)
347 endif
348endif
349
Ethan Yonker75bf0412014-11-21 13:54:27 -0600350SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600351ALL_TOOLS :=
352BSD_TOOLS :=
353OUR_TOOLS :=
354TEMP_TOOLS :=
355TOOLS_FOR_SELINUX :=