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. |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 21 | ifeq ($(TWHAVE_SELINUX), true) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 22 | TOOLS_FOR_SELINUX := \ |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 23 | 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 Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 36 | OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX)) |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 37 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 38 | # 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 Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 40 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) |
| 41 | OUR_TOOLS += setenforce |
| 42 | endif |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 43 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 44 | |
Ethan Yonker | 5c93369 | 2014-04-04 11:26:32 -0500 | [diff] [blame] | 45 | ifeq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 46 | 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 Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 48 | BSD_TOOLS := \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 49 | dd \ |
| 50 | du \ |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 51 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 52 | OUR_TOOLS := \ |
| 53 | df \ |
| 54 | iftop \ |
| 55 | ioctl \ |
| 56 | ionice \ |
| 57 | log \ |
| 58 | ls \ |
| 59 | lsof \ |
| 60 | mount \ |
| 61 | nandread \ |
| 62 | newfs_msdos \ |
| 63 | ps \ |
| 64 | prlimit \ |
| 65 | renice \ |
| 66 | sendevent \ |
| 67 | start \ |
| 68 | stop \ |
| 69 | top \ |
| 70 | uptime \ |
| 71 | watchprops \ |
| 72 | |
| 73 | else |
| 74 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22)) |
| 75 | OUR_TOOLS += \ |
| 76 | mknod \ |
| 77 | nohup |
| 78 | BSD_TOOLS := \ |
| 79 | cat \ |
| 80 | chown \ |
| 81 | cp \ |
| 82 | dd \ |
| 83 | du \ |
| 84 | grep \ |
| 85 | kill \ |
| 86 | ln \ |
| 87 | mv \ |
| 88 | printenv \ |
| 89 | rm \ |
| 90 | rmdir \ |
| 91 | sleep \ |
| 92 | sync |
| 93 | else |
| 94 | OUR_TOOLS += \ |
| 95 | cat \ |
| 96 | chown \ |
| 97 | dd \ |
| 98 | du \ |
| 99 | kill \ |
| 100 | ln \ |
| 101 | mv \ |
| 102 | printenv \ |
| 103 | rm \ |
| 104 | rmdir \ |
| 105 | setconsole \ |
| 106 | sleep \ |
| 107 | sync |
| 108 | endif |
| 109 | |
| 110 | OUR_TOOLS += \ |
| 111 | chmod \ |
| 112 | clear \ |
| 113 | cmp \ |
| 114 | date \ |
| 115 | df \ |
| 116 | dmesg \ |
| 117 | getevent \ |
| 118 | hd \ |
| 119 | id \ |
| 120 | ifconfig \ |
| 121 | iftop \ |
| 122 | insmod \ |
| 123 | ioctl \ |
| 124 | ionice \ |
| 125 | log \ |
| 126 | lsmod \ |
| 127 | lsof \ |
| 128 | md5 \ |
| 129 | mkdir \ |
| 130 | mkswap \ |
| 131 | mount \ |
| 132 | nandread \ |
| 133 | netstat \ |
| 134 | newfs_msdos \ |
| 135 | notify \ |
| 136 | ps \ |
| 137 | readlink \ |
| 138 | renice \ |
| 139 | rmmod \ |
| 140 | route \ |
| 141 | schedtop \ |
| 142 | sendevent \ |
| 143 | smd \ |
| 144 | swapoff \ |
| 145 | swapon \ |
| 146 | top \ |
| 147 | touch \ |
| 148 | umount \ |
| 149 | uptime \ |
| 150 | vmstat \ |
| 151 | watchprops \ |
| 152 | wipe |
| 153 | ifneq ($(TWHAVE_SELINUX), true) |
| 154 | OUR_TOOLS += ls |
| 155 | endif |
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 | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 209 | ifeq ($(TWHAVE_SELINUX), true) |
| 210 | LOCAL_SHARED_LIBRARIES += libselinux |
| 211 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 212 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 213 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 214 | # libusbhost is only used by lsusb, and that isn't usually included in toolbox. |
| 215 | # The linker strips out all the unused library code in the normal case. |
| 216 | LOCAL_STATIC_LIBRARIES := libusbhost |
| 217 | LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS)) |
| 218 | endif |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 219 | |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 220 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 22; echo $$?),0) |
| 221 | # Rule to make getprop and setprop in M trees where toybox normally |
| 222 | # provides these tools. Toybox does not allow for easy dynamic |
| 223 | # configuration, so we would have to include the entire toybox binary |
| 224 | # which takes up more space than is necessary so long as we are still |
| 225 | # including busybox. |
| 226 | LOCAL_SRC_FILES += \ |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 227 | ../../../$(TWRP_TOOLBOX_PATH)/getprop.c \ |
| 228 | ../../../$(TWRP_TOOLBOX_PATH)/setprop.c |
| 229 | OUR_TOOLS += getprop setprop |
Ethan Yonker | 916cae8 | 2016-01-22 11:32:57 -0600 | [diff] [blame] | 230 | ifneq ($(TW_USE_TOOLBOX), true) |
Ethan Yonker | 34ae483 | 2016-08-24 15:32:18 -0500 | [diff] [blame] | 231 | LOCAL_SRC_FILES += ../../../$(TWRP_TOOLBOX_PATH)/ls.c |
Ethan Yonker | 916cae8 | 2016-01-22 11:32:57 -0600 | [diff] [blame] | 232 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 233 | endif |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 234 | ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0) |
| 235 | # Rule for making start and stop in N trees |
| 236 | LOCAL_SRC_FILES += \ |
| 237 | ../../../$(TWRP_TOOLBOX_PATH)/start.c \ |
| 238 | ../../../$(TWRP_TOOLBOX_PATH)/stop.c |
| 239 | OUR_TOOLS += start stop |
| 240 | endif |
Ethan Yonker | 6bb26b5 | 2016-01-10 22:26:51 -0600 | [diff] [blame] | 241 | |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 242 | LOCAL_MODULE := toolbox_recovery |
| 243 | LOCAL_MODULE_STEM := toolbox |
| 244 | LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 245 | LOCAL_MODULE_TAGS := optional |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 246 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 247 | # Including this will define $(intermediates) below |
Dees Troy | 8d66f8b | 2013-10-08 14:04:55 +0000 | [diff] [blame] | 248 | include $(BUILD_EXECUTABLE) |
| 249 | |
| 250 | $(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h |
| 251 | |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 252 | ifneq (,$(filter $(PLATFORM_SDK_VERSION), 21 22 23)) |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 253 | ALL_TOOLS := $(BSD_TOOLS) $(OUR_TOOLS) |
| 254 | else |
| 255 | ALL_TOOLS := $(OUR_TOOLS) |
| 256 | endif |
| 257 | |
Andrea Mennillo | 7d66ce5 | 2015-03-17 15:39:27 +0100 | [diff] [blame] | 258 | TOOLS_H := $(intermediates)/tools.h |
| 259 | $(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS) |
| 260 | $(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done |
| 261 | $(TOOLS_H): $(LOCAL_PATH)/Android.mk |
| 262 | $(TOOLS_H): |
| 263 | $(transform-generated-source) |
| 264 | |
Matt Mower | 92084af | 2015-02-19 13:19:47 -0600 | [diff] [blame] | 265 | ifeq ($(TWHAVE_SELINUX), true) |
| 266 | # toolbox setenforce is used during init in non-symlink form, so it was |
| 267 | # required to be included as part of the suite above. if busybox already |
| 268 | # provides setenforce, we can omit the toolbox symlink |
| 269 | TEMP_TOOLS := $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(ALL_TOOLS)) |
| 270 | ALL_TOOLS := $(TEMP_TOOLS) |
| 271 | endif |
| 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 := |