Include su binary executable in AOSP build

3,088 views
Skip to first unread message

lee xiong

unread,
Aug 27, 2014, 8:58:12 PM8/27/14
to android-...@googlegroups.com

I have been trying to get the su binary included in the <android_source_root>/out/.../system/xbin/su after building Android from source. I have the su binary (from Chainfire) as an executable file but I can't seem to get it included in the AOSP build.

All the examples or solutions I've came across discussed about the following in the android_source_root:

  1. Removing the su directory from system/extras/ and include the su-binary directory (taken from ChainsDD) in external/.
  2. Modify the file system/extras/su/Android.mk with "LOCAL_MODULE_TAGS := optional" and the file build/target/product/core.mk to include su in the PRODUCT_PACKAGES.

All of those have the su.c, su.h and other files in the su directory that are used to build the su package.

What I would like to know is how to include su in the AOSP build when I have the "su binary executable file" only without the need to include the su.c or any of those files? Where should I put the su directory and what is the content of the Android.mk file?

Please advice and thank you for your time.

trevd

unread,
Aug 28, 2014, 1:28:54 PM8/28/14
to android-...@googlegroups.com
Hi 
look up PRODUCT_COPY_FILES in any of the device specific directories for examples of copying files into the system image ... alternatively set the build type to debug which "should" include the original su file built from source. You can type choosetype after selecting the device from the lunch ,menu to change the build type

Thanks
trevd

lee xiong

unread,
Sep 5, 2014, 4:28:08 AM9/5/14
to android-...@googlegroups.com
Hi trevd,

Thank you for the guidance.
I managed to copy the su binary file into xbin using 2 solutions but both solutions have issues with changing the permission of the file (Listed below).
(Note: My su binary is put in <android_root_tree>/prebuilts/)

Solution 1
I modified the device.mk file in the <android_root_tree>/device/ directory to add the following:
PRODUCT_COPY_FILES += \
prebuilts/su/su:system/xbin
$(shell chmod 6755 <destination_path_to_out_system>/xbin/su)

***Issue: This solution changed the su binary permissions but whenever I run the command lunch, I get warnings of the su file does not exists.

Solution 2
I modified the device.mk file in the <android_root_tree>/device/ directory to add the following:
PRODUCT_PACKAGES += \
su

I then create an Android.mk file in the su directory in <android_root_tree>/prebuilts/su/ and put the following contents into it:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := su
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 
LOCAL_UNSTRIPPED_PATH := $(LOCAL_MODULE_PATH)

###->Inserted chmod command here. Ways I've tried are listed below.
 
include $(BUILD_PREBUILT)

***Issue: The su binary file is copied to /system/xbin directory but the file permission is never modified.
***### Insertion code to change permission:
    Insertion 1:
SU_BINARY := $(LOCAL_MODULE_PATH)/su
$(SU_BINARY)-post: su
chmod 6755 $(LOCAL_MODULE_PATH)/su
 
    Insertion 2:
SU_BINARY := $(LOCAL_MODULE_PATH)/su
$(SU_BINARY)-post: su
$(shell chmod 6755 $(LOCAL_MODULE_PATH)/su)

I hope someone could advice on how to chmod a file right after it has been copied to /system/xbin directory.
Thank you very much.

trevd

unread,
Sep 6, 2014, 8:19:55 PM9/6/14
to android-...@googlegroups.com
Hello Again! 

Just a couple of pointers, solution 1, Your binary source path needs to be fully qualified from the top of the source tree. If you have a <source dir>/prebuilts/su/su then it's ok. A common practice is to locate the prebuilts files either in the device/oem/hw path or the vendor/oem/ . Also the destination path should include the filename otherwise ( AFAIK ) the file in this case would be copied to system/xbin if the xbin directory was absent. I wouldn't expect that to ever be the case but obviously the same is true for all PRODUCT_COPY_FILES items. wrt to permissions, I think I've generally applied to permissions to the file before hand and they were retained during post copy. Although don't quote me on that one :) . Anyway the PRODUCT_COPY_FILES should at least look like this.

PRODUCT_COPY_FILES += prebuilts/su/su:system/xbin/su

Lunch will complain because the device.mk is processed as part of the lunch command sequence and the $(shell .. )  command is not inside a make recipe.

I originally refrained from suggesting the use of BUILD_PREBUILT but it's probably more suitable tbh .. The secret sauce here is LOCAL_POST_INSTALL_CMD something like this should do the trick

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := su
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 
LOCAL_UNSTRIPPED_PATH :=
LOCAL_POST_INSTALL_CMD := chmod 6755 $(TARGET_OUT_OPTIONAL_EXECUTABLES)/$(LOCAL_MODULE)
include $(BUILD_PREBUILT)

 Hope that helps
trevd

lee xiong

unread,
Sep 9, 2014, 12:54:58 AM9/9/14
to android-...@googlegroups.com
Hey trevd,

The 2 solutions you provided worked.
The "secret recipe" of LOCAL_POST_INSTALL_CMD is something that is not part of the Android Cookbook and not many people use this in their modified code or packages. After weeks of trying various ways, now I managed to get the su file into system/xbin/ and modify the permission of that file.
Thank you very much for the guidance. It has been of paramount help to me.
Have a great week.
Reply all
Reply to author
Forward
0 new messages