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 := \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 50 | iftop \ |
| 51 | ioctl \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 52 | nandread \ |
| 53 | newfs_msdos \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 54 | prlimit \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 55 | sendevent \ |
| 56 | start \ |
| 57 | stop \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 58 | |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 59 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23)) |
| 60 | BSD_TOOLS += \ |
| 61 | dd \ |
| 62 | |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 63 | OUR_TOOLS += \ |
| 64 | df \ |
| 65 | ionice \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 66 | log \ |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 67 | ls \ |
| 68 | lsof \ |
| 69 | mount \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 70 | ps \ |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 71 | renice \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 72 | top \ |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 73 | uptime \ |
| 74 | watchprops |
| 75 | endif |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 76 | 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 |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 156 | endif |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 157 | endif |
| 158 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 159 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 160 | ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) |
| 161 | OUR_TOOLS += r |
| 162 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 163 | endif |
| 164 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 165 | LOCAL_SRC_FILES := \ |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 166 | toolbox.c \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 167 | $(patsubst %,%.c,$(OUR_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 168 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 169 | ifneq ($(wildcard system/core/toolbox/dynarray.c),) |
| 170 | LOCAL_SRC_FILES += dynarray.c |
Ethan Yonker | dc3223a | 2014-12-22 14:31:37 -0600 | [diff] [blame] | 171 | endif |
| 172 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 173 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 174 | LOCAL_SRC_FILES += \ |
| 175 | pwcache.c \ |
| 176 | upstream-netbsd/lib/libc/gen/getbsize.c \ |
| 177 | upstream-netbsd/lib/libc/gen/humanize_number.c \ |
| 178 | upstream-netbsd/lib/libc/stdlib/strsuftoll.c \ |
| 179 | upstream-netbsd/lib/libc/string/swab.c \ |
| 180 | upstream-netbsd/lib/libutil/raise_default_signal.c |
| 181 | endif |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 182 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 183 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 184 | LOCAL_CFLAGS += \ |
| 185 | -std=gnu99 \ |
| 186 | -Werror -Wno-unused-parameter \ |
| 187 | -I$(LOCAL_PATH)/upstream-netbsd/include \ |
| 188 | -include bsd-compatibility.h |
| 189 | endif |
| 190 | |
| 191 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 192 | LOCAL_C_INCLUDES += external/openssl/include |
| 193 | else |
| 194 | LOCAL_C_INCLUDES += bionic/libc/bionic |
| 195 | endif |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 196 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 197 | LOCAL_SHARED_LIBRARIES += libcutils |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 198 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 199 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 200 | ifeq ($(TW_USE_TOOLBOX), true) |
| 201 | LOCAL_SHARED_LIBRARIES += libcrypto |
| 202 | endif |
| 203 | else |
| 204 | LOCAL_SHARED_LIBRARIES += \ |
| 205 | libc \ |
| 206 | liblog |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 207 | endif |
| 208 | |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 209 | LOCAL_SHARED_LIBRARIES += libselinux |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 210 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 211 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 212 | # libusbhost is only used by lsusb, and that isn't usually included in toolbox. |
| 213 | # The linker strips out all the unused library code in the normal case. |
| 214 | LOCAL_STATIC_LIBRARIES := libusbhost |
| 215 | LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS)) |
| 216 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 217 | |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 218 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0) |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 219 | # Rule to make getprop and setprop in M trees where toybox normally |
| 220 | # provides these tools. Toybox does not allow for easy dynamic |
| 221 | # configuration, so we would have to include the entire toybox binary |
| 222 | # which takes up more space than is necessary so long as we are still |
| 223 | # including busybox. |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 224 | ifneq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 225 | LOCAL_SRC_FILES += \ |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 226 | ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \ |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 227 | ../../../$(TWRP_TOOLBOX_PATH)/setprop.c \ |
| 228 | ../../../$(TWRP_TOOLBOX_PATH)/ls.c |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 229 | OUR_TOOLS += getprop setprop |
D. Andrei Măceș | 9ce12ec | 2016-12-22 17:14:21 -0500 | [diff] [blame] | 230 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 231 | endif |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 232 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0) |
| 233 | # Rule for making start and stop in N trees |
| 234 | LOCAL_SRC_FILES += \ |
| 235 | ../../../$(TWRP_TOOLBOX_PATH)/start.c \ |
| 236 | ../../../$(TWRP_TOOLBOX_PATH)/stop.c |
| 237 | OUR_TOOLS += start stop |
| 238 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 239 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 240 | LOCAL_MODULE := toolbox_recovery |
| 241 | LOCAL_MODULE_STEM := toolbox |
| 242 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 243 | LOCAL_MODULE_TAGS := optional |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 244 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 245 | # Including this will define $(intermediates) below |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 246 | include $(BUILD_EXECUTABLE) |
| 247 | |
| 248 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 249 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 250 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 251 | ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS) |
| 252 | else |
| 253 | ALL_TOOLS := $(OUR_TOOLS) |
| 254 | endif |
| 255 | |
Andrea Mennillo | 7d66ce5 | 2015-03-17 15:39:27 +0100 | [diff] [blame] | 256 | TOOLS_H := $(intermediates)/tools.h |
| 257 | $(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS) |
| 258 | $(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done |
| 259 | $(TOOLS_H): $(LOCAL_PATH)/Android.mk |
| 260 | $(TOOLS_H): |
| 261 | $(transform-generated-source) |
| 262 | |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 263 | # toolbox setenforce is used during init in non-symlink form, so it was |
| 264 | # required to be included as part of the suite above. if busybox already |
| 265 | # provides setenforce, we can omit the toolbox symlink |
| 266 | TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS)) |
| 267 | ALL_TOOLS := $(TEMP_TOOLS) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 268 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 269 | # Make /sbin/toolbox launchers for each tool |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 270 | SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 271 | $(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM) |
| 272 | $(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk |
| 273 | @echo "Symlink: $@ -> $(TOOLBOX_BINARY)" |
| 274 | @mkdir -p $(dir $@) |
| 275 | @rm -rf $@ |
| 276 | $(hide) ln -sf $(TOOLBOX_BINARY) $@ |
| 277 | |
Matt Mower | 031163b | 2014-11-01 15:13:03 -0500 | [diff] [blame] | 278 | include $(CLEAR_VARS) |
| 279 | LOCAL_MODULE := toolbox_symlinks |
| 280 | LOCAL_MODULE_TAGS := optional |
| 281 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 282 | include $(BUILD_PHONY_PACKAGE) |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 283 | |
Dees Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 284 | ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 285 | # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES |
| 286 | ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS) |
| 287 | ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \ |
| 288 | $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS) |
Dees Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 289 | endif |
| 290 | |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 291 | SYMLINKS := |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 292 | ALL_TOOLS := |
| 293 | BSD_TOOLS := |
| 294 | OUR_TOOLS := |
| 295 | TEMP_TOOLS := |
| 296 | TOOLS_FOR_SELINUX := |