Creating Symbolic Links, Copy files using Android.mk and learn about permission changing inside init.rc
Its been long time I blogged, I learnt few things in Android.mk which I wanted to share with fellow members.
I started working on ICS Codebase where I have requirement to create Symbolic links, copy files/folders as part of prebuilt to /data and /system partitions and change the permissions during boot time via init.rc
Symbolic Links:
when you want to create symbolic link for a binary which is present in /system/bin the below code snippet will help you achieve the task
/system/bin/xyz -> /system/bin/abc
Pre-requisites:
Inside Android.mk create binary for abc which goes inside /system/bin
COMMANDS = xyz
SYMLINKS := $(addprefix $(TARGET_OUT_EXECUTABLES)/,$(COMMANDS))
$(SYMLINKS): ABC_BINARY := abc
$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
@echo "Symlink: $@ -> $(ABC_BINARY)"
@mkdir -p $(dir $@)
@rm -rf $@
$(hide) ln -sf $(ABC_BINARY) $@
ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
Explanation:
xyz would be your symbolic link for abc binary. The above code is self explanatory, please ping me if you dont understand.
Note: symlinks can be created inside init.rc also
ex: symlink /system/etc /etc
Copy files/folders:
PRODUCE_COPY_FILES += external/abc_folder/abc.conf:data/etc/abc.conf
The above command copies abc.conf file from external/abc_folder to /data/etc/ location. when you build and flash the binary you can verify the same in the adb shell
Changing Permissions and creating folders as part of system boot:
init.rc is the location which you need to address for achieving this task,
under on post-fs-data trigger inside init.rc
create below mentioned commands which will be reflected during your boot time.
mkdir /data/var
chmod 0755 /data/var
Its been long time I blogged, I learnt few things in Android.mk which I wanted to share with fellow members.
I started working on ICS Codebase where I have requirement to create Symbolic links, copy files/folders as part of prebuilt to /data and /system partitions and change the permissions during boot time via init.rc
Symbolic Links:
when you want to create symbolic link for a binary which is present in /system/bin the below code snippet will help you achieve the task
/system/bin/xyz -> /system/bin/abc
Pre-requisites:
Inside Android.mk create binary for abc which goes inside /system/bin
COMMANDS = xyz
SYMLINKS := $(addprefix $(TARGET_OUT_EXECUTABLES)/,$(COMMANDS))
$(SYMLINKS): ABC_BINARY := abc
$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
@echo "Symlink: $@ -> $(ABC_BINARY)"
@mkdir -p $(dir $@)
@rm -rf $@
$(hide) ln -sf $(ABC_BINARY) $@
ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
Explanation:
xyz would be your symbolic link for abc binary. The above code is self explanatory, please ping me if you dont understand.
Note: symlinks can be created inside init.rc also
ex: symlink /system/etc /etc
Copy files/folders:
PRODUCE_COPY_FILES += external/abc_folder/abc.conf:data/etc/abc.conf
The above command copies abc.conf file from external/abc_folder to /data/etc/ location. when you build and flash the binary you can verify the same in the adb shell
Changing Permissions and creating folders as part of system boot:
init.rc is the location which you need to address for achieving this task,
under on post-fs-data trigger inside init.rc
create below mentioned commands which will be reflected during your boot time.
mkdir /data/var
chmod 0755 /data/var