Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 1 | TWRP_TOOLBOX_PATH := $(call my-dir) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 2 | LOCAL_PATH := system/core/toolbox |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 3 | include $(CLEAR_VARS) |
| 4 | |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 5 | OUR_TOOLS := |
| 6 | |
| 7 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0) |
| 8 | OUR_TOOLS := \ |
| 9 | start \ |
| 10 | stop |
| 11 | endif |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 12 | |
| 13 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) |
| 14 | OUR_TOOLS += \ |
| 15 | getprop \ |
| 16 | setprop |
| 17 | endif |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 18 | |
Matt Mower | 81742fb | 2014-09-01 14:40:52 -0500 | [diff] [blame] | 19 | # 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 Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 21 | TOOLS_FOR_SELINUX := \ |
| 22 | ls |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 23 | |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 24 | ifeq ($(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 |
| 33 | endif |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 34 | |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 35 | OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 36 | |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 37 | # 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 |
| 39 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) |
| 40 | OUR_TOOLS += setenforce |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 41 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 42 | |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 43 | ifeq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 44 | 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 Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 46 | BSD_TOOLS := \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 47 | $(if $(filter $(PLATFORM_SDK_VERSION), 23 24), du) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 48 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 49 | OUR_TOOLS := \ |
Ivan Kutepov | ff9d097 | 2018-03-21 23:05:39 +0300 | [diff] [blame] | 50 | 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 Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 62 | |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 63 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23)) |
| 64 | BSD_TOOLS += \ |
| 65 | dd \ |
| 66 | |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 67 | OUR_TOOLS += \ |
| 68 | df \ |
| 69 | ionice \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 70 | log \ |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 71 | ls \ |
| 72 | lsof \ |
| 73 | mount \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 74 | ps \ |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 75 | renice \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 76 | top \ |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 77 | uptime \ |
| 78 | watchprops |
| 79 | endif |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 80 | 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 Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 160 | endif |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 161 | endif |
| 162 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 163 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 164 | ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) |
| 165 | OUR_TOOLS += r |
| 166 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 167 | endif |
| 168 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 169 | LOCAL_SRC_FILES := \ |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 170 | toolbox.c \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 171 | $(patsubst %,%.c,$(OUR_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 172 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 173 | ifneq ($(wildcard system/core/toolbox/dynarray.c),) |
| 174 | LOCAL_SRC_FILES += dynarray.c |
Ethan Yonker | dc3223a | 2014-12-22 14:31:37 -0600 | [diff] [blame] | 175 | endif |
| 176 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 177 | ifneq (,$(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 |
| 185 | endif |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 186 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 187 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 188 | LOCAL_CFLAGS += \ |
| 189 | -std=gnu99 \ |
| 190 | -Werror -Wno-unused-parameter \ |
| 191 | -I$(LOCAL_PATH)/upstream-netbsd/include \ |
| 192 | -include bsd-compatibility.h |
| 193 | endif |
| 194 | |
| 195 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 196 | LOCAL_C_INCLUDES += external/openssl/include |
| 197 | else |
| 198 | LOCAL_C_INCLUDES += bionic/libc/bionic |
| 199 | endif |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 200 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 201 | LOCAL_SHARED_LIBRARIES += libcutils |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 202 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 203 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 204 | ifeq ($(TW_USE_TOOLBOX), true) |
| 205 | LOCAL_SHARED_LIBRARIES += libcrypto |
| 206 | endif |
| 207 | else |
| 208 | LOCAL_SHARED_LIBRARIES += \ |
| 209 | libc \ |
| 210 | liblog |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 211 | endif |
| 212 | |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 213 | LOCAL_SHARED_LIBRARIES += libselinux |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 214 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 215 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 216 | # 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)) |
| 220 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 221 | |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 222 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0) |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 223 | # 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ș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 228 | ifneq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 229 | LOCAL_SRC_FILES += \ |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 230 | ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 231 | ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \ |
| 232 | ../../../$(TWRP_TOOLBOX_PATH)/ls.c |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 233 | OUR_TOOLS += getprop setprop |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 234 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 235 | endif |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 236 | ifeq ($(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 |
| 242 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 243 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 244 | LOCAL_MODULE := toolbox_recovery |
| 245 | LOCAL_MODULE_STEM := toolbox |
| 246 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 247 | LOCAL_MODULE_TAGS := optional |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 248 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 249 | # Including this will define $(intermediates) below |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 250 | include $(BUILD_EXECUTABLE) |
| 251 | |
| 252 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 253 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 254 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 255 | ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS) |
| 256 | else |
| 257 | ALL_TOOLS := $(OUR_TOOLS) |
| 258 | endif |
| 259 | |
Andrea Mennillo | 7d66ce5 | 2015-03-17 15:39:27 +0100 | [diff] [blame] | 260 | TOOLS_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 Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 267 | # 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 |
| 270 | TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS)) |
| 271 | ALL_TOOLS := $(TEMP_TOOLS) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 272 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 273 | # Make /sbin/toolbox launchers for each tool |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 274 | SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 275 | $(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 Mower | 031163b | 2014-11-01 15:13:03 -0500 | [diff] [blame] | 282 | include $(CLEAR_VARS) |
| 283 | LOCAL_MODULE := toolbox_symlinks |
| 284 | LOCAL_MODULE_TAGS := optional |
| 285 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 286 | include $(BUILD_PHONY_PACKAGE) |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 287 | |
Dees Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 288 | ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 289 | # 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 Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 293 | endif |
| 294 | |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 295 | SYMLINKS := |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 296 | ALL_TOOLS := |
| 297 | BSD_TOOLS := |
| 298 | OUR_TOOLS := |
| 299 | TEMP_TOOLS := |
| 300 | TOOLS_FOR_SELINUX := |