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