Custom Service is not running on IMX8QM-Android 9

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom Service is not running on IMX8QM-Android 9

Jump to solution
4,849 Views
vinothkumars
Senior Contributor IV

Dear NXP,

 

I am working on IMX8QM with Android 9. Currently, I am using imx-p9.0.0_2.1.1-auto-ga source. I added new service but, the service is not started automatically. So, I start the service manually then I got error,

mek_8q:/ #
mek_8q:/ # start usb-update
[ 192.968153] init: Received control message 'start' for 'usb-update' from pid: 3747 (start usb-update)
[ 192.977574] init: No such service 'usb-update' for ctl.start

Thanks & Regards,

VinothS,

Regards,
Vinothkumar Sekar
1 Solution
4,084 Views
vinothkumars
Senior Contributor IV

Hi,

This is the final configuration working for me,

1. Set Selinux policy to permissive mode,

   Path : device/fsl/imx8q/mek_8q/BoardConfig.mk       

   BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive

 2. Create the service,    
Path :  device/fsl/imx8q/mek_8q/init_car.rc


  # Start the service
  start usb-update 

   # Provide the root permission to the script   
  exec - root root system -- /system/bin/usb-update.sh

   # start the usb-update service   
  service usb-update /system/bin/usb-update.sh     
   class main     
   user root    
   oneshot     
   seclabel u:r:init:s0

3. For Adding the custom service,

   Path : device/fsl/imx8q/mek_8q/mek_8q.mk    
   
    PRODUCT_FULL_TREBLE_OVERRIDE := false

4. For execute the service,     
    Path : device/fsl/imx8q/sepolicy/file_contexts       
   
     /system/bin/usb-update.sh       u:object_r:init_exec:s0

Thanks & Regards,

VinothS,

Regards,
Vinothkumar Sekar

View solution in original post

8 Replies
4,085 Views
vinothkumars
Senior Contributor IV

Hi,

This is the final configuration working for me,

1. Set Selinux policy to permissive mode,

   Path : device/fsl/imx8q/mek_8q/BoardConfig.mk       

   BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive

 2. Create the service,    
Path :  device/fsl/imx8q/mek_8q/init_car.rc


  # Start the service
  start usb-update 

   # Provide the root permission to the script   
  exec - root root system -- /system/bin/usb-update.sh

   # start the usb-update service   
  service usb-update /system/bin/usb-update.sh     
   class main     
   user root    
   oneshot     
   seclabel u:r:init:s0

3. For Adding the custom service,

   Path : device/fsl/imx8q/mek_8q/mek_8q.mk    
   
    PRODUCT_FULL_TREBLE_OVERRIDE := false

4. For execute the service,     
    Path : device/fsl/imx8q/sepolicy/file_contexts       
   
     /system/bin/usb-update.sh       u:object_r:init_exec:s0

Thanks & Regards,

VinothS,

Regards,
Vinothkumar Sekar
4,084 Views
vinothkumars
Senior Contributor IV

Hi,

This is my configuration for lunch 36 ,

diff --git a/imx8q/mek_8q/BoardConfig.mk b/imx8q/mek_8q/BoardConfig.mk
index 1c681ed..5308567 100644
--- a/imx8q/mek_8q/BoardConfig.mk
+++ b/imx8q/mek_8q/BoardConfig.mk
@@ -165,6 +165,8 @@ else
BOARD_KERNEL_CMDLINE += androidboot.console=ttyLP0
endif

+BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive
+
ifeq ($(TARGET_USERIMAGES_USE_UBIFS),true)
ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
$(error "TARGET_USERIMAGES_USE_UBIFS and TARGET_USERIMAGES_USE_EXT4 config open in same time, please only choose one target file system image")
diff --git a/imx8q/mek_8q/init_car.rc b/imx8q/mek_8q/init_car.rc
index aed7c7a..6a0becf 100644
--- a/imx8q/mek_8q/init_car.rc
+++ b/imx8q/mek_8q/init_car.rc
@@ -16,6 +16,9 @@ on early-init
on init
start watchdogd

# Support legacy paths
symlink /sdcard /mnt/sdcard
symlink /sdcard /storage/sdcard0
@@ -287,6 +290,15 @@ on property:sys.boot_completed=1
write /sys/class/drm/card0-HDMI-A-2/status on
write /sys/class/drm/card1-HDMI-A-2/status on

