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 | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 5 | OUR_TOOLS := \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 6 | start \ |
| 7 | stop \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 8 | |
| 9 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) |
| 10 | OUR_TOOLS += \ |
| 11 | getprop \ |
| 12 | setprop |
| 13 | endif |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 14 | |
Matt Mower | 81742fb | 2014-09-01 14:40:52 -0500 | [diff] [blame] | 15 | # If busybox does not have SELinux support, provide these tools with toolbox. |
| 16 | # Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true. |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 17 | ifeq ($(TWHAVE_SELINUX), true) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 18 | TOOLS_FOR_SELINUX := \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 19 | ls |
| 20 | |
| 21 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) |
| 22 | TOOLS_FOR_SELINUX += \ |
| 23 | load_policy \ |
| 24 | getenforce \ |
| 25 | chcon \ |
| 26 | restorecon \ |
| 27 | runcon \ |
| 28 | getsebool \ |
| 29 | setsebool |
| 30 | endif |
| 31 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 32 | OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 33 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 34 | # toolbox setenforce is used during init, so it needs to be included here |
| 35 | # symlink is omitted at the very end if busybox already provides this |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 36 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) |
| 37 | OUR_TOOLS += setenforce |
| 38 | endif |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 39 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 40 | |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 41 | ifeq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 42 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0) |
| 43 | # 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] | 44 | BSD_TOOLS := \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 45 | dd \ |
| 46 | du \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 47 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 48 | OUR_TOOLS := \ |
| 49 | df \ |
| 50 | iftop \ |
| 51 | ioctl \ |
| 52 | ionice \ |
| 53 | log \ |
| 54 | ls \ |
| 55 | lsof \ |
| 56 | mount \ |
| 57 | nandread \ |
| 58 | newfs_msdos \ |
| 59 | ps \ |
| 60 | prlimit \ |
| 61 | renice \ |
| 62 | sendevent \ |
| 63 | start \ |
| 64 | stop \ |
| 65 | top \ |
| 66 | uptime \ |
| 67 | watchprops \ |
| 68 | |
| 69 | else |
| 70 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 71 | OUR_TOOLS += \ |
| 72 | mknod \ |
| 73 | nohup |
| 74 | BSD_TOOLS := \ |
| 75 | cat \ |
| 76 | chown \ |
| 77 | cp \ |
| 78 | dd \ |
| 79 | du \ |
| 80 | grep \ |
| 81 | kill \ |
| 82 | ln \ |
| 83 | mv \ |
| 84 | printenv \ |
| 85 | rm \ |
| 86 | rmdir \ |
| 87 | sleep \ |
| 88 | sync |
| 89 | else |
| 90 | OUR_TOOLS += \ |
| 91 | cat \ |
| 92 | chown \ |
| 93 | dd \ |
| 94 | du \ |
| 95 | kill \ |
| 96 | ln \ |
| 97 | mv \ |
| 98 | printenv \ |
| 99 | rm \ |
| 100 | rmdir \ |
| 101 | setconsole \ |
| 102 | sleep \ |
| 103 | sync |
| 104 | endif |
| 105 | |
| 106 | OUR_TOOLS += \ |
| 107 | chmod \ |
| 108 | clear \ |
| 109 | cmp \ |
| 110 | date \ |
| 111 | df \ |
| 112 | dmesg \ |
| 113 | getevent \ |
| 114 | hd \ |
| 115 | id \ |
| 116 | ifconfig \ |
| 117 | iftop \ |
| 118 | insmod \ |
| 119 | ioctl \ |
| 120 | ionice \ |
| 121 | log \ |
| 122 | lsmod \ |
| 123 | lsof \ |
| 124 | md5 \ |
| 125 | mkdir \ |
| 126 | mkswap \ |
| 127 | mount \ |
| 128 | nandread \ |
| 129 | netstat \ |
| 130 | newfs_msdos \ |
| 131 | notify \ |
| 132 | ps \ |
| 133 | readlink \ |
| 134 | renice \ |
| 135 | rmmod \ |
| 136 | route \ |
| 137 | schedtop \ |
| 138 | sendevent \ |
| 139 | smd \ |
| 140 | swapoff \ |
| 141 | swapon \ |
| 142 | top \ |
| 143 | touch \ |
| 144 | umount \ |
| 145 | uptime \ |
| 146 | vmstat \ |
| 147 | watchprops \ |
| 148 | wipe |
| 149 | ifneq ($(TWHAVE_SELINUX), true) |
| 150 | OUR_TOOLS += ls |
| 151 | endif |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 152 | endif |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 153 | endif |
| 154 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 155 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 156 | ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) |
| 157 | OUR_TOOLS += r |
| 158 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 159 | endif |
| 160 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 161 | LOCAL_SRC_FILES := \ |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 162 | toolbox.c \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 163 | $(patsubst %,%.c,$(OUR_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 164 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 165 | ifneq ($(wildcard system/core/toolbox/dynarray.c),) |
| 166 | LOCAL_SRC_FILES += dynarray.c |
Ethan Yonker | dc3223a | 2014-12-22 14:31:37 -0600 | [diff] [blame] | 167 | endif |
| 168 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 169 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 170 | LOCAL_SRC_FILES += \ |
| 171 | pwcache.c \ |
| 172 | upstream-netbsd/lib/libc/gen/getbsize.c \ |
| 173 | upstream-netbsd/lib/libc/gen/humanize_number.c \ |
| 174 | upstream-netbsd/lib/libc/stdlib/strsuftoll.c \ |
| 175 | upstream-netbsd/lib/libc/string/swab.c \ |
| 176 | upstream-netbsd/lib/libutil/raise_default_signal.c |
| 177 | endif |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 178 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 179 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 180 | LOCAL_CFLAGS += \ |
| 181 | -std=gnu99 \ |
| 182 | -Werror -Wno-unused-parameter \ |
| 183 | -I$(LOCAL_PATH)/upstream-netbsd/include \ |
| 184 | -include bsd-compatibility.h |
| 185 | endif |
| 186 | |
| 187 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 188 | LOCAL_C_INCLUDES += external/openssl/include |
| 189 | else |
| 190 | LOCAL_C_INCLUDES += bionic/libc/bionic |
| 191 | endif |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 192 | |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 193 | LOCAL_SHARED_LIBRARIES += libcutils |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 194 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 195 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 196 | ifeq ($(TW_USE_TOOLBOX), true) |
| 197 | LOCAL_SHARED_LIBRARIES += libcrypto |
| 198 | endif |
| 199 | else |
| 200 | LOCAL_SHARED_LIBRARIES += \ |
| 201 | libc \ |
| 202 | liblog |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 203 | endif |
| 204 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 205 | ifeq ($(TWHAVE_SELINUX), true) |
| 206 | LOCAL_SHARED_LIBRARIES += libselinux |
| 207 | endif |
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 | |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 216 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0) |
| 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) |
| 227 | LOCAL_SRC_FILES += ls.c |
| 228 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 229 | endif |
| 230 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 231 | LOCAL_MODULE := toolbox_recovery |
| 232 | LOCAL_MODULE_STEM := toolbox |
| 233 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 234 | LOCAL_MODULE_TAGS := optional |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 235 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 236 | # Including this will define $(intermediates) below |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 237 | include $(BUILD_EXECUTABLE) |
| 238 | |
| 239 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 240 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 241 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 242 | ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS) |
| 243 | else |
| 244 | ALL_TOOLS := $(OUR_TOOLS) |
| 245 | endif |
| 246 | |
Andrea Mennillo | 7d66ce5 | 2015-03-17 15:39:27 +0100 | [diff] [blame] | 247 | TOOLS_H := $(intermediates)/tools.h |
| 248 | $(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS) |
| 249 | $(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done |
| 250 | $(TOOLS_H): $(LOCAL_PATH)/Android.mk |
| 251 | $(TOOLS_H): |
| 252 | $(transform-generated-source) |
| 253 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 254 | ifeq ($(TWHAVE_SELINUX), true) |
| 255 | # toolbox setenforce is used during init in non-symlink form, so it was |
| 256 | # required to be included as part of the suite above. if busybox already |
| 257 | # provides setenforce, we can omit the toolbox symlink |
| 258 | TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS)) |
| 259 | ALL_TOOLS := $(TEMP_TOOLS) |
| 260 | endif |
| 261 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 262 | # Make /sbin/toolbox launchers for each tool |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 263 | SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 264 | $(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM) |
| 265 | $(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk |
| 266 | @echo "Symlink: $@ -> $(TOOLBOX_BINARY)" |
| 267 | @mkdir -p $(dir $@) |
| 268 | @rm -rf $@ |
| 269 | $(hide) ln -sf $(TOOLBOX_BINARY) $@ |
| 270 | |
Matt Mower | 031163b | 2014-11-01 15:13:03 -0500 | [diff] [blame] | 271 | include $(CLEAR_VARS) |
| 272 | LOCAL_MODULE := toolbox_symlinks |
| 273 | LOCAL_MODULE_TAGS := optional |
| 274 | LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) |
| 275 | include $(BUILD_PHONY_PACKAGE) |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 276 | |
Dees Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 277 | ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 278 | # Only needed if the build system lacks support for LOCAL_ADDITIONAL_DEPENDENCIES |
| 279 | ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS) |
| 280 | ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \ |
| 281 | $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS) |
Dees Troy | b47f28b | 2014-12-11 17:20:59 +0000 | [diff] [blame] | 282 | endif |
| 283 | |
Ethan Yonker | 75bf041 | 2014-11-21 13:54:27 -0600 | [diff] [blame] | 284 | SYMLINKS := |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 285 | ALL_TOOLS := |
| 286 | BSD_TOOLS := |
| 287 | OUR_TOOLS := |
| 288 | TEMP_TOOLS := |
| 289 | TOOLS_FOR_SELINUX := |