blob: 07e47389df4b1305415dd20776967ba63cbc1004 [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.
Dees Troy8d66f8b2013-10-08 14:04:55 +000021ifeq ($(TWHAVE_SELINUX), true)
Matt Mower92084af2015-02-19 13:19:47 -060022 TOOLS_FOR_SELINUX := \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050023 ls
24
25 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
26 TOOLS_FOR_SELINUX += \
27 load_policy \
28 getenforce \
29 chcon \
30 restorecon \
31 runcon \
32 getsebool \
33 setsebool
34 endif
35
Matt Mower92084af2015-02-19 13:19:47 -060036 OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
Dees Troy8d66f8b2013-10-08 14:04:55 +000037
Matt Mower92084af2015-02-19 13:19:47 -060038 # toolbox setenforce is used during init, so it needs to be included here
39 # symlink is omitted at the very end if busybox already provides this
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050040 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
41 OUR_TOOLS += setenforce
42 endif
Matt Mower92084af2015-02-19 13:19:47 -060043endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -060044
Ethan Yonker5c933692014-04-04 11:26:32 -050045ifeq ($(TW_USE_TOOLBOX), true)
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050046 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0)
47 # These are the only toolbox tools in M. The rest are now in toybox.
Matt Mower92084af2015-02-19 13:19:47 -060048 BSD_TOOLS := \
Matt Mower92084af2015-02-19 13:19:47 -060049 dd \
50 du \
Matt Mower92084af2015-02-19 13:19:47 -060051
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050052 OUR_TOOLS := \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050053 iftop \
54 ioctl \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050055 log \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050056 nandread \
57 newfs_msdos \
58 ps \
59 prlimit \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050060 sendevent \
61 start \
62 stop \
63 top \
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050064
Hashcode57332152016-12-20 01:30:49 +010065 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 25; echo $$?),0)
66 OUR_TOOLS += \
67 df \
68 ionice \
69 ls \
70 lsof \
71 mount \
72 renice \
73 uptime \
74 watchprops
75 endif
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050076 else
77 ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
78 OUR_TOOLS += \
79 mknod \
80 nohup
81 BSD_TOOLS := \
82 cat \
83 chown \
84 cp \
85 dd \
86 du \
87 grep \
88 kill \
89 ln \
90 mv \
91 printenv \
92 rm \
93 rmdir \
94 sleep \
95 sync
96 else
97 OUR_TOOLS += \
98 cat \
99 chown \
100 dd \
101 du \
102 kill \
103 ln \
104 mv \
105 printenv \
106 rm \
107 rmdir \
108 setconsole \
109 sleep \
110 sync
111 endif
112
113 OUR_TOOLS += \
114 chmod \
115 clear \
116 cmp \
117 date \
118 df \
119 dmesg \
120 getevent \
121 hd \
122 id \
123 ifconfig \
124 iftop \
125 insmod \
126 ioctl \
127 ionice \
128 log \
129 lsmod \
130 lsof \
131 md5 \
132 mkdir \
133 mkswap \
134 mount \
135 nandread \
136 netstat \
137 newfs_msdos \
138 notify \
139 ps \
140 readlink \
141 renice \
142 rmmod \
143 route \
144 schedtop \
145 sendevent \
146 smd \
147 swapoff \
148 swapon \
149 top \
150 touch \
151 umount \
152 uptime \
153 vmstat \
154 watchprops \
155 wipe
156 ifneq ($(TWHAVE_SELINUX), true)
157 OUR_TOOLS += ls
158 endif
Matt Mower92084af2015-02-19 13:19:47 -0600159 endif
Ethan Yonker5c933692014-04-04 11:26:32 -0500160endif
161
Matt Mower92084af2015-02-19 13:19:47 -0600162ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
163 ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
164 OUR_TOOLS += r
165 endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600166endif
167
Dees Troy8d66f8b2013-10-08 14:04:55 +0000168LOCAL_SRC_FILES := \
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600169 toolbox.c \
Matt Mower92084af2015-02-19 13:19:47 -0600170 $(patsubst %,%.c,$(OUR_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000171
Matt Mower92084af2015-02-19 13:19:47 -0600172ifneq ($(wildcard system/core/toolbox/dynarray.c),)
173 LOCAL_SRC_FILES += dynarray.c
Ethan Yonkerdc3223a2014-12-22 14:31:37 -0600174endif
175
Matt Mower92084af2015-02-19 13:19:47 -0600176ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
177 LOCAL_SRC_FILES += \
178 pwcache.c \
179 upstream-netbsd/lib/libc/gen/getbsize.c \
180 upstream-netbsd/lib/libc/gen/humanize_number.c \
181 upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
182 upstream-netbsd/lib/libc/string/swab.c \
183 upstream-netbsd/lib/libutil/raise_default_signal.c
184endif
Dees Troy8d66f8b2013-10-08 14:04:55 +0000185
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500186ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600187 LOCAL_CFLAGS += \
188 -std=gnu99 \
189 -Werror -Wno-unused-parameter \
190 -I$(LOCAL_PATH)/upstream-netbsd/include \
191 -include bsd-compatibility.h
192endif
193
194ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
195 LOCAL_C_INCLUDES += external/openssl/include
196else
197 LOCAL_C_INCLUDES += bionic/libc/bionic
198endif
Dees Troybb4c0cb2013-11-02 20:25:14 +0000199
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600200LOCAL_SHARED_LIBRARIES += libcutils
Dees Troy8d66f8b2013-10-08 14:04:55 +0000201
Matt Mower92084af2015-02-19 13:19:47 -0600202ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22))
203 ifeq ($(TW_USE_TOOLBOX), true)
204 LOCAL_SHARED_LIBRARIES += libcrypto
205 endif
206else
207 LOCAL_SHARED_LIBRARIES += \
208 libc \
209 liblog
Dees Troy8d66f8b2013-10-08 14:04:55 +0000210endif
211
Matt Mower92084af2015-02-19 13:19:47 -0600212ifeq ($(TWHAVE_SELINUX), true)
213 LOCAL_SHARED_LIBRARIES += libselinux
214endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600215
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500216ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600217 # libusbhost is only used by lsusb, and that isn't usually included in toolbox.
218 # The linker strips out all the unused library code in the normal case.
219 LOCAL_STATIC_LIBRARIES := libusbhost
220 LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
221endif
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600222
Hashcode57332152016-12-20 01:30:49 +0100223ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23 24))
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600224 # Rule to make getprop and setprop in M trees where toybox normally
225 # provides these tools. Toybox does not allow for easy dynamic
226 # configuration, so we would have to include the entire toybox binary
227 # which takes up more space than is necessary so long as we are still
228 # including busybox.
229 LOCAL_SRC_FILES += \
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600230 ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \
231 ../../../$(TWRP_TOOLBOX_PATH)/setprop.c
232 OUR_TOOLS += getprop setprop
Ethan Yonker916cae82016-01-22 11:32:57 -0600233 ifneq ($(TW_USE_TOOLBOX), true)
Ethan Yonker34ae4832016-08-24 15:32:18 -0500234 LOCAL_SRC_FILES += ../../../$(TWRP_TOOLBOX_PATH)/ls.c
Ethan Yonker916cae82016-01-22 11:32:57 -0600235 endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600236endif
Ethan Yonkerf1179622016-08-25 15:32:21 -0500237ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
238 # Rule for making start and stop in N trees
239 LOCAL_SRC_FILES += \
240 ../../../$(TWRP_TOOLBOX_PATH)/start.c \
241 ../../../$(TWRP_TOOLBOX_PATH)/stop.c
242 OUR_TOOLS += start stop
243endif
Ethan Yonker6bb26b52016-01-10 22:26:51 -0600244
Dees Troy8d66f8b2013-10-08 14:04:55 +0000245LOCAL_MODULE := toolbox_recovery
246LOCAL_MODULE_STEM := toolbox
247LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
Matt Mower92084af2015-02-19 13:19:47 -0600248LOCAL_MODULE_TAGS := optional
Dees Troy8d66f8b2013-10-08 14:04:55 +0000249
Matt Mower92084af2015-02-19 13:19:47 -0600250# Including this will define $(intermediates) below
Dees Troy8d66f8b2013-10-08 14:04:55 +0000251include $(BUILD_EXECUTABLE)
252
253$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
254
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500255ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23))
Matt Mower92084af2015-02-19 13:19:47 -0600256 ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS)
257else
258 ALL_TOOLS := $(OUR_TOOLS)
259endif
260
Andrea Mennillo7d66ce52015-03-17 15:39:27 +0100261TOOLS_H := $(intermediates)/tools.h
262$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
263$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
264$(TOOLS_H): $(LOCAL_PATH)/Android.mk
265$(TOOLS_H):
266 $(transform-generated-source)
267
Matt Mower92084af2015-02-19 13:19:47 -0600268ifeq ($(TWHAVE_SELINUX), true)
269 # toolbox setenforce is used during init in non-symlink form, so it was
270 # required to be included as part of the suite above. if busybox already
271 # provides setenforce, we can omit the toolbox symlink
272 TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS))
273 ALL_TOOLS := $(TEMP_TOOLS)
274endif
275
Matt Mower92084af2015-02-19 13:19:47 -0600276# Make /sbin/toolbox launchers for each tool
Ethan Yonkerbcc502c2014-11-10 11:22:10 -0600277SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
Dees Troy8d66f8b2013-10-08 14:04:55 +0000278$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
279$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
280 @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
281 @mkdir -p $(dir $@)
282 @rm -rf $@
283 $(hide) ln -sf $(TOOLBOX_BINARY) $@
284
Matt Mower031163b2014-11-01 15:13:03 -0500285include $(CLEAR_VARS)
286LOCAL_MODULE := toolbox_symlinks
287LOCAL_MODULE_TAGS := optional
288LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
289include $(BUILD_PHONY_PACKAGE)
Ethan Yonker75bf0412014-11-21 13:54:27 -0600290
Dees Troyb47f28b2014-12-11 17:20:59 +0000291ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
Matt Mower92084af2015-02-19 13:19:47 -0600292 # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES
293 ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
294 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
295 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
Dees Troyb47f28b2014-12-11 17:20:59 +0000296endif
297
Ethan Yonker75bf0412014-11-21 13:54:27 -0600298SYMLINKS :=
Matt Mower92084af2015-02-19 13:19:47 -0600299ALL_TOOLS :=
300BSD_TOOLS :=
301OUR_TOOLS :=
302TEMP_TOOLS :=
303TOOLS_FOR_SELINUX :=