blob: bf77ba26b588bfb6c771aac1dba0acc06b188cd8 [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
Matt Mower92084af2015-02-19 13:19:47 -0600163ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
164 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
165 OUR_TOOLS += r
166 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600167endif
168
Dees Troy8d66f8b2013-10-08 14:04:55 +0000169LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600170 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600171 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000172
Matt Mower92084af2015-02-19 13:19:47 -0600173ifneq ($(wildcard system/core/toolbox/dynarray.c),)
174 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600175endif
176
Matt Mower92084af2015-02-19 13:19:47 -0600177ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
178 LOCAL_SRC_FILES += \
179 pwcache.c \
180 upstream-netbsd/lib/libc/gen/getbsize.c \
181 upstream-netbsd/lib/libc/gen/humanize_number.c \
182 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
183 upstream-netbsd/lib/libc/string/swab.c \
184 upstream-netbsd/lib/libutil/raise_default_signal.c
185endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000186
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500187ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600188 LOCAL_CFLAGS += \
189 -std=gnu99 \
190 -Werror -Wno-unused-parameter \
191 -I$(LOCAL_PATH)/upstream-netbsd/include \
192 -include bsd-compatibility.h
193endif
194
195ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
196 LOCAL_C_INCLUDES += external/openssl/include
197else
198 LOCAL_C_INCLUDES += bionic/libc/bionic
199endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000200
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600201LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000202
Matt Mower92084af2015-02-19 13:19:47 -0600203ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
204 ifeq ($(TW_USE_TOOLBOX), true)
205 LOCAL_SHARED_LIBRARIES += libcrypto
206 endif
207else
208 LOCAL_SHARED_LIBRARIES += \
209 libc \
210 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000211endif
212
Matt Mower87413642017-01-17 21:14:46 -0600213LOCAL_SHARED_LIBRARIES += libselinux
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600214
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500215ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600216 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
217 # The linker strips out all the unused library code in the normal case.
218 LOCAL_STATIC_LIBRARIES := libusbhost
219 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
220endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600221
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500222ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600223 # Rule to make getprop and setprop in M trees where toybox normally
224 # provides these tools. Toybox does not allow for easy dynamic
225 # configuration, so we would have to include the entire toybox binary
226 # which takes up more space than is necessary so long as we are still
227 # including busybox.
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500228ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600229 LOCAL_SRC_FILES += \
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600230 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500231 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \
232 ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600233 OUR_TOOLS += getprop setprop
D. Andrei Măceș9ce12ec2016-12-22 17:14:21 -0500234endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600235endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500236ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
237 # Rule for making start and stop in N trees
238 LOCAL_SRC_FILES += \
239 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
240 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
241 OUR_TOOLS += start stop
242endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600243
Dees Troy8d66f8b2013-10-08 14:04:55 +0000244LOCAL_MODULE := toolbox_recovery
245LOCAL_MODULE_STEM := toolbox
246LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600247LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000248
Matt Mower92084af2015-02-19 13:19:47 -0600249# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000250include $(BUILD_EXECUTABLE)
251
252$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
253
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500254ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600255 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
256else
257 ALL_TOOLS := $(OUR_TOOLS)
258endif
259
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100260TOOLS_H := $(intermediates)/tools.h
261$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
262$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
263$(TOOLS_H): $(LOCAL_PATH)/Android.mk
264$(TOOLS_H):
265 $(transform-generated-source)
266
Matt Mower87413642017-01-17 21:14:46 -0600267# toolbox setenforce is used during init in non-symlink form, so it was
268# required to be included as part of the suite above. if busybox already
269# provides setenforce, we can omit the toolbox symlink
270TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
271ALL_TOOLS := $(TEMP_TOOLS)
Matt Mower92084af2015-02-19 13:19:47 -0600272
Matt Mower92084af2015-02-19 13:19:47 -0600273# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600274SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000275$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
276$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
277 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
278 @mkdir -p $(dir $@)
279 @rm -rf $@
280 $(hide) ln -sf $(TOOLBOX_BINARY) $@
281
Matt Mower031163b2014-11-01 15:13:03 -0500282include $(CLEAR_VARS)
283LOCAL_MODULE := toolbox_symlinks
284LOCAL_MODULE_TAGS := optional
285LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
286include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600287
Dees Troyb47f28b2014-12-11 17:20:59 +0000288ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600289 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
290 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
291 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
292 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000293endif
294
Ethan Yonker75bf0412014-11-21 13:54:27 -0600295SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600296ALL_TOOLS :=
297BSD_TOOLS :=
298OUR_TOOLS :=
299TEMP_TOOLS :=
300TOOLS_FOR_SELINUX :=