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