Howto opersys exercise


upload in try2 branch in gitlab


130|generic_x86_64:/ # service call opersys 3 i32 2728
10|generic_x86_64:/ # service call opersys 1 i32 2728
Result: Parcel(00000000 00000000 00000000 '............')
generic_x86_64:/ # service call opersys 2 i32 2728
Result: Parcel(
0x00000000: fffffffc 00000060 00740041 00650074 '....`...A.t.t.e.'
0x00000010: 0070006d 00200074 006f0074 00690020 'm.p.t. .t.o. .i.'
0x00000020: 0076006e 006b006f 00200065 00690076 'n.v.o.k.e. .v.i.'
0x00000030: 00740072 00610075 0020006c 0065006d 'r.t.u.a.l. .m.e.'
0x00000040: 00680074 0064006f 00270020 00790062 't.h.o.d. .'.b.y.'
0x00000050: 00650074 005d005b 006a0020 00760061 't.e.[.]. .j.a.v.'
0x00000060: 002e0061 0061006c 0067006e 0053002e 'a...l.a.n.g...S.'
0x00000070: 00720074 006e0069 002e0067 00650067 't.r.i.n.g...g.e.'
0x00000080: 00420074 00740079 00730065 00290028 't.B.y.t.e.s.(.).'
0x00000090: 00200027 006e006f 00610020 006e0020 ''. .o.n. .a. .n.'
0x000000a0: 006c0075 0020006c 0062006f 0065006a 'u.l.l. .o.b.j.e.'
0x000000b0: 00740063 00720020 00660065 00720065 'c.t. .r.e.f.e.r.'
0x000000c0: 006e0065 00650063 00000000 0000018c 'e.n.c.e.........'
0x000000d0: 000000c0 00610009 00200074 006f0063 '......a.t. .c.o.'
0x000000e0: 002e006d 006e0061 00720064 0069006f 'm...a.n.d.r.o.i.'
0x000000f0: 002e0064 00650073 00760072 00720065 'd...s.e.r.v.e.r.'
0x00000100: 004f002e 00650070 00730072 00730079 '..O.p.e.r.s.y.s.'
0x00000110: 00650053 00760072 00630069 002e0065 'S.e.r.v.i.c.e...'
0x00000120: 00720077 00740069 00280065 0070004f 'w.r.i.t.e.(.O.p.'
0x00000130: 00720065 00790073 00530073 00720065 'e.r.s.y.s.S.e.r.'
0x00000140: 00690076 00650063 006a002e 00760061 'v.i.c.e...j.a.v.'
0x00000150: 003a0061 00310034 000a0029 00610009 'a.:.4.1.).....a.'
0x00000160: 00200074 006e0061 00720064 0069006f 't. .a.n.d.r.o.i.'
0x00000170: 002e0064 0073006f 0049002e 0070004f 'd...o.s...I.O.p.'
0x00000180: 00720065 00790073 00530073 00720065 'e.r.s.y.s.S.e.r.'
0x00000190: 00690076 00650063 00530024 00750074 'v.i.c.e.$.S.t.u.'
0x000001a0: 002e0062 006e006f 00720054 006e0061 'b...o.n.T.r.a.n.'
0x000001b0: 00610073 00740063 00490028 0070004f 's.a.c.t.(.I.O.p.'
0x000001c0: 00720065 00790073 00530073 00720065 'e.r.s.y.s.S.e.r.'
0x000001d0: 00690076 00650063 006a002e 00760061 'v.i.c.e...j.a.v.'
0x000001e0: 003a0061 00340036 000a0029 00610009 'a.:.6.4.).....a.'
0x000001f0: 00200074 006e0061 00720064 0069006f 't. .a.n.d.r.o.i.'
0x00000200: 002e0064 0073006f 0042002e 006e0069 'd...o.s...B.i.n.'
0x00000210: 00650064 002e0072 00780065 00630065 'd.e.r...e.x.e.c.'
0x00000220: 00720054 006e0061 00610073 00740063 'T.r.a.n.s.a.c.t.'
0x00000230: 00420028 006e0069 00650064 002e0072 '(.B.i.n.d.e.r...'
0x00000240: 0061006a 00610076 0037003a 00310033 'j.a.v.a.:.7.3.1.'
0x00000250: 000a0029 00000000 ')....... ')
generic_x86_64:/ # service call opersys 3 i32 2728
Result: Parcel(00000000 '....')

generic_x86_64:/ # logcat | grep Opersys
generic_x86_64:/ # logcat | grep opersys
09-06 08:52:13.640 1810 1810 E vndksupport: Could not load /vendor/lib64/hw/android.hardware.opersys@2.0-impl.so from sphal namespace: dlopen failed: library "android.hardware.opersys@2.0.so" not found.
09-06 08:52:13.640 1810 1810 E ServiceManagement: Failed to dlopen android.hardware.opersys@2.0-impl.so: unknown error


try below to resolve?? SELinux : avc: denied { add } for service=opersys
follow to add entry "opersys u:object_r:serial_service:s0"
in these 2 file to make they has no diff.
system/sepolicy/private/service_contexts (opersys pdf slides only told this one)
system/sepolicy/prebuilts/api/28.0/private/service_contexts

after adding entry "opersys u:object_r:serial_service:s0" in service_contexts
"SELinux : avc: denied { add } for service=opersys" is gone!!
generic_x86_64:/ # logcat | grep persys
09-06 08:21:30.948 1956 1956 I SystemServer: StartOpersysService
09-06 08:21:30.948 1956 1956 I SystemServer: Opersys Service
09-06 08:21:31.307 1956 1956 D SystemServerTiming: StartOpersysService took to complete: 359ms

start checking....
generic_x86_64:/ # service list | grep opersys
38 opersys: [android.os.IOpersysService]

130|generic_x86_64:/ # ps -A | grep system_server
system 1956 1903 3291644 231788 ep_poll 7e593b6bf28a S system_server
generic_x86_64:/ # cat /proc/1956/maps | grep persys
7e58a28ce000-7e58a28e4000 r-xp 00000000 fd:01 167 /system/lib64/android.hardware.opersys@2.0.so
7e58a28e5000-7e58a28e7000 r--p 00016000 fd:01 167 /system/lib64/android.hardware.opersys@2.0.so
7e58a28e7000-7e58a28e8000 rw-p 00018000 fd:01 167 /system/lib64/android.hardware.opersys@2.0.so

generic_x86_64:/ # lshal | grep opersys
android.hardware.opersys@2.0::I*/* (/vendor/lib/hw/) N/A N/A
android.hardware.opersys@2.0::I*/* (/vendor/lib64/hw/) N/A N/A


build ok, run "$ emulator &", but sepolicy still not pass.
generic_x86_64:/ # lshal | grep opersys
android.hardware.opersys@2.0::I*/* (/vendor/lib/hw/) N/A N/A
android.hardware.opersys@2.0::I*/* (/vendor/lib64/hw/) N/A N/A

generic_x86_64:/ # logcat | grep persys
09-05 22:55:26.946 1854 1854 I SystemServer: StartOpersysService
09-05 22:55:26.946 1854 1854 I SystemServer: Opersys Service
09-05 22:55:26.951 1507 1507 E SELinux : avc: denied { add } for service=opersys pid=1854 uid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_manager permissive=0
09-05 22:55:26.951 1507 1507 E ServiceManager: add_service('opersys',64) uid=1000 - PERMISSION DENIED
09-05 22:55:26.951 1854 1854 E SystemServer: Failure starting OpersysService Service
09-05 22:55:27.208 1854 1854 D SystemServerTiming: StartOpersysService took to complete: 262ms


