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 := \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 47 | dd \ |
| 48 | du \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 49 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 50 | OUR_TOOLS := \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 51 | iftop \ |
| 52 | ioctl \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 53 | log \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 54 | nandread \ |
| 55 | newfs_msdos \ |
| 56 | ps \ |
| 57 | prlimit \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 58 | sendevent \ |
| 59 | start \ |
| 60 | stop \ |
| 61 | top \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 62 | |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 63 | 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 Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 74 | 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 Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 154 | endif |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 155 | endif |
| 156 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 157 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 158 | ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) |
| 159 | OUR_TOOLS += r |
| 160 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 161 | endif |
| 162 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 163 | LOCAL_SRC_FILES := \ |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 164 | toolbox.c \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 165 | $(patsubst %,%.c,$(OUR_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 166 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 167 | ifneq ($(wildcard system/core/toolbox/dynarray.c),) |
| 168 | LOCAL_SRC_FILES += dynarray.c |
Ethan Yonker | dc3223a | 2014-12-22 14:31:37 -0600 | [diff] [blame] | 169 | endif |
| 170 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 171 | ifneq (,$(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 |
| 179 | endif |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 180 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 181 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 182 | LOCAL_CFLAGS += \ |
| 183 | -std=gnu99 \ |
| 184 | -Werror -Wno-unused-parameter \ |
| 185 | -I$(LOCAL_PATH)/upstream-netbsd/include \ |
| 186 | -include bsd-compatibility.h |
| 187 | endif |
| 188 | |
| 189 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 190 | LOCAL_C_INCLUDES += external/openssl/include |
| 191 | else |
| 192 | LOCAL_C_INCLUDES += bionic/libc/bionic |
| 193 | endif |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 194 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 195 | LOCAL_SHARED_LIBRARIES += libcutils |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 196 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 197 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 198 | ifeq ($(TW_USE_TOOLBOX), true) |
| 199 | LOCAL_SHARED_LIBRARIES += libcrypto |
| 200 | endif |
| 201 | else |
| 202 | LOCAL_SHARED_LIBRARIES += \ |
| 203 | libc \ |
| 204 | liblog |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 205 | endif |
| 206 | |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 207 | LOCAL_SHARED_LIBRARIES += libselinux |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 208 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 209 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 210 | # 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)) |
| 214 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 215 | |
Hashcode | 5733215 | 2016-12-20 01:30:49 +0100 | [diff] [blame] | 216 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 23 24)) |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 217 | # 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 Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 223 | ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \ |
| 224 | ../../../$(TWRP_TOOLBOX_PATH)/setprop.c |
| 225 | OUR_TOOLS += getprop setprop |
Ethan Yonker | 916cae8 | 2016-01-22 11:32:57 -0600 | [diff] [blame] | 226 | ifneq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | 34ae483 | 2016-08-24 15:32:18 -0500 | [diff] [blame] | 227 | LOCAL_SRC_FILES += ../../../$(TWRP_TOOLBOX_PATH)/ls.c |
Ethan Yonker | 916cae8 | 2016-01-22 11:32:57 -0600 | [diff] [blame] | 228 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 229 | endif |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 230 | ifeq ($(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 |
| 236 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 237 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 238 | LOCAL_MODULE := toolbox_recovery |
| 239 | LOCAL_MODULE_STEM := toolbox |
| 240 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 241 | LOCAL_MODULE_TAGS := optional |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 242 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 243 | # Including this will define $(intermediates) below |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 244 | include $(BUILD_EXECUTABLE) |
| 245 | |
| 246 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 247 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 248 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 249 | ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS) |
| 250 | else |
| 251 | ALL_TOOLS := $(OUR_TOOLS) |
| 252 | endif |
| 253 | |
Andrea Mennillo | 7d66ce5 | 2015-03-17 15:39:27 +0100 | [diff] [blame] | 254 | TOOLS_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 Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 261 | # 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 |
| 264 | TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS)) |
| 265 | ALL_TOOLS := $(TEMP_TOOLS) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 266 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 267 | # Make /sbin/toolbox launchers for each tool |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 268 | SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 269 | $(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 Mower | 031163b | 2014-11-01 15:13:03 -0500 | [diff] [blame] | 276 | include $(CLEAR_VARS) |
| 277 | LOCAL_MODULE := toolbox_symlinks |
| 278 | LOCAL_MODULE_TAGS := optional |
| 279 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 280 | include $(BUILD_PHONY_PACKAGE) |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 281 | |
Dees Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 282 | ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 283 | # 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 Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 287 | endif |
| 288 | |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 289 | SYMLINKS := |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 290 | ALL_TOOLS := |
| 291 | BSD_TOOLS := |
| 292 | OUR_TOOLS := |
| 293 | TEMP_TOOLS := |
| 294 | TOOLS_FOR_SELINUX := |