blob: 7d1b602514108d68dc3e53691ec6af640a68686a [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 := \
Ivan Kutepovff9d0972018-03-21 23:05:39 +030050 newfs_msdos
51
52 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 26; echo $$?),0)
53 OUR_TOOLS += \
54 iftop \
55 ioctl \
56 nandread \
57 prlimit \
58 sendevent \
59 start \
60 stop
61 endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050062
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -050063 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23))
64 BSD_TOOLS += \
65 dd \
66
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
168 ifneq ($(TW_USE_TOOLBOX), true)
169 OUR_TOOLS += newfs_msdos
170 endif
171endif
172
Matt Mower92084af2015-02-19 13:19:47 -0600173ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
174 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
175 OUR_TOOLS += r
176 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600177endif
178
Dees Troy8d66f8b2013-10-08 14:04:55 +0000179LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600180 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600181 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000182
Matt Mower92084af2015-02-19 13:19:47 -0600183ifneq ($(wildcard system/core/toolbox/dynarray.c),)
184 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600185endif
186
Matt Mower92084af2015-02-19 13:19:47 -0600187ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
188 LOCAL_SRC_FILES += \
189 pwcache.c \
190 upstream-netbsd/lib/libc/gen/getbsize.c \
191 upstream-netbsd/lib/libc/gen/humanize_number.c \
192 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
193 upstream-netbsd/lib/libc/string/swab.c \
194 upstream-netbsd/lib/libutil/raise_default_signal.c
195endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000196
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500197ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600198 LOCAL_CFLAGS += \
199 -std=gnu99 \
200 -Werror -Wno-unused-parameter \
201 -I$(LOCAL_PATH)/upstream-netbsd/include \
202 -include bsd-compatibility.h
203endif
204
205ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
206 LOCAL_C_INCLUDES += external/openssl/include
207else
208 LOCAL_C_INCLUDES += bionic/libc/bionic
209endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000210
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600211LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000212
Matt Mower92084af2015-02-19 13:19:47 -0600213ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
214 ifeq ($(TW_USE_TOOLBOX), true)
215 LOCAL_SHARED_LIBRARIES += libcrypto
216 endif
217else
218 LOCAL_SHARED_LIBRARIES += \
219 libc \
220 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000221endif
222
Matt Mower87413642017-01-17 21:14:46 -0600223LOCAL_SHARED_LIBRARIES += libselinux
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600224
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500225ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600226 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
227 # The linker strips out all the unused library code in the normal case.
228 LOCAL_STATIC_LIBRARIES := libusbhost
229 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
230endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600231
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500232ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600233 # Rule to make getprop and setprop in M trees where toybox normally
234 # provides these tools. Toybox does not allow for easy dynamic
235 # configuration, so we would have to include the entire toybox binary
236 # which takes up more space than is necessary so long as we are still
237 # including busybox.
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500238ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600239 LOCAL_SRC_FILES += \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500240 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \
241 ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker58f21322018-08-24 11:17:36 -0500242 OUR_TOOLS += setprop
243 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; echo $$?),0)
244 # Special rules for <= 8.1
245 LOCAL_SRC_FILES += \
246 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c
247 OUR_TOOLS += getprop
248 endif
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500249endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600250endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500251ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
Ethan Yonker58f21322018-08-24 11:17:36 -0500252 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 28; echo $$?),0)
Ethan Yonkerf1179622016-08-25 15:32:21 -0500253 # Rule for making start and stop in N trees
254 LOCAL_SRC_FILES += \
255 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
256 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
257 OUR_TOOLS += start stop
Ethan Yonker58f21322018-08-24 11:17:36 -0500258 endif
259endif
260ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
261 LOCAL_SRC_FILES += getprop.cpp
262 LOCAL_SHARED_LIBRARIES += libbase
263 LOCAL_STATIC_LIBRARIES += libpropertyinfoparser
264 LOCAL_CPPFLAGS += -std=c++17
265 OUR_TOOLS += getprop
Ethan Yonkerf1179622016-08-25 15:32:21 -0500266endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600267
Dees Troy8d66f8b2013-10-08 14:04:55 +0000268LOCAL_MODULE := toolbox_recovery
269LOCAL_MODULE_STEM := toolbox
270LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600271LOCAL_MODULE_TAGS := optional
Ethan Yonker58f21322018-08-24 11:17:36 -0500272LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-const-variable
Dees Troy8d66f8b2013-10-08 14:04:55 +0000273
Matt Mower92084af2015-02-19 13:19:47 -0600274# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000275include $(BUILD_EXECUTABLE)
276
277$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
278
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500279ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600280 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
281else
282 ALL_TOOLS := $(OUR_TOOLS)
283endif
284
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100285TOOLS_H := $(intermediates)/tools.h
286$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
287$(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 +0100288$(TOOLS_H):
289 $(transform-generated-source)
290
Matt Mower87413642017-01-17 21:14:46 -0600291# toolbox setenforce is used during init in non-symlink form, so it was
292# required to be included as part of the suite above. if busybox already
293# provides setenforce, we can omit the toolbox symlink
294TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
295ALL_TOOLS := $(TEMP_TOOLS)
Matt Mower92084af2015-02-19 13:19:47 -0600296
Matt Mower92084af2015-02-19 13:19:47 -0600297# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600298SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000299$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
Ethan Yonker58f21322018-08-24 11:17:36 -0500300$(SYMLINKS): $(LOCAL_INSTALLED_MODULE)
Dees Troy8d66f8b2013-10-08 14:04:55 +0000301 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
302 @mkdir -p $(dir $@)
303 @rm -rf $@
304 $(hide) ln -sf $(TOOLBOX_BINARY) $@
305
Matt Mower031163b2014-11-01 15:13:03 -0500306include $(CLEAR_VARS)
307LOCAL_MODULE := toolbox_symlinks
308LOCAL_MODULE_TAGS := optional
309LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
310include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600311
Dees Troyb47f28b2014-12-11 17:20:59 +0000312ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600313 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
314 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
315 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
316 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000317endif
318
Ethan Yonker75bf0412014-11-21 13:54:27 -0600319SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600320ALL_TOOLS :=
321BSD_TOOLS :=
322OUR_TOOLS :=
323TEMP_TOOLS :=
324TOOLS_FOR_SELINUX :=