+# start the usb-update service
+service usb-update /system/bin/usb-update.sh
+ class main
+ user root
+ oneshot
+ seclabel u:r:usb-update:s0
+
on post-fs-data
# Set netd memlock rlimit to 8MB
setrlimit 8 8388608 8388608
diff --git a/imx8q/mek_8q/mek_8q.mk b/imx8q/mek_8q/mek_8q.mk
index 3d0263b..453581a 100644
--- a/imx8q/mek_8q/mek_8q.mk
+++ b/imx8q/mek_8q/mek_8q.mk
@@ -18,7 +18,7 @@ endif
PRODUCT_NAME := mek_8q
PRODUCT_DEVICE := mek_8q

-PRODUCT_FULL_TREBLE_OVERRIDE := true
+PRODUCT_FULL_TREBLE_OVERRIDE := false

# Copy device related config and binary to board
PRODUCT_COPY_FILES += \
@@ -33,8 +33,8 @@ PRODUCT_COPY_FILES += \
$(IMX_DEVICE_PATH)/privapp-permissions-imx.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/privapp-permissions-imx.xml \
device/fsl/common/init/init.insmod.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.insmod.sh \
device/fsl/common/wifi/p2p_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/p2p_supplicant_overlay.conf \
- device/fsl/common/wifi/wpa_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant_overlay.conf
-
+ device/fsl/common/wifi/wpa_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant_overlay.conf \
+ device/fsl/imx8q/mek_8q/usb-update.sh:/system/bin/usb-update.sh

ifeq ($(PRODUCT_IMX_CAR),true)
PRODUCT_COPY_FILES += \
diff --git a/imx8q/sepolicy/init.te b/imx8q/sepolicy/init.te
index 9d2b22c..55645ef 100644
--- a/imx8q/sepolicy/init.te
+++ b/imx8q/sepolicy/init.te
@@ -19,3 +19,4 @@ allow init boot_block_device:lnk_file { relabelto };
allow init vbmeta_block_device:lnk_file { relabelto };
allow init sysfs_dm:file { write open };
allow init sysfs_devices_system_cpu:file { write };
+allow init usb-update_exec:process {transition};
diff --git a/imx8q/sepolicy/shell.te b/imx8q/sepolicy/shell.te
index ac32503..ba6188b 100644
--- a/imx8q/sepolicy/shell.te
+++ b/imx8q/sepolicy/shell.te
@@ -8,3 +8,4 @@ allow shell kernel:process { setsched };
dontaudit shell self:capability { dac_override };
allow shell vendor_file:file { read execute open getattr };
allow shell system_prop:property_service { set };
+allow shell usb-update_exec:file {read open};

Define sepolicy for usb-update ,

usb-update.te

# OBD service

type usb-update, domain;
type usb-update_exec, exec_type, file_type;

init_daemon_domain(usb-update)

domain_auto_trans(init, usb-update_exec, usb-update)

allow init usb-update:process transition;

Thanks & Regards,

VinothS.

Regards,
Vinothkumar Sekar
0 Kudos
4,084 Views
vinothkumars
Senior Contributor IV

Hi,

Please check the updated one,

emb-vinosek@IndVm:~/Documents/VINOTH/IndiEV-IMX8-A9/source/device/fsl/imx8q$ git diff
diff --git a/imx8q/mek_8q/BoardConfig.mk b/imx8q/mek_8q/BoardConfig.mk
index 1c681ed..5308567 100644
--- a/imx8q/mek_8q/BoardConfig.mk
+++ b/imx8q/mek_8q/BoardConfig.mk
@@ -165,6 +165,8 @@ else
BOARD_KERNEL_CMDLINE += androidboot.console=ttyLP0
endif

+BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive
+
ifeq ($(TARGET_USERIMAGES_USE_UBIFS),true)
ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
$(error "TARGET_USERIMAGES_USE_UBIFS and TARGET_USERIMAGES_USE_EXT4 config open in same time, please only choose one target file system image")
diff --git a/imx8q/mek_8q/init_car.rc b/imx8q/mek_8q/init_car.rc
index aed7c7a..697556a 100644
--- a/imx8q/mek_8q/init_car.rc
+++ b/imx8q/mek_8q/init_car.rc
@@ -287,6 +287,16 @@ on property:sys.boot_completed=1
write /sys/class/drm/card0-HDMI-A-2/status on
write /sys/class/drm/card1-HDMI-A-2/status on

