blob: 9160802135d20f7ddc24c1cca3d53d0d4eb877f0 [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 := \
Matt Mower92084af2015-02-19 13:19:47 -060047 dd \
48 du \
Matt Mower92084af2015-02-19 13:19:47 -060049
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050050 OUR_TOOLS := \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050051 iftop \
52 ioctl \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050053 log \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050054 nandread \
55 newfs_msdos \
56 ps \
57 prlimit \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050058 sendevent \
59 start \
60 stop \
61 top \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050062
Hashcode57332152016-12-20 01:30:49 +010063 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 25; echo $$?),0)
64 OUR_TOOLS += \
65 df \
66 ionice \
67 ls \
68 lsof \
69 mount \
70 renice \
71 uptime \
72 watchprops
73 endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050074 else
75 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
76 OUR_TOOLS += \
77 mknod \
78 nohup
79 BSD_TOOLS := \
80 cat \
81 chown \
82 cp \
83 dd \
84 du \
85 grep \
86 kill \
87 ln \
88 mv \
89 printenv \
90 rm \
91 rmdir \
92 sleep \
93 sync
94 else
95 OUR_TOOLS += \
96 cat \
97 chown \
98 dd \
99 du \
100 kill \
101 ln \
102 mv \
103 printenv \
104 rm \
105 rmdir \
106 setconsole \
107 sleep \
108 sync
109 endif
110
111 OUR_TOOLS += \
112 chmod \
113 clear \
114 cmp \
115 date \
116 df \
117 dmesg \
118 getevent \
119 hd \
120 id \
121 ifconfig \
122 iftop \
123 insmod \
124 ioctl \
125 ionice \
126 log \
127 lsmod \
128 lsof \
129 md5 \
130 mkdir \
131 mkswap \
132 mount \
133 nandread \
134 netstat \
135 newfs_msdos \
136 notify \
137 ps \
138 readlink \
139 renice \
140 rmmod \
141 route \
142 schedtop \
143 sendevent \
144 smd \
145 swapoff \
146 swapon \
147 top \
148 touch \
149 umount \
150 uptime \
151 vmstat \
152 watchprops \
153 wipe
Matt Mower92084af2015-02-19 13:19:47 -0600154 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500155endif
156
Matt Mower92084af2015-02-19 13:19:47 -0600157ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
158 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
159 OUR_TOOLS += r
160 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600161endif
162
Dees Troy8d66f8b2013-10-08 14:04:55 +0000163LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600164 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600165 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000166
Matt Mower92084af2015-02-19 13:19:47 -0600167ifneq ($(wildcard system/core/toolbox/dynarray.c),)
168 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600169endif
170
Matt Mower92084af2015-02-19 13:19:47 -0600171ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
172 LOCAL_SRC_FILES += \
173 pwcache.c \
174 upstream-netbsd/lib/libc/gen/getbsize.c \
175 upstream-netbsd/lib/libc/gen/humanize_number.c \
176 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
177 upstream-netbsd/lib/libc/string/swab.c \
178 upstream-netbsd/lib/libutil/raise_default_signal.c
179endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000180
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500181ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600182 LOCAL_CFLAGS += \
183 -std=gnu99 \
184 -Werror -Wno-unused-parameter \
185 -I$(LOCAL_PATH)/upstream-netbsd/include \
186 -include bsd-compatibility.h
187endif
188
189ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
190 LOCAL_C_INCLUDES += external/openssl/include
191else
192 LOCAL_C_INCLUDES += bionic/libc/bionic
193endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000194
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600195LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000196
Matt Mower92084af2015-02-19 13:19:47 -0600197ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
198 ifeq ($(TW_USE_TOOLBOX), true)
199 LOCAL_SHARED_LIBRARIES += libcrypto
200 endif
201else
202 LOCAL_SHARED_LIBRARIES += \
203 libc \
204 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000205endif
206
Matt Mower87413642017-01-17 21:14:46 -0600207LOCAL_SHARED_LIBRARIES += libselinux
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600208
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500209ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600210 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
211 # The linker strips out all the unused library code in the normal case.
212 LOCAL_STATIC_LIBRARIES := libusbhost
213 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
214endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600215
Hashcode57332152016-12-20 01:30:49 +0100216ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23 24))
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600217 # Rule to make getprop and setprop in M trees where toybox normally
218 # provides these tools. Toybox does not allow for easy dynamic
219 # configuration, so we would have to include the entire toybox binary
220 # which takes up more space than is necessary so long as we are still
221 # including busybox.
222 LOCAL_SRC_FILES += \
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600223 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \
224 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c
225 OUR_TOOLS += getprop setprop
Ethan Yonker916cae82016-01-22 11:32:57 -0600226 ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker34ae4832016-08-24 15:32:18 -0500227 LOCAL_SRC_FILES += ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker916cae82016-01-22 11:32:57 -0600228 endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600229endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500230ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
231 # Rule for making start and stop in N trees
232 LOCAL_SRC_FILES += \
233 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
234 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
235 OUR_TOOLS += start stop
236endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600237
Dees Troy8d66f8b2013-10-08 14:04:55 +0000238LOCAL_MODULE := toolbox_recovery
239LOCAL_MODULE_STEM := toolbox
240LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600241LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000242
Matt Mower92084af2015-02-19 13:19:47 -0600243# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000244include $(BUILD_EXECUTABLE)
245
246$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
247
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500248ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600249 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
250else
251 ALL_TOOLS := $(OUR_TOOLS)
252endif
253
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100254TOOLS_H := $(intermediates)/tools.h
255$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
256$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
257$(TOOLS_H): $(LOCAL_PATH)/Android.mk
258$(TOOLS_H):
259 $(transform-generated-source)
260
Matt Mower87413642017-01-17 21:14:46 -0600261# toolbox setenforce is used during init in non-symlink form, so it was
262# required to be included as part of the suite above. if busybox already
263# provides setenforce, we can omit the toolbox symlink
264TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
265ALL_TOOLS := $(TEMP_TOOLS)
Matt Mower92084af2015-02-19 13:19:47 -0600266
Matt Mower92084af2015-02-19 13:19:47 -0600267# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600268SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000269$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
270$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
271 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
272 @mkdir -p $(dir $@)
273 @rm -rf $@
274 $(hide) ln -sf $(TOOLBOX_BINARY) $@
275
Matt Mower031163b2014-11-01 15:13:03 -0500276include $(CLEAR_VARS)
277LOCAL_MODULE := toolbox_symlinks
278LOCAL_MODULE_TAGS := optional
279LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
280include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600281
Dees Troyb47f28b2014-12-11 17:20:59 +0000282ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600283 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
284 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
285 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
286 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000287endif
288
Ethan Yonker75bf0412014-11-21 13:54:27 -0600289SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600290ALL_TOOLS :=
291BSD_TOOLS :=
292OUR_TOOLS :=
293TEMP_TOOLS :=
294TOOLS_FOR_SELINUX :=