To avoid the following error, we copy the downloaded file: hardware/interfaces/opersys/2.0/default/Opersys.h to the same folder with Opersys.cpp
hardware/interfaces/opersys/2.0/default/Opersys.cpp:16:10: error: out-of-line definition of 'Opersys' does not match any declaration in 'android::hardware::opersys::V2_0::implementation::Opersys'
Opersys::Opersys(opersyshw_device_t *device) : mDevice(device) {
^~~~~~~
hardware/interfaces/opersys/2.0/default/Opersys.cpp:16:48: error: member initializer 'mDevice' does not name a non-static data member or base class
Opersys::Opersys(opersyshw_device_t *device) : mDevice(device) {
^~~~~~~~~~~~~~~
hardware/interfaces/opersys/2.0/default/Opersys.cpp:17:9: error: use of undeclared identifier 'mDevice'; did you mean 'device'?
if (mDevice)
^~~~~~~
device
hardware/interfaces/opersys/2.0/default/Opersys.cpp:16:38: note: 'device' declared here
Opersys::Opersys(opersyshw_device_t *device) : mDevice(device) {
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:21:10: error: definition of implicitly declared destructor
Opersys::~Opersys() {
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:22:12: error: use of undeclared identifier 'mDevice'
delete(mDevice);
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:35:19: error: use of undeclared identifier 'mDevice'
if ((retval = mDevice->read(intermediate_buffer, size)) < 0)
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:53:19: error: use of undeclared identifier 'mDevice'
if ((retval = mDevice->write(buffer.c_str(), buffer.size())) < 0)
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:66:12: error: use of undeclared identifier 'mDevice'
return mDevice->test(valueIn);
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:101:16: error: no matching constructor for initialization of 'android::hardware::opersys::V2_0::implementation::Opersys'
return new Opersys(opersys_device);
^ ~~~~~~~~~~~~~~
hardware/interfaces/opersys/2.0/default/Opersys.h:22:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'opersyshw_device_t *' (aka 'opersyshw_device *') to 'const android::hardware::opersys::V2_0::implementation::Opersys' for 1st argument
struct Opersys : public IOpersys {
^
hardware/interfaces/opersys/2.0/default/Opersys.h:22:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
9 errors generated.
[ 74% 79333/106795] //hardware/interfaces/power/1.2:andro...header-abi-dumper android/hardware/power/1.2/PowerAll.cpp
ninja: build stopped: subcommand failed.
21:50:16 ninja failed with: exit status 1

#### failed to build some targets (13:15 (mm:ss)) ####

FAILED: out/target/product/generic_x86_64/obj/ETC/sepolicy_freeze_test_intermediates/sepolicy_freeze_test
/bin/bash -c "(diff -rq system/sepolicy/prebuilts/api/28.0/public system/sepolicy/public ) && (diff -rq system/sepolicy/prebuilts/api/28.0/private system/sepolicy/private ) && (touch out/target/product/generic_x86_64/obj/ETC/sepolicy_freeze_test_intermediates/sepolicy_freeze_test )"
Files system/sepolicy/prebuilts/api/28.0/private/hwservice_contexts and system/sepolicy/private/hwservice_contexts differ
[ 3% 4137/106795] build out/target/product/generic_x86_6...e_sepolicy_tests_27.0_intermediates/27.0_plat_policy.conf
ninja: build stopped: subcommand failed.
23:23:42 ninja failed with: exit status 1


add items in shared_libs of Android.bp to avoid compile error about missing headers
./hardware/interfaces/opersys/2.0/default/Opersys.cpp
#include <log/log.h>
#include <hardware/hardware.h>
#include <hardware/opersyshw.h>
./hardware/interfaces/opersys/2.0/default/Android.bp
cc_library_shared {
// FIXME: this should only be -impl for a passthrough hal.
// In most cases, to convert this to a binderized implementation, you should:
// - change '-impl' to '-service' here and make it a cc_binary instead of a
// cc_library_shared.
// - add a *.rc file for this module.
// - delete HIDL_FETCH_I* functions.
// - call configureRpcThreadpool and registerAsService on the instance.
// You may also want to append '-impl/-service' with a specific identifier like
// '-vendor' or '-<hardware identifier>' etc to distinguish it.
name: "android.hardware.opersys@2.0-impl",
relative_install_path: "hw",
// FIXME: this should be 'vendor: true' for modules that will eventually be
// on AOSP.
proprietary: true,
srcs: [
"Opersys.cpp",
],
shared_libs: [
"liblog", (added by me)
"libhardware", (added by me)
"libhidlbase", (auto gen)
"libhidltransport", (auto gen)
"libutils", (auto gen)
"android.hardware.opersys@2.0", (auto gen)
],
}
header file : hardware/libhardware/include/hardware/
$ ll hardware/libhardware/include/hardware/
...
-rw-rw-r-- 1 samlee samlee 15522 Aug 15 16:21 gralloc.h
-rw-rw-r-- 1 samlee samlee 8063 Aug 15 16:21 hardware.h
...
-rw-r--r-- 1 samlee samlee 510 Feb 19 2018 opersyshw.h (added by me for Opersys.cpp )
...
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$


HIDL sha256 HSAH generator for new interface
https://emn178.github.io/online-tools/sha256.html

To avoid this compile erro , I did a hidl-gen from a clean ./opersys/2.0 folder with only 2 files ( types.hal, IOpersys.hal)
frameworks/base/services/core/jni/com_android_server_OpersysService.cpp:7:10: fatal error: 'android/hardware/opersys/2.0/IOpersys.h' file not found
#include
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

$ mkdir -p /mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces/opersys/2.0
$ cp IOpersys.hal /mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces/opersys/2.0
$ cp types.hal /mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces/opersys/2.0
./opersys/2.0/types.hal
./opersys/2.0/IOpersys.hal

$ croot
$ cd ./hardware/interfaces
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces $ ./update-makefiles.sh
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces$ find ./opersys/
./opersys/2.0/types.hal
./opersys/2.0/IOpersys.hal
./opersys/2.0/Android.bp

$ LOC=hardware/interfaces/opersys/2.0/default
$ PACKAGE=android.hardware.opersys@2.0

samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces/opersys/2.0$ echo $LOC
hardware/interfaces/opersys/2.0/default
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces/opersys/2.0$ echo $PACKAGE
android.hardware.opersys@2.0
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces/opersys/2.0$

$ croot
$ hidl-gen -o $LOC -Lc++-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
./opersys/2.0/types.hal
./opersys/2.0/Android.bp
./opersys/2.0/IOpersys.hal
./opersys/2.0/default/Opersys.cpp
./opersys/2.0/default/Opersys.h

$ hidl-gen -o $LOC -Landroidbp-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
./opersys/2.0/types.hal
./opersys/2.0/Android.bp
./opersys/2.0/IOpersys.hal
./opersys/2.0/default/Opersys.cpp
./opersys/2.0/default/Opersys.h
./opersys/2.0/default/Android.bp

upload to gitlab repository: https://gitlab.com/samhblee/opersys-android-9.0.0_r39


App for opersys
/mnt/sw/android/bsp/android-9.0.0_r39/packages/apps/HelloOpersysInternal

temporarily commented out .write() and .read() to avoid compile error.
//om.write("Hello Opersys");
//Log.d(DTAG, "Service returned: " + om.read(20));

APPS/HelloOpersysInternal_intermediates/classes; echo \"-C out/empty .\") )"
packages/apps/HelloOpersysInternal/src/com/opersys/hellointernal/HelloOpersysInternalActivity.java:21: error: cannot find symbol
om.write("Hello Opersys");
^
symbol: method write(String)
location: variable om of type IOpersysService
packages/apps/HelloOpersysInternal/src/com/opersys/hellointernal/HelloOpersysInternalActivity.java:22: error: cannot find symbol
Log.d(DTAG, "Service returned: " + om.read(20));
^
symbol: method read(int)
location: variable om of type IOpersysService
2 errors


./android-9.0.0_r39/packages/apps/HelloOpersysInternal/Android.mk
add this line to make build can find symbol from android.os etc
LOCAL_PRIVATE_PLATFORM_APIS=true

samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ mmm ./packages/apps/HelloOpersysInternal

packages/apps/HelloOpersysInternal/src/com/opersys/hellointernal/HelloOpersysInternalActivity.java:6: error: cannot find symbol
import android.os.ServiceManager; // Will only work in AOSP
^
symbol: class ServiceManager
location: package android.os
packages/apps/HelloOpersysInternal/src/com/opersys/hellointernal/HelloOpersysInternalActivity.java:7: error: cannot find symbol
import android.os.IOpersysService; // Interface "hidden" in SDK
^
symbol: class IOpersysService
location: package android.os
packages/apps/HelloOpersysInternal/src/com/opersys/hellointernal/HelloOpersysInternalActivity.java:18: error: cannot find symbol
IOpersysService om = IOpersysService.Stub.asInterface(ServiceManager.getService("opersys"));
^
symbol: class IOpersysService
location: class HelloOpersysInternalActivity
packages/apps/HelloOpersysInternal/src/com/opersys/hellointernal/HelloOpersysInternalActivity.java:18: error: package IOpersysService does not exist
IOpersysService om = IOpersysService.Stub.asInterface(ServiceManager.getService("opersys"));
^
packages/apps/HelloOpersysInternal/src/com/opersys/hellointernal/HelloOpersysInternalActivity.java:18: error: cannot find symbol
IOpersysService om = IOpersysService.Stub.asInterface(ServiceManager.getService("opersys"));
^
symbol: variable ServiceManager
location: class HelloOpersysInternalActivity
5 errors



Add HAL module in Android9.0 (HIDL)
check if a specific HAL is running:
generic_x86_64:/ # lshal | grep opersys
android.hardware.opersys@2.0::I*/* (/vendor/lib/hw/) N/A N/A
android.hardware.opersys@2.0::I*/* (/vendor/lib64/hw/) N/A N/A

generic_x86_64: # cd /vendor/lib64/hw
generic_x86_64:/vendor/lib64/hw # ls -al | grep opersys
-rw-r--r-- 1 root root 19216 2019-08-26 16:21 android.hardware.opersys@2.0-impl.so
-rw-r--r-- 1 root root 6936 2019-08-26 16:17 opersyshw.ranchu.so

generic_x86_64:/vendor/lib64/hw # ps -A | grep system_server
system 1944 1897 3289508 233648 ep_poll 7fd5920fe28a S system_server

generic_x86_64:/vendor/lib64/hw # cat /proc/1944/maps | grep opersys
7fd4fb210000-7fd4fb226000 r-xp 00000000 fd:01 167 /system/lib64/android.hardware.opersys@2.0.so
7fd4fb227000-7fd4fb229000 r--p 00016000 fd:01 167 /system/lib64/android.hardware.opersys@2.0.so
7fd4fb229000-7fd4fb22a000 rw-p 00018000 fd:01 167 /system/lib64/android.hardware.opersys@2.0.so


add code for HAL
1. We will use the code from the following tarball for this hands-on session:
For the Hikey board:
http://opersys.com/downloads/libhw-opersys-hikey-8.1-180404.tar.bz2
For the emulator:
http://opersys.com/downloads/libhw-opersys-goldfish-9.0-190530.tar.bz2

28.txt


[ 4% 4714/106797] build out/target/product/generic_x86_64/obj/ETC/sepolicy_freeze_test_intermediates/sepolicy_freeze_test
FAILED: out/target/product/generic_x86_64/obj/ETC/sepolicy_freeze_test_intermediates/sepolicy_freeze_test
/bin/bash -c "(diff -rq system/sepolicy/prebuilts/api/28.0/public system/sepolicy/public ) && (diff -rq system/sepolicy/prebuilts/api/28.0/private system/sepolicy/private ) && (touch out/target/product/generic_x86_64/obj/ETC/sepolicy_freeze_test_intermediates/sepolicy_freeze_test )"
Files system/sepolicy/prebuilts/api/28.0/private/hwservice_contexts and system/sepolicy/private/hwservice_contexts differ
$ meld system/sepolicy/prebuilts/api/28.0/private/hwservice_contexts system/sepolicy/private/hwservice_contexts


copy opersyshw folder into aosp's device/generic/goldfish/operasyshw
./device/generic/goldfish/opersyshw/Android.mk
LOCAL_MODULE := opersyshw.ranchu



WHY No android.hardware.opersys@2.0-impl.so compiled in out folder
we need to modify /device/generic/goldfish/vendor.mk
add the name which also defined in hardware/interfaces/opersys/2.0/default/Android.bp
./2.0/default/Android.bp ( name: "android.hardware.opersys@2.0-impl",)
THEN compile error shows up!!
/opersys/2.0/default/Opersys.o' hardware/interfaces/opersys/2.0/default/Opersys.cpp
hardware/interfaces/opersys/2.0/default/Opersys.cpp:16:10: error: out-of-line definition of 'Opersys' does not match any declaration in 'android::hardware::opersys::V2_0::implementation::Opersys'
Opersys::Opersys(opersyshw_device_t *device) : mDevice(device) {
^~~~~~~
hardware/interfaces/opersys/2.0/default/Opersys.cpp:16:48: error: member initializer 'mDevice' does not name a non-static data member or base class
Opersys::Opersys(opersyshw_device_t *device) : mDevice(device) {
^~~~~~~~~~~~~~~
hardware/interfaces/opersys/2.0/default/Opersys.cpp:17:9: error: use of undeclared identifier 'mDevice'; did you mean 'device'?
if (mDevice)
^~~~~~~
device
hardware/interfaces/opersys/2.0/default/Opersys.cpp:16:38: note: 'device' declared here
Opersys::Opersys(opersyshw_device_t *device) : mDevice(device) {
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:21:10: error: definition of implicitly declared destructor
Opersys::~Opersys() {
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:22:12: error: use of undeclared identifier 'mDevice'
delete(mDevice);
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:35:19: error: use of undeclared identifier 'mDevice'
if ((retval = mDevice->read(intermediate_buffer, size)) < 0)
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:53:19: error: use of undeclared identifier 'mDevice'
if ((retval = mDevice->write(buffer.c_str(), buffer.size())) < 0)
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:66:12: error: use of undeclared identifier 'mDevice'
return mDevice->test(valueIn);
^
hardware/interfaces/opersys/2.0/default/Opersys.cpp:101:16: error: no matching constructor for initialization of 'android::hardware::opersys::V2_0::implementation::Opersys'
return new Opersys(opersys_device);
^ ~~~~~~~~~~~~~~
hardware/interfaces/opersys/2.0/default/Opersys.h:22:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'opersyshw_device_t *' (aka 'opersyshw_device *') to 'const android::hardware::opersys::V2_0::implementation::Opersys' for 1st argument
struct Opersys : public IOpersys {
^
hardware/interfaces/opersys/2.0/default/Opersys.h:22:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
9 errors generated.






modify /device/generic/goldfish/manifest.xml to add HIDL interface
>android.hardware.opersys
passthrough
2.0
IOpersys
default



copy com_android_server_OpersysService.cpp to frameworks/base/services/core/jni/


modify onload.cpp in ./framworks/base/services/core/jni/ to add register_android_server_OpersysService(JNIEnv* env);



modify Android.bp in ./framworks/base/services/core/jni/ to
add src of com_android_server_OpersysService.cpp
& add shared_libs: android.hardware.opersys@2.0 (will built in ./hardware/interfaces/opersys/2.0





copy /opersys folder into $croot/hardware/interfaces/
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/hardware/interfaces/opersys$ find .
./Android.bp (generated after running ./update-makefiles.sh)
./2.0
./2.0/types.hal (provided by developer)
./2.0/Android.bp & Android.mk (generated by ./update-makefiles.sh)
./2.0/IOpersys.hal (provided by developer)
./2.0/default
./2.0/default/Opersys.cpp (auto created by hidl-gen)
./2.0/default/Opersys.h (auto created by hidl-gen)
./2.0/default/Android.bp ( name: "android.hardware.opersys@2.0-impl",)

https://youtu.be/UFaWqdxBW4E?t=4303







https://source.android.com/devices/architecture/hidl-cpp#creating-the-hal-server
To create the necessary files to implement your HAL:
$ croot && cd ./hardware/interfaces/opersys/2.0
$ export LOC=hardware/interfaces/opersys/2.0/default
$ export PACKAGE=android.hardware.opersys@2.0
$ croot
$ hidl-gen -o $LOC -Lc++-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
(let AOSP to auto generate the default implementation: Opersys.cpp & Opersys.h )


$ croot
$ hidl-gen -o $LOC -Landroidbp-iml -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
(let AOSP to auto generate Android.bp for Opersys.cpp & Opersys.h in default implementation)







copy opersyshw.h into /hardware/libhardware/include/hardware
/hardware/libhardware/include/hardware/opersyshw.h is included by hardware/interface/opersys/2.0/default/Opersys.cpp file.


sepolicy avc denied
generic_x86_64:/ # logcat | grep persys
09-04 21:51:24.826 1870 1870 I SystemServer: StartOpersysService
09-04 21:51:24.826 1870 1870 I SystemServer: Opersys Service
09-04 21:51:24.826 1505 1505 E SELinux : avc: denied { find } for interface=android.hardware.opersys::IOpersys sid=u:r:system_server:s0 pid=1870 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_hwservice:s0 tclass=hwservice_manager permissive=0
09-04 21:51:24.827 1504 1504 E SELinux : avc: denied { add } for service=opersys pid=1870 uid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_manager permissive=0
09-04 21:51:24.827 1504 1504 E ServiceManager: add_service('opersys',64) uid=1000 - PERMISSION DENIED
09-04 21:51:24.827 1870 1870 E SystemServer: Failure starting OpersysService Service
09-04 21:51:25.091 1870 1870 D SystemServerTiming: StartOpersysService took to complete: 265ms

modify /system/sepolicy/private/hwservice_contexts to add android.hardware.opersys::IOpersys

generic_x86_64:/ # logcat | grep persys
09-04 22:33:14.699 1794 1794 I SystemServer: StartOpersysService
09-04 22:33:14.699 1794 1794 I SystemServer: Opersys Service
09-04 22:33:14.700 1794 1794 I OpersysService: System service initialized
09-04 22:33:14.700 1496 1496 W hwservicemanager: getTransport: Cannot find entry android.hardware.opersys@2.0::IOpersys/default in either framework or device manifest.
09-04 22:33:14.700 1794 1794 E OpersysService: Unable to get IOpersys interface.
09-04 22:33:14.700 1794 1794 I OpersysService: test() returns 0
09-04 22:33:14.700 1794 1794 I OpersysService: read() returns
09-04 22:33:14.700 1495 1495 E SELinux : avc: denied { add } for service=opersys pid=1794 uid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_manager permissive=0
09-04 22:33:14.700 1495 1495 E ServiceManager: add_service('opersys',64) uid=1000 - PERMISSION DENIED
09-04 22:33:14.700 1794 1794 E SystemServer: Failure starting OpersysService Service
09-04 22:33:14.844 1794 1794 D SystemServerTiming: StartOpersysService took to complete: 145ms

add below code in ./device/generic/goldfish/manifest.xml
>android.hardware.opersys
passthrough
2.0
IOpersys
default

then,
samlee@PCRD1448:/mnt/mx200_sw/sw/android/bsp/opersys-android-9.0.0_r39$ adb shell logcat | grep persys
09-04 22:40:16.381 1809 1809 I SystemServer: StartOpersysService
09-04 22:40:16.381 1809 1809 I SystemServer: Opersys Service
09-04 22:40:16.381 1809 1809 I OpersysService: System service initialized
09-04 22:40:16.381 1809 1809 E OpersysService: Unable to get IOpersys interface.
09-04 22:40:16.381 1809 1809 I OpersysService: test() returns 0
09-04 22:40:16.381 1809 1809 I OpersysService: read() returns
09-04 22:40:16.381 1494 1494 E SELinux : avc: denied { add } for service=opersys pid=1809 uid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_manager permissive=0
09-04 22:40:16.381 1494 1494 E ServiceManager: add_service('opersys',64) uid=1000 - PERMISSION DENIED
09-04 22:40:16.381 1809 1809 E SystemServer: Failure starting OpersysService Service
09-04 22:40:17.792 2120 2120 I SystemServer: StartOpersysService
09-04 22:40:17.792 2120 2120 I SystemServer: Opersys Service
09-04 22:40:17.792 1494 1494 E SELinux : avc: denied { add } for service=opersys pid=2120 uid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_manager permissive=0
09-04 22:40:17.792 1494 1494 E ServiceManager: add_service('opersys',64) uid=1000 - PERMISSION DENIED
09-04 22:40:17.793 2120 2120 E SystemServer: Failure starting OpersysService Service
09-04 22:40:17.925 2120 2120 D SystemServerTiming: StartOpersysService took to complete: 133ms

modify /system/sepolicy/vendor/file_contexts to add android.hardware.opersys@2.0-impl.so with sepolicy




Add Kernel driver

check the kernel module via /dev/circcar sysfs
generic_x86_64:/ # echo 19191 > /dev/circchar
generic_x86_64:/ # cat /dev/circchar
19191


add a Linux Device Driver in AOSP device folder (not kernel folder!!)

samlee@PCRD1448:/mnt/SSD500G/operasys/ForAosp$ cp -a circular-driver /mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/

samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver$ code Makefile


samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver$ make ARCH=x86 CROSS_COMPILE=x86_64-linux-android-
make -C /mnt/sw/android/bsp/android-9.0.0_r39/kernel/goldfish M=/mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver modules
make[1]: Entering directory '/mnt/sw/android/bsp/kernel/goldfish'
CC [M] /mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver/circular-char.o
/mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver/circular-char.c: In function 'circ_char_enter':
/mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver/circular-char.c:87:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
printk("mmap is %08X\n", (int) fops.mmap);
^
Building modules, stage 2.
MODPOST 1 modules
CC /mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver/circular-char.mod.o
LD [M] /mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver/circular-char.ko
make[1]: Leaving directory '/mnt/sw/android/bsp/kernel/goldfish'

#### build completed successfully (2 seconds) ####
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/device/generic/goldfish/circular-driver$ ls -al
total 364
drwxr-xr-x 3 samlee samlee 4096 Aug 22 18:21 .
drwxrwxr-x 29 samlee samlee 4096 Aug 22 16:23 ..
-rw-r--r-- 1 samlee samlee 1925 Oct 25 2011 circular-char.c
-rw-r--r-- 1 samlee samlee 152920 Aug 22 18:21 circular-char.ko
-rw-r--r-- 1 samlee samlee 476 Aug 22 18:21 .circular-char.ko.cmd
-rw-r--r-- 1 samlee samlee 930 Aug 22 18:21 circular-char.mod.c
-rw-r--r-- 1 samlee samlee 43048 Aug 22 18:21 circular-char.mod.o
-rw-r--r-- 1 samlee samlee 27798 Aug 22 18:21 .circular-char.mod.o.cmd
-rw-r--r-- 1 samlee samlee 75584 Aug 22 18:21 circular-char.o
-rw-r--r-- 1 samlee samlee 29937 Aug 22 18:21 .circular-char.o.cmd
-rw-r--r-- 1 samlee samlee 465 Aug 22 18:21 Makefile
-rw-r--r-- 1 samlee samlee 102 Aug 22 18:21 modules.order
-rw-r--r-- 1 samlee samlee 0 Aug 22 18:21 Module.symvers
drwxr-xr-x 2 samlee samlee 4096 Aug 22 18:21 .tmp_versions

samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ code device/generic/goldfish/init.ranchu.rc
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ code device/generic/goldfish/ueventd.ranchu.rc



2147 code system/sepolicy/public/init.te
2150 code system/sepolicy/prebuilts/api/28.0/public/init.te


2149 code system/sepolicy/prebuilts/api/28.0/public/file_contexts
2160 code system/sepolicy/prebuilts/api/28.0/private/file_contexts




Add Service

check running service and send call to this service
130|generic_x86_64:/ # service check opersys
Service opersys: found
generic_x86_64:/ # logcat | grep Opersys
08-22 15:29:42.785 1908 1908 I SystemServer: StartOpersysService
08-22 15:29:42.785 1908 1908 I SystemServer: Opersys Service
08-22 15:29:42.785 1908 1908 D SystemServerTiming: StartOpersysService took to complete: 0ms
^C
130|generic_x86_64:/ # service call opersys 1 i32 2728
Result: Parcel(00000000 '....')
generic_x86_64:/ # logcat | grep Opersys
08-22 15:29:42.785 1908 1908 I SystemServer: StartOpersysService
08-22 15:29:42.785 1908 1908 I SystemServer: Opersys Service
08-22 15:29:42.785 1908 1908 D SystemServerTiming: StartOpersysService took to complete: 0ms
08-22 15:33:03.204 1908 2099 I OpersysService: test 2728
^[[A^C
130|generic_x86_64:/ # service call opersys 3 i32 2728
Result: Parcel(Error: 0xffffffffffffffb6 "Not a data message")
generic_x86_64:/ # service call opersys 2 i32 2728
Result: Parcel(Error: 0xffffffffffffffb6 "Not a data message")
generic_x86_64:/ # service call opersys 1 i32 2728
Result: Parcel(00000000 '....')
generic_x86_64:/ # logcat | grep Opersys
08-22 15:29:42.785 1908 1908 I SystemServer: StartOpersysService
08-22 15:29:42.785 1908 1908 I SystemServer: Opersys Service
08-22 15:29:42.785 1908 1908 D SystemServerTiming: StartOpersysService took to complete: 0ms
08-22 15:33:03.204 1908 2099 I OpersysService: test 2728
08-22 15:34:53.629 1908 2026 I OpersysService: test 2728

OpersysService.java build error
All methods in OpersysService.java must match what's defined in IOpersysService.aidl (so I removed read, write method to avoid build error!)
OpersysService.java

frameworks/base/services/core/java/com/android/server/OpersysService.java:7: error: OpersysService is not abstract and does not override abstract method write(String) in IOpersysService
public class OpersysService extends IOpersysService.Stub {
^
1 error

/mnt/sw/android/bsp/android-9.0.0_r39/frameworks/base/Android.bp
java_library {
name: "framework",

srcs: [
...
"core/java/android/os/IPowerManager.aidl",
"core/java/android/os/IOpersysService.aidl",
..
compare with IPowerManager.aidl converted to IPowerManager.java here:
/mnt/sw/android/bsp/android-9.0.0_r39/out/soong/.intermediates/frameworks/base/framework/android_common/gen/aidl/frameworks/base/core/java/android/os/IPowerManager.java

/mnt/sw/android/bsp/android-.0.0_r39/out/soong/.intermediates/frameworks/base/framework/android_common/gen/aidl/frameworks/base/core/java/android/os/IOpersysService.java

Selinux build error in Android 9 emulator
Files system/sepolicy/prebuilts/api/28.0/private/service_contexts and system/sepolicy/private/service_contexts differ
follow this error to add entry "opersys u:object_r:serial_service:s0"
in these 2 file to make they has no diff.
system/sepolicy/private/service_contexts (opersys pdf slides only told this one)
system/sepolicy/prebuilts/api/28.0/private/service_contexts
then
$ touch /system/sepolicy/Android.bp
$ make -j24
$ emulator &

needs to modify 11 files?
http://www.programmersought.com/article/3776273097/
need to modify 10 files?
https://www.itread01.com/content/1543159215.html

add a opersys service
ps. TI wiki also intro. similar thing http://processors.wiki.ti.com/index.php/Android-Adding_SystemService
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ find ./frameworks/base/ | grep 'Opersys*'
./frameworks/base/core/java/android/os/IOpersysService.aidl
./frameworks/base/services/core/java/com/android/server/OpersysService.java



samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ cat ./frameworks/base/Android.bp | grep Opersys
"core/java/android/os/IOpersysService.aidl",


samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ find ./frameworks/base/ | grep 'SystemServer'
./frameworks/base/services/core/java/com/android/server/SystemServerInitThreadPool.java
./frameworks/base/services/core/jni/com_android_server_SystemServer.cpp
./frameworks/base/services/java/com/android/server/SystemServer.java

$ code ./frameworks/base/services/java/com/android/server/SystemServer.java
add line 1406 ~1413 in SystemServer.java



modify the selinux policies in order to allow your system service to be registered.
To do so, modify the "system/sepolicy/private/service_contexts" file to add this entry: opersys u:object_r:serial_service:s0
$ code



build error (Emulator has no root folder in out/target/product/generic_x86_64/ )
[ 4% 4779/106706] Install: out/target/product/generic_x86_64/system/glibc/rootfs-glibc
FAILED: out/target/product/generic_x86_64/system/glibc/rootfs-glibc
/bin/bash -c "(rm -f out/target/product/generic_x86_64/system/glibc/rootfs-glibc ) && (cp out/target/product/generic_x86_64/obj/ETC/rootfs-glibc_intermediates/rootfs-glibc out/target/product/generic_x86_64/system/glibc/rootfs-glibc ) && (
mkdir -p out/target/product/generic_x86_64/system/glibc;
cp -af rootfs-glibc/rootfs/* out/target/product/generic_x86_64/system/glibc;
ln -fs system/glibc/bin out/target/product/generic_x86_64/root/bin;
ln -fs system/glibc/lib out/target/product/generic_x86_64/root/lib;
ln -fs system/glibc/lib out/target/product/generic_x86_64/root/lib64 )"
ln: failed to create symbolic link 'out/target/product/generic_x86_64/root/bin': No such file or directory
ln: failed to create symbolic link 'out/target/product/generic_x86_64/root/lib': No such file or directory
ln: failed to create symbolic link 'out/target/product/generic_x86_64/root/lib64': No such file or directory
[ 4% 4802/106706] target C++: libtextclassifier_32 <= external/libtextclassifier/text-classifier.cc
ninja: build stopped: subcommand failed.
18:28:00 ninja failed with: exit status 1
#### failed to build some targets (03:34 (mm:ss)) ####samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$



samlee@PCRD1448:/mnt/SSD500G/operasys/ForAosp$ mkdir -p /mnt/sw/android/bsp/android-9.0.0_r39/frameworks/base/cmds/server
samlee@PCRD1448:/mnt/SSD500G/operasys/ForAosp$ cp server.c /mnt/sw/android/bsp/android-9.0.0_r39/frameworks/base/cmds/server
$ code /mnt/sw/android/bsp/android-9.0.0_r39/frameworks/base/cmds/server/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
server.c

LOCAL_SHARED_LIBRARIES := \
libcutils

LOCAL_MODULE:= server

include $(BUILD_EXECUTABLE)




add server as package in core.mk



$ cp /mnt/SSD500G/operasys/ForAosp/client.c /mnt/SSD500G/operasys/Forx86-64/custom-x86/rootfs/bin/

samlee@PCRD1448:/mnt/SSD500G/operasys/Forx86-64/custom-x86/rootfs/bin$ ${PRJROOT}/tools/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-gcc -o client client.c


samlee@PCRD1448:/mnt/SSD500G/operasys/Forx86-64/custom-x86$ cp -va /mnt/SSD500G/operasys/Forx86-64/custom-x86/rootfs/bin/client /mnt/sw/android/bsp/android-9.0.0_r39/rootfs-glibc/rootfs/bin/
'/mnt/SSD500G/operasys/Forx86-64/custom-x86/rootfs/bin/client' -> '/mnt/sw/android/bsp/android-9.0.0_r39/rootfs-glibc/rootfs/bin/client'


samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ code ./build/target/product/emulator.mk

Sample code
C code for a very simple client and server are provided for you. These communicate using stream sockets in the Internet domain. The code is described in detail below. However, before you read the descriptions and look at the code, you should compile and run the two programs to see what they do.

server.c http://www.linuxhowtos.org/data/6/server.c
client.c http://www.linuxhowtos.org/data/6/client.c

Download these into files called server.c and client.c and compile them separately into two executables called server and client.

copy rootfs into a new folder in AOSP tree
samlee@PCRD1448:/mnt/SSD500G/operasys/Forx86-64/custom-x86$ cp -a ${PRJROOT}/rootfs /mnt/sw/android/bsp/android-9.0.0_r39/rootfs-glibc
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ ls -al ./rootfs-glibc
total 20
drwxr-xr-x 3 samlee samlee 4096 Aug 21 16:56 .
drwxrwxr-x 30 samlee samlee 4096 Aug 21 16:51 ..
-rw-rw-r-- 1 samlee samlee 515 Aug 21 16:56 Android.mk
-rw-rw-r-- 1 samlee samlee 515 Aug 21 15:06 glibcroot-Android-sys.mk
drwxrwxr-x 8 samlee samlee 4096 Aug 21 16:32 rootfs
-rw-r--r-- 1 samlee samlee 0 Aug 21 16:51 stub

samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ code ./build/target/product/emulator.mk



check rootfs folder with glibc & busybox in opersys working folder
samlee@PCRD1448:/mnt/SSD500G/operasys/Forx86-64/custom-x86/rootfs$ tree .
.
├── bin
│ ├── ash -> busybox
│ ├── base64 -> busybox
│ ├── busybox
│ ├── cat -> busybox
│ ├── catv -> busybox
│ ├── chattr -> busybox
│ ├── chgrp -> busybox
│ ├── chmod -> busybox
│ ├── chown -> busybox
│ ├── conspy -> busybox
│ ├── cp -> busybox
│ ├── cpio -> busybox
│ ├── cttyhack -> busybox
│ ├── date -> busybox
│ ├── dd -> busybox
│ ├── df -> busybox
│ ├── dmesg -> busybox
│ ├── dnsdomainname -> busybox
│ ├── dumpkmap -> busybox
│ ├── echo -> busybox
│ ├── ed -> busybox
│ ├── egrep -> busybox
│ ├── false -> busybox
│ ├── fatattr -> busybox
│ ├── fdflush -> busybox
│ ├── fgrep -> busybox
│ ├── fsync -> busybox
│ ├── getopt -> busybox
│ ├── grep -> busybox
│ ├── gunzip -> busybox
│ ├── gzip -> busybox
│ ├── hostname -> busybox
│ ├── hush -> busybox
│ ├── ionice -> busybox
│ ├── iostat -> busybox
│ ├── ipcalc -> busybox
│ ├── kbd_mode -> busybox
│ ├── kill -> busybox
│ ├── linux32 -> busybox
│ ├── linux64 -> busybox
│ ├── ln -> busybox
│ ├── login -> busybox
│ ├── ls -> busybox
│ ├── lsattr -> busybox
│ ├── lzop -> busybox
│ ├── makemime -> busybox
│ ├── mkdir -> busybox
│ ├── mknod -> busybox
│ ├── mktemp -> busybox
│ ├── more -> busybox
│ ├── mount -> busybox
│ ├── mountpoint -> busybox
│ ├── mpstat -> busybox
│ ├── mt -> busybox
│ ├── mv -> busybox
│ ├── netstat -> busybox
│ ├── nice -> busybox
│ ├── pidof -> busybox
│ ├── ping -> busybox
│ ├── ping6 -> busybox
│ ├── pipe_progress -> busybox
│ ├── printenv -> busybox
│ ├── ps -> busybox
│ ├── pwd -> busybox
│ ├── reformime -> busybox
│ ├── rev -> busybox
│ ├── rm -> busybox
│ ├── rmdir -> busybox
│ ├── rpm -> busybox
│ ├── run-parts -> busybox
│ ├── scriptreplay -> busybox
│ ├── sed -> busybox
│ ├── setarch -> busybox
│ ├── setserial -> busybox
│ ├── sh -> busybox
│ ├── sleep -> busybox
│ ├── stat -> busybox
│ ├── stty -> busybox
│ ├── su -> busybox
│ ├── sync -> busybox
│ ├── tar -> busybox
│ ├── touch -> busybox
│ ├── true -> busybox
│ ├── umount -> busybox
│ ├── uname -> busybox
│ ├── usleep -> busybox
│ ├── vi -> busybox
│ ├── watch -> busybox
│ └── zcat -> busybox
├── lib
│ ├── ld-2.21.so
│ ├── ld-linux-x86-64.so.2 -> ld-2.21.so
│ ├── libanl-2.21.so
│ ├── libanl.so.1 -> libanl-2.21.so
│ ├── libatomic.a
│ ├── libatomic.la
│ ├── libatomic.so -> libatomic.so.1.1.0
│ ├── libatomic.so.1 -> libatomic.so.1.1.0
│ ├── libatomic.so.1.1.0
│ ├── libBrokenLocale-2.21.so
│ ├── libBrokenLocale.so.1 -> libBrokenLocale-2.21.so
│ ├── libc-2.21.so
│ ├── libcrypt-2.21.so
│ ├── libcrypt.so.1 -> libcrypt-2.21.so
│ ├── libc.so.6 -> libc-2.21.so
│ ├── libdl-2.21.so
│ ├── libdl.so.2 -> libdl-2.21.so
│ ├── libgcc_s.so -> libgcc_s.so.1
│ ├── libgcc_s.so.1
│ ├── libm-2.21.so
│ ├── libmemusage.so
│ ├── libm.so.6 -> libm-2.21.so
│ ├── libnsl-2.21.so
│ ├── libnsl.so.1 -> libnsl-2.21.so
│ ├── libnss_compat-2.21.so
│ ├── libnss_compat.so.2 -> libnss_compat-2.21.so
│ ├── libnss_db-2.21.so
│ ├── libnss_db.so.2 -> libnss_db-2.21.so
│ ├── libnss_dns-2.21.so
│ ├── libnss_dns.so.2 -> libnss_dns-2.21.so
│ ├── libnss_files-2.21.so
│ ├── libnss_files.so.2 -> libnss_files-2.21.so
│ ├── libnss_hesiod-2.21.so
│ ├── libnss_hesiod.so.2 -> libnss_hesiod-2.21.so
│ ├── libnss_nis-2.21.so
│ ├── libnss_nisplus-2.21.so
│ ├── libnss_nisplus.so.2 -> libnss_nisplus-2.21.so
│ ├── libnss_nis.so.2 -> libnss_nis-2.21.so
│ ├── libpcprofile.so
│ ├── libpthread-2.21.so
│ ├── libpthread.so.0 -> libpthread-2.21.so
│ ├── libresolv-2.21.so
│ ├── libresolv.so.2 -> libresolv-2.21.so
│ ├── librt-2.21.so
│ ├── librt.so.1 -> librt-2.21.so
│ ├── libSegFault.so
│ ├── libthread_db-1.0.so
│ ├── libthread_db.so.1 -> libthread_db-1.0.so
│ ├── libutil-2.21.so
│ └── libutil.so.1 -> libutil-2.21.so
├── linuxrc -> bin/busybox
├── mkdir
├── sbin
│ ├── acpid -> ../bin/busybox
│ ├── adjtimex -> ../bin/busybox
│ ├── arp -> ../bin/busybox
│ ├── blkid -> ../bin/busybox
│ ├── blockdev -> ../bin/busybox
│ ├── bootchartd -> ../bin/busybox
│ ├── depmod -> ../bin/busybox
│ ├── devmem -> ../bin/busybox
│ ├── fbsplash -> ../bin/busybox
│ ├── fdisk -> ../bin/busybox
│ ├── findfs -> ../bin/busybox
│ ├── freeramdisk -> ../bin/busybox
│ ├── fsck -> ../bin/busybox
│ ├── fsck.minix -> ../bin/busybox
│ ├── fstrim -> ../bin/busybox
│ ├── getty -> ../bin/busybox
│ ├── halt -> ../bin/busybox
│ ├── hdparm -> ../bin/busybox
│ ├── hwclock -> ../bin/busybox
│ ├── ifconfig -> ../bin/busybox
│ ├── ifdown -> ../bin/busybox
│ ├── ifenslave -> ../bin/busybox
│ ├── ifup -> ../bin/busybox
│ ├── init -> ../bin/busybox
│ ├── insmod -> ../bin/busybox
│ ├── ip -> ../bin/busybox
│ ├── ipaddr -> ../bin/busybox
│ ├── iplink -> ../bin/busybox
│ ├── ipneigh -> ../bin/busybox
│ ├── iproute -> ../bin/busybox
│ ├── iprule -> ../bin/busybox
│ ├── iptunnel -> ../bin/busybox
│ ├── klogd -> ../bin/busybox
│ ├── loadkmap -> ../bin/busybox
│ ├── logread -> ../bin/busybox
│ ├── losetup -> ../bin/busybox
│ ├── lsmod -> ../bin/busybox
│ ├── makedevs -> ../bin/busybox
│ ├── mdev -> ../bin/busybox
│ ├── mkdosfs -> ../bin/busybox
│ ├── mke2fs -> ../bin/busybox
│ ├── mkfs.ext2 -> ../bin/busybox
│ ├── mkfs.minix -> ../bin/busybox
│ ├── mkfs.vfat -> ../bin/busybox
│ ├── mkswap -> ../bin/busybox
│ ├── modinfo -> ../bin/busybox
│ ├── modprobe -> ../bin/busybox
│ ├── nameif -> ../bin/busybox
│ ├── pivot_root -> ../bin/busybox
│ ├── poweroff -> ../bin/busybox
│ ├── raidautorun -> ../bin/busybox
│ ├── reboot -> ../bin/busybox
│ ├── rmmod -> ../bin/busybox
│ ├── route -> ../bin/busybox
│ ├── runlevel -> ../bin/busybox
│ ├── setconsole -> ../bin/busybox
│ ├── slattach -> ../bin/busybox
│ ├── start-stop-daemon -> ../bin/busybox
│ ├── sulogin -> ../bin/busybox
│ ├── swapoff -> ../bin/busybox
│ ├── swapon -> ../bin/busybox
│ ├── switch_root -> ../bin/busybox
│ ├── sysctl -> ../bin/busybox
│ ├── syslogd -> ../bin/busybox
│ ├── tunctl -> ../bin/busybox
│ ├── udhcpc -> ../bin/busybox
│ ├── uevent -> ../bin/busybox
│ ├── vconfig -> ../bin/busybox
│ ├── watchdog -> ../bin/busybox
│ └── zcip -> ../bin/busybox
├── usr
│ ├── bin
│ │ ├── [ -> ../../bin/busybox
│ │ ├── [[ -> ../../bin/busybox
│ │ ├── awk -> ../../bin/busybox
│ │ ├── basename -> ../../bin/busybox
│ │ ├── beep -> ../../bin/busybox
│ │ ├── blkdiscard -> ../../bin/busybox
│ │ ├── bunzip2 -> ../../bin/busybox
│ │ ├── bzcat -> ../../bin/busybox
│ │ ├── bzip2 -> ../../bin/busybox
│ │ ├── cal -> ../../bin/busybox
│ │ ├── chpst -> ../../bin/busybox
│ │ ├── chrt -> ../../bin/busybox
│ │ ├── chvt -> ../../bin/busybox
│ │ ├── cksum -> ../../bin/busybox
│ │ ├── clear -> ../../bin/busybox
│ │ ├── cmp -> ../../bin/busybox
│ │ ├── comm -> ../../bin/busybox
│ │ ├── crontab -> ../../bin/busybox
│ │ ├── cryptpw -> ../../bin/busybox
│ │ ├── cut -> ../../bin/busybox
│ │ ├── dc -> ../../bin/busybox
│ │ ├── deallocvt -> ../../bin/busybox
│ │ ├── diff -> ../../bin/busybox
│ │ ├── dirname -> ../../bin/busybox
│ │ ├── dos2unix -> ../../bin/busybox
│ │ ├── dpkg -> ../../bin/busybox
│ │ ├── dpkg-deb -> ../../bin/busybox
│ │ ├── du -> ../../bin/busybox
│ │ ├── dumpleases -> ../../bin/busybox
│ │ ├── eject -> ../../bin/busybox
│ │ ├── env -> ../../bin/busybox
│ │ ├── envdir -> ../../bin/busybox
│ │ ├── envuidgid -> ../../bin/busybox
│ │ ├── expand -> ../../bin/busybox
│ │ ├── expr -> ../../bin/busybox
│ │ ├── fgconsole -> ../../bin/busybox
│ │ ├── find -> ../../bin/busybox
│ │ ├── flock -> ../../bin/busybox
│ │ ├── fold -> ../../bin/busybox
│ │ ├── free -> ../../bin/busybox
│ │ ├── ftpget -> ../../bin/busybox
│ │ ├── ftpput -> ../../bin/busybox
│ │ ├── fuser -> ../../bin/busybox
│ │ ├── groups -> ../../bin/busybox
│ │ ├── hd -> ../../bin/busybox
│ │ ├── head -> ../../bin/busybox
│ │ ├── hexdump -> ../../bin/busybox
│ │ ├── hostid -> ../../bin/busybox
│ │ ├── id -> ../../bin/busybox
│ │ ├── install -> ../../bin/busybox
│ │ ├── ipcrm -> ../../bin/busybox
│ │ ├── ipcs -> ../../bin/busybox
│ │ ├── killall -> ../../bin/busybox
│ │ ├── last -> ../../bin/busybox
│ │ ├── less -> ../../bin/busybox
│ │ ├── logger -> ../../bin/busybox
│ │ ├── logname -> ../../bin/busybox
│ │ ├── lpq -> ../../bin/busybox
│ │ ├── lpr -> ../../bin/busybox
│ │ ├── lsof -> ../../bin/busybox
│ │ ├── lspci -> ../../bin/busybox
│ │ ├── lsusb -> ../../bin/busybox
│ │ ├── lzcat -> ../../bin/busybox
│ │ ├── lzma -> ../../bin/busybox
│ │ ├── lzopcat -> ../../bin/busybox
│ │ ├── man -> ../../bin/busybox
│ │ ├── md5sum -> ../../bin/busybox
│ │ ├── mesg -> ../../bin/busybox
│ │ ├── microcom -> ../../bin/busybox
│ │ ├── mkfifo -> ../../bin/busybox
│ │ ├── mkpasswd -> ../../bin/busybox
│ │ ├── nc -> ../../bin/busybox
│ │ ├── nmeter -> ../../bin/busybox
│ │ ├── nohup -> ../../bin/busybox
│ │ ├── nsenter -> ../../bin/busybox
│ │ ├── nslookup -> ../../bin/busybox
│ │ ├── od -> ../../bin/busybox
│ │ ├── openvt -> ../../bin/busybox
│ │ ├── passwd -> ../../bin/busybox
│ │ ├── patch -> ../../bin/busybox
│ │ ├── pgrep -> ../../bin/busybox
│ │ ├── pkill -> ../../bin/busybox
│ │ ├── pmap -> ../../bin/busybox
│ │ ├── printf -> ../../bin/busybox
│ │ ├── pscan -> ../../bin/busybox
│ │ ├── pstree -> ../../bin/busybox
│ │ ├── pwdx -> ../../bin/busybox
│ │ ├── readlink -> ../../bin/busybox
│ │ ├── realpath -> ../../bin/busybox
│ │ ├── renice -> ../../bin/busybox
│ │ ├── reset -> ../../bin/busybox
│ │ ├── resize -> ../../bin/busybox
│ │ ├── rpm2cpio -> ../../bin/busybox
│ │ ├── runsv -> ../../bin/busybox
│ │ ├── runsvdir -> ../../bin/busybox
│ │ ├── rx -> ../../bin/busybox
│ │ ├── script -> ../../bin/busybox
│ │ ├── seq -> ../../bin/busybox
│ │ ├── setkeycodes -> ../../bin/busybox
│ │ ├── setsid -> ../../bin/busybox
│ │ ├── setuidgid -> ../../bin/busybox
│ │ ├── sha1sum -> ../../bin/busybox
│ │ ├── sha256sum -> ../../bin/busybox
│ │ ├── sha3sum -> ../../bin/busybox
│ │ ├── sha512sum -> ../../bin/busybox
│ │ ├── showkey -> ../../bin/busybox
│ │ ├── shuf -> ../../bin/busybox
│ │ ├── smemcap -> ../../bin/busybox
│ │ ├── softlimit -> ../../bin/busybox
│ │ ├── sort -> ../../bin/busybox
│ │ ├── split -> ../../bin/busybox
│ │ ├── strings -> ../../bin/busybox
│ │ ├── sum -> ../../bin/busybox
│ │ ├── sv -> ../../bin/busybox
│ │ ├── svc -> ../../bin/busybox
│ │ ├── tac -> ../../bin/busybox
│ │ ├── tail -> ../../bin/busybox
│ │ ├── tcpsvd -> ../../bin/busybox
│ │ ├── tee -> ../../bin/busybox
│ │ ├── telnet -> ../../bin/busybox
│ │ ├── test -> ../../bin/busybox
│ │ ├── tftp -> ../../bin/busybox
│ │ ├── time -> ../../bin/busybox
│ │ ├── timeout -> ../../bin/busybox
│ │ ├── top -> ../../bin/busybox
│ │ ├── tr -> ../../bin/busybox
│ │ ├── traceroute -> ../../bin/busybox
│ │ ├── traceroute6 -> ../../bin/busybox
│ │ ├── truncate -> ../../bin/busybox
│ │ ├── tty -> ../../bin/busybox
│ │ ├── ttysize -> ../../bin/busybox
│ │ ├── udpsvd -> ../../bin/busybox
│ │ ├── unexpand -> ../../bin/busybox
│ │ ├── uniq -> ../../bin/busybox
│ │ ├── unix2dos -> ../../bin/busybox
│ │ ├── unlink -> ../../bin/busybox
│ │ ├── unlzma -> ../../bin/busybox
│ │ ├── unlzop -> ../../bin/busybox
│ │ ├── unshare -> ../../bin/busybox
│ │ ├── unxz -> ../../bin/busybox
│ │ ├── unzip -> ../../bin/busybox
│ │ ├── uptime -> ../../bin/busybox
│ │ ├── users -> ../../bin/busybox
│ │ ├── uudecode -> ../../bin/busybox
│ │ ├── uuencode -> ../../bin/busybox
│ │ ├── vlock -> ../../bin/busybox
│ │ ├── volname -> ../../bin/busybox
│ │ ├── wall -> ../../bin/busybox
│ │ ├── wc -> ../../bin/busybox
│ │ ├── wget -> ../../bin/busybox
│ │ ├── which -> ../../bin/busybox
│ │ ├── who -> ../../bin/busybox
│ │ ├── whoami -> ../../bin/busybox
│ │ ├── whois -> ../../bin/busybox
│ │ ├── xargs -> ../../bin/busybox
│ │ ├── xz -> ../../bin/busybox
│ │ ├── xzcat -> ../../bin/busybox
│ │ └── yes -> ../../bin/busybox
│ ├── lib
│ └── sbin
│ ├── addgroup -> ../../bin/busybox
│ ├── add-shell -> ../../bin/busybox
│ ├── adduser -> ../../bin/busybox
│ ├── arping -> ../../bin/busybox
│ ├── brctl -> ../../bin/busybox
│ ├── chat -> ../../bin/busybox
│ ├── chpasswd -> ../../bin/busybox
│ ├── chroot -> ../../bin/busybox
│ ├── crond -> ../../bin/busybox
│ ├── delgroup -> ../../bin/busybox
│ ├── deluser -> ../../bin/busybox
│ ├── dhcprelay -> ../../bin/busybox
│ ├── dnsd -> ../../bin/busybox
│ ├── ether-wake -> ../../bin/busybox
│ ├── fakeidentd -> ../../bin/busybox
│ ├── fbset -> ../../bin/busybox
│ ├── fdformat -> ../../bin/busybox
│ ├── ftpd -> ../../bin/busybox
│ ├── httpd -> ../../bin/busybox
│ ├── i2cdetect -> ../../bin/busybox
│ ├── i2cdump -> ../../bin/busybox
│ ├── i2cget -> ../../bin/busybox
│ ├── i2cset -> ../../bin/busybox
│ ├── ifplugd -> ../../bin/busybox
│ ├── inetd -> ../../bin/busybox
│ ├── killall5 -> ../../bin/busybox
│ ├── loadfont -> ../../bin/busybox
│ ├── lpd -> ../../bin/busybox
│ ├── nanddump -> ../../bin/busybox
│ ├── nandwrite -> ../../bin/busybox
│ ├── nbd-client -> ../../bin/busybox
│ ├── ntpd -> ../../bin/busybox
│ ├── popmaildir -> ../../bin/busybox
│ ├── powertop -> ../../bin/busybox
│ ├── rdate -> ../../bin/busybox
│ ├── rdev -> ../../bin/busybox
│ ├── readahead -> ../../bin/busybox
│ ├── readprofile -> ../../bin/busybox
│ ├── remove-shell -> ../../bin/busybox
│ ├── rtcwake -> ../../bin/busybox
│ ├── sendmail -> ../../bin/busybox
│ ├── setfont -> ../../bin/busybox
│ ├── setlogcons -> ../../bin/busybox
│ ├── svlogd -> ../../bin/busybox
│ ├── telnetd -> ../../bin/busybox
│ ├── tftpd -> ../../bin/busybox
│ ├── ubiattach -> ../../bin/busybox
│ ├── ubidetach -> ../../bin/busybox
│ ├── ubimkvol -> ../../bin/busybox
│ ├── ubirename -> ../../bin/busybox
│ ├── ubirmvol -> ../../bin/busybox
│ ├── ubirsvol -> ../../bin/busybox
│ ├── ubiupdatevol -> ../../bin/busybox
│ └── udhcpd -> ../../bin/busybox
└── var
├── lib
├── lock
├── log
├── run
└── tmp

14 directories, 422 files
samlee@PCRD1448:/mnt/SSD500G/operasys/Forx86-64/custom-x86/rootfs$


try busybox part from p.161~p.165
Extract BusyBox using the "tar" command
Configure BusyBox per the slides




Build BusyBox per the slides
Install BusyBox per the slides





try to create rootfs and copy glibc into rootfs folder (follow p.149~p.155)
Create yourself a root filesystem that includes the glibc shared libraries as in
slides 149




and 155,


except for the "strip" command.


running this copy_glibc_2rootfs scripts in opersys custom-x86 folder:

modify kernel and run it in emulator or hikey
cd kernel/goldfish
make ARCH=x86 xconfig
make ARCH=x86 CROSS_COMPILE=x86_64-linux-android- bzImage -j24
croot
ls -al kernel/goldfish/arch/x86/boot/bzImage
cp kernel/goldfish/arch/x86/boot/bzImage prebuilts/qemu-kernel/x86_64/4.9/kernel-qemu2
make -j24 TARGET_SKIP_OTA_PACKAGE=true
emulator &
adb shell cat /proc/version
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ adb shell cat /proc/version (emulator kernel version)
Linux version 4.4.124+ (samlee@PCRD1448) (gcc version 4.9.x 20150123 (prerelease) (GCC) ) #2 SMP PREEMPT Wed Aug 21 10:51:33 CST 2019





aosp8 for hikey
aosp9 for emulator

samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ mkdir out
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39$ sudo mount --bind /mnt/SSD500G/MyOut/bsp/android-9.0.0_r39 $PWD/out

samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18$ mkdir out
samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18$ sudo mount --bind /mnt/SSD500G/MyOut/bsp/aosp $PWD/out
samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18$ LC_ALL=C make -j24 TARGET_SKIP_OTA_PACKAGE=true
ps. LC_ALL=C is to avoid build error caused by old prebuilt flex binary tool in 8.1.0 ...

at the top-level of the AOSP tree:
b. Get the kernel itself – for Hikey:
aosp-8.1.0_r18$ mkdir kernel
aosp-8.1.0_r18$ cd kernel
$ git clone https://android.googlesource.com/kernel/hikey-linaro
$ cd hikey-linaro
$ git checkout -b android-hikey-linaro-4.9 origin/android-hikey-linaro-4.9
$ git checkout 7c9f462e1a438c37a616063c381a59840793b1a0
b. Get the kernel itself – for emulator:
android-9.0.0_r39$ mkdir kernel
android-9.0.0_r39$ cd kernel
$ git clone https://android.googlesource.com/kernel/goldfish
$ cd goldfish
$ git checkout android-goldfish-4.4-dev

Reconfigure the kernel to support:
CONFIG_TI_ST and
CONFIG_ST_HCI.
Here's a reminder on how to get the kernel configuration that uses the default "hikey" configuration as its starting point:
samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18$ cd kernel/hikey-linaro
samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18/kernel/hikey-linaro$ make ARCH=arm64 hikey_defconfig
#
# configuration written to .config
#
#### build completed successfully ####

samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18/kernel/hikey-linaro$ make ARCH=arm64 xconfig
scripts/kconfig/qconf Kconfig
qt5ct: using qt5ct plugin
qt5ct: D-Bus global menu: no

#### build completed successfully (11 seconds) ####

find TI_ST and ST_HCI using below xconfig GUI and set them to Y


compare files .config vs. .config.old in folder aosp-8.1.0_r18/kernel/hikey-linaro




samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18/kernel/hikey-linaro$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -j8
LD vmlinux
SORTEX vmlinux
SYSMAP System.map
DTC arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
OBJCOPY arch/arm64/boot/Image
Building modules, stage 2.
CAT arch/arm64/boot/Image-dtb
MODPOST 0 modules
#### build completed successfully (09:51 (mm:ss)) ####


samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18/kernel/hikey-linaro$ cp arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb /mnt/sw/android/bsp/aosp-8.1.0_r18/device/linaro/hikey-kernel/hi6220-hikey.dtb-4.9
samlee@PCRD1448:/mnt/sw/android/bsp/aosp-8.1.0_r18/kernel/hikey-linaro$ cp arch/arm64/boot/Image-dtb /mnt/sw/android/bsp/aosp-8.1.0_r18/device/linaro/hikey-kernel/Image-dtb-4.9
ps. in symlink folder (I used it for kernel folder), the syntax ../../ DONOT work as expected!!

for emulator,
Build the AOSP:
cd ~/android/android-9.0.0_r39
. build/envsetup.sh
lunch aosp_x86_64-eng
make -j8
5. Give the AOSP a spin:
From the same directory where you build the AOSP, run the emulator:
$ emulator &
At this point, an emulator should start with your custom-built Android running inside.

Reconfigure the kernel to make sure support for modules and module unloading is enabled.
You don't need to enable forced module unloading.
Here's a reminder on how to get the kernel configuration that uses the default configuration from a running emulator as its starting point:
how to get the kernel configuration from a running emulator
$ cd kernel/goldfish
$ adb pull /proc/config.gz
$ gunzip config.gz
$ mv config .config
$ make ARCH=x86 oldconfig
$ make ARCH=x86 menuconfig
samlee@PCRD1448:/mnt/sw/android/bsp/android-9.0.0_r39/kernel/goldfish$ make ARCH=x86 CROSS_COMPILE=x86_64-linux-android- bzImage -j24

LD arch/x86/boot/compressed/vmlinux
ZOFFSET arch/x86/boot/zoffset.h
OBJCOPY arch/x86/boot/vmlinux.bin
AS arch/x86/boot/header.o
LD arch/x86/boot/setup.elf
OBJCOPY arch/x86/boot/setup.bin
BUILD arch/x86/boot/bzImage
Setup is 15404 bytes (padded to 15872 bytes).
System is 5890 kB
CRC 7d628385
Kernel: arch/x86/boot/bzImage is ready (#1)
#### build completed successfully (01:55 (mm:ss)) ####