+ exec u:r:shell:s0 shell shell input log adb sdcard_rw sdcard_r net_bt_admin net_bt inet net_bw_stats -- /system/bin/sh /system/bin/usb-update.sh start -n com.example.package/com.example.package.MainActivity
+
+on post-fs
+# start the usb-update service
+service usb-update /system/bin/usb-update.sh
+ class main
+ user root
+ oneshot
+ seclabel u:r:usb-update:s0
+
on post-fs-data
# Set netd memlock rlimit to 8MB
setrlimit 8 8388608 8388608
diff --git a/imx8q/mek_8q/mek_8q.mk b/imx8q/mek_8q/mek_8q.mk
index 3d0263b..453581a 100644
--- a/imx8q/mek_8q/mek_8q.mk
+++ b/imx8q/mek_8q/mek_8q.mk
@@ -18,7 +18,7 @@ endif
PRODUCT_NAME := mek_8q
PRODUCT_DEVICE := mek_8q

-PRODUCT_FULL_TREBLE_OVERRIDE := true
+PRODUCT_FULL_TREBLE_OVERRIDE := false

# Copy device related config and binary to board
PRODUCT_COPY_FILES += \
@@ -33,8 +33,8 @@ PRODUCT_COPY_FILES += \
$(IMX_DEVICE_PATH)/privapp-permissions-imx.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/privapp-permissions-imx.xml \
device/fsl/common/init/init.insmod.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.insmod.sh \
device/fsl/common/wifi/p2p_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/p2p_supplicant_overlay.conf \
- device/fsl/common/wifi/wpa_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant_overlay.conf
-
+ device/fsl/common/wifi/wpa_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant_overlay.conf \
+ device/fsl/imx8q/mek_8q/usb-update.sh:/system/bin/usb-update.sh

ifeq ($(PRODUCT_IMX_CAR),true)
PRODUCT_COPY_FILES += \
diff --git a/imx8q/sepolicy/file_contexts b/imx8q/sepolicy/file_contexts
index e281b5c..25a68dc 100644
--- a/imx8q/sepolicy/file_contexts
+++ b/imx8q/sepolicy/file_contexts
@@ -19,6 +19,7 @@
/dev/diag u:object_r:diag_device:s0
/vendor/bin/wcnss_filter u:object_r:wcnss_filter_exec:s0
/vendor/app(/.*)? u:object_r:same_process_hal_file:s0
+/system/bin/usb-update.sh u:object_r: usb-update_exec:s0
/data/vendor/ss(/.*)? u:object_r:tee_data_file:s0
/data/vendor/.opencl-cache(/.*)? u:object_r:opencl_cache_file:s0

---------------------------------------------------------------------------------------------------------

Define sepolicy for usb-update ,

usb-update.te

# OBD service

type usb-update, domain;
type usb-update_exec, exec_type, file_type;

init_daemon_domain(usb-update)

domain_auto_trans(init, usb-update_exec, usb-update)

Thanks & Regards,

VinothS.

Regards,
Vinothkumar Sekar
0 Kudos
4,084 Views
vinothkumars
Senior Contributor IV

Hi,

Still I am in the same issue. Let me know if I miss anything

Thanks & Regards,

VinothS,

Regards,
Vinothkumar Sekar
0 Kudos
4,084 Views
vinothkumars
Senior Contributor IV

Hi,

Custom service started probably but, I got error and service exit. 

SELinux:  Context u:object_r:usb-update_exec:s0 is not valid (left unmapped)

mek_8q:/ # start usb-update
[ 442.362348] init: Received control message 'start' for 'usb-update' from pid: 3538 (start usb-update)
[ 442.371635] init: starting service 'usb-update'...
[ 442.377693] init: cannot setexeccon('u:r:usb-update:s0') for usb-update: Invalid argument
mek_8q:/ # [ 442.386918] init: Service 'usb-update' (pid 3539) exited with status 6

Thanks & Regards,

VinothS,

Regards,
Vinothkumar Sekar
0 Kudos
4,084 Views
vinothkumars
Senior Contributor IV

Hi,

I am using "lunch 36". Is it give problem ?

Regards,

VinothS,

Regards,
Vinothkumar Sekar
0 Kudos
4,084 Views
diegoadrian
NXP Employee
NXP Employee

Hello,

Unfortunately, the creation and implementation of Android services are out of the scope of our free support. You could go with professional service support. They could help you with this problem. I apologize for the inconvenience this could give you.

Professional Support for Processors and Microcontrollers | NXP 

Best regards,

Diego.

0 Kudos
4,084 Views
vinothkumars
Senior Contributor IV

Thank you Diego.

Regards,

VinothS,

Regards,
Vinothkumar Sekar
0 Kudos