blob: 4a2546ed8e6c4d6e218831839a95d3c72feb5e22 [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)
bigbiffd58ba182020-03-23 10:02:29 -0400167 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
168 LOCAL_WHOLE_STATIC_LIBRARIES += libtoolbox_dd
169 endif
bigbiff bigbiff6af36a42019-04-23 20:05:28 -0400170
Ethan Yonker58f21322018-08-24 11:17:36 -0500171 ifneq ($(TW_USE_TOOLBOX), true)
172 OUR_TOOLS += newfs_msdos
173 endif
174endif
175
Matt Mower92084af2015-02-19 13:19:47 -0600176ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
177 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
178 OUR_TOOLS += r
179 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600180endif
181
Dees Troy8d66f8b2013-10-08 14:04:55 +0000182LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600183 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600184 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000185
Matt Mower92084af2015-02-19 13:19:47 -0600186ifneq ($(wildcard system/core/toolbox/dynarray.c),)
187 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600188endif
189
Matt Mower92084af2015-02-19 13:19:47 -0600190ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
191 LOCAL_SRC_FILES += \
192 pwcache.c \
193 upstream-netbsd/lib/libc/gen/getbsize.c \
194 upstream-netbsd/lib/libc/gen/humanize_number.c \
195 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
196 upstream-netbsd/lib/libc/string/swab.c \
197 upstream-netbsd/lib/libutil/raise_default_signal.c
198endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000199
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500200ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600201 LOCAL_CFLAGS += \
202 -std=gnu99 \
203 -Werror -Wno-unused-parameter \
204 -I$(LOCAL_PATH)/upstream-netbsd/include \
205 -include bsd-compatibility.h
206endif
207
208ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
209 LOCAL_C_INCLUDES += external/openssl/include
210else
211 LOCAL_C_INCLUDES += bionic/libc/bionic
212endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000213
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600214LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000215
Matt Mower92084af2015-02-19 13:19:47 -0600216ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
217 ifeq ($(TW_USE_TOOLBOX), true)
218 LOCAL_SHARED_LIBRARIES += libcrypto
219 endif
220else
221 LOCAL_SHARED_LIBRARIES += \
222 libc \
223 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000224endif
225
Matt Mower87413642017-01-17 21:14:46 -0600226LOCAL_SHARED_LIBRARIES += libselinux
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600227
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500228ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600229 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
230 # The linker strips out all the unused library code in the normal case.
231 LOCAL_STATIC_LIBRARIES := libusbhost
232 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
233endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600234
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500235ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600236 # Rule to make getprop and setprop in M trees where toybox normally
237 # provides these tools. Toybox does not allow for easy dynamic
238 # configuration, so we would have to include the entire toybox binary
239 # which takes up more space than is necessary so long as we are still
240 # including busybox.
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500241ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600242 LOCAL_SRC_FILES += \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500243 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \
244 ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker58f21322018-08-24 11:17:36 -0500245 OUR_TOOLS += setprop
246 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; echo $$?),0)
247 # Special rules for <= 8.1
248 LOCAL_SRC_FILES += \
249 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c
250 OUR_TOOLS += getprop
251 endif
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500252endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600253endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500254ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
Ethan Yonker58f21322018-08-24 11:17:36 -0500255 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; echo $$?),0)
Ethan Yonkerf1179622016-08-25 15:32:21 -0500256 # Rule for making start and stop in N trees
257 LOCAL_SRC_FILES += \
258 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
259 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
260 OUR_TOOLS += start stop
Ethan Yonker58f21322018-08-24 11:17:36 -0500261 endif
262endif
263ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
264 LOCAL_SRC_FILES += getprop.cpp
265 LOCAL_SHARED_LIBRARIES += libbase
266 LOCAL_STATIC_LIBRARIES += libpropertyinfoparser
267 LOCAL_CPPFLAGS += -std=c++17
268 OUR_TOOLS += getprop
Ethan Yonkerf1179622016-08-25 15:32:21 -0500269endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600270
Dees Troy8d66f8b2013-10-08 14:04:55 +0000271LOCAL_MODULE := toolbox_recovery
272LOCAL_MODULE_STEM := toolbox
273LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600274LOCAL_MODULE_TAGS := optional
Ethan Yonker58f21322018-08-24 11:17:36 -0500275LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-const-variable
Dees Troy8d66f8b2013-10-08 14:04:55 +0000276
Matt Mower92084af2015-02-19 13:19:47 -0600277# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000278include $(BUILD_EXECUTABLE)
279
280$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
281
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500282ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600283 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
284else
285 ALL_TOOLS := $(OUR_TOOLS)
286endif
287
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100288TOOLS_H := $(intermediates)/tools.h
289$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
290$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
bigbiffd58ba182020-03-23 10:02:29 -0400291$(TOOLS_H):
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100292 $(transform-generated-source)
293
lambdadroidead0f492019-05-12 11:48:04 +0200294# toolbox setenforce is used during init in non-symlink form, so it was
295# required to be included as part of the suite above. if busybox already
296# provides setenforce, we can omit the toolbox symlink
297TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
298ALL_TOOLS := $(TEMP_TOOLS)
299
300# Make /sbin/toolbox launchers for each tool
301SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
302$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
303$(SYMLINKS): $(LOCAL_INSTALLED_MODULE)
304 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
305 @mkdir -p $(dir $@)
306 @rm -rf $@
307 $(hide) ln -sf $(TOOLBOX_BINARY) $@
308
309include $(CLEAR_VARS)
310LOCAL_MODULE := toolbox_symlinks
311LOCAL_MODULE_TAGS := optional
Ethan Yonkerae7ff3b2019-05-24 16:31:09 -0500312LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
lambdadroidead0f492019-05-12 11:48:04 +0200313include $(BUILD_PHONY_PACKAGE)
314
315ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
316 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
317 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
318 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
319 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
320endif
bigbiff bigbiff6af36a42019-04-23 20:05:28 -0400321
322ifeq ($(TW_USE_TOOLBOX), true)
323 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
324 include $(CLEAR_VARS)
325 LOCAL_MODULE := dd_twrp
326 LOCAL_MODULE_STEM := dd
327 LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
328 LOCAL_MODULE_TAGS := optional
329 LOCAL_CFLAGS := -include bsd-compatibility.h -DNO_CONV -Wno-unused-parameter
330 LOCAL_C_INCLUDES := system/core/toolbox/upstream-netbsd/include/ system/core/toolbox/upstream-netbsd/bin/dd system/core/toolbox
331
332 LOCAL_SHARED_LIBRARIES := \
333 libcutils \
334
335 LOCAL_SRC_FILES += \
336 upstream-netbsd/bin/dd/args.c \
337 upstream-netbsd/bin/dd/conv.c \
338 upstream-netbsd/bin/dd/dd.c \
339 upstream-netbsd/bin/dd/dd_hostops.c \
340 upstream-netbsd/bin/dd/misc.c \
341 upstream-netbsd/bin/dd/position.c \
342 upstream-netbsd/lib/libc/gen/getbsize.c \
343 upstream-netbsd/lib/libc/gen/humanize_number.c \
344 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
345 upstream-netbsd/lib/libc/string/swab.c \
346 upstream-netbsd/lib/libutil/raise_default_signal.c
347
348 include $(BUILD_EXECUTABLE)
349 endif
350endif
351
Ethan Yonker75bf0412014-11-21 13:54:27 -0600352SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600353ALL_TOOLS :=
354BSD_TOOLS :=
355OUR_TOOLS :=
356TEMP_TOOLS :=
357TOOLS_FOR_SELINUX :=