티스토리 뷰
목차
1. 에러 메시지
2. 실행 파일 분석
3. 디버깅 방향 설정
4. shared object 파일 다운로드 및 저장
5. 빌드 및 포팅
6. shared object 파일 경로 재설정
7. shared object 파일 빌트인
8. 테스트
결론
런타임 링커가 shared object를 찾지 못해서 로드하지 못함
리눅스 file 명령어로 실행 파일의 shared object 로딩 경로 파악 후
타겟보드에 shared object 로딩 경로에 맞게 shared object 복사
1. 에러 메시지
실행 파일 실행 시 에러 메시지 발생
어떤 파일 또는 디렉토리가 필요한걸까?

2. 실행 파일 분석
file 명령어: 파일 유형 확인하는 명령어
ldd 명령어: 파일의 shared library 의존성 확인하는 리눅스 명령어
readelf 명령어: ELF 파일 읽어내는 명령어
라이브러리 종류 3가지
- static library: 실행파일에 binary 형태로 박혀있는 라이브러리
- shared library:(SO, shared object): 실행 파일과 분리되어 있다. 실행 파일 실행 시 실행 파일과 함께 메모리에 로드 되는 라이브러리. 다른 프로그램들이 공유해서 사용할 수 있는 라이브러리
- dynamic library(DLL, dynamic link library): 실행 파일과 분리되어 있다. 실행 파일 실행 시 실행 파일만 메모리에 로드되고, 라이브러리는 실행 도중 따로 메모리에 로드되는 라이브러리
root@ubuntu:# file Btdiag
Btdiag: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=5773c7f71d08ee1da53e8b765fcc0fdf65862c26, stripped
root@ubuntu:# ldd Btdiag
not a dynamic executable
root@ubuntu:# file Qcmbr
Qcmbr: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=c192a4ff5e8820c05fbd81b63a2f98ead43d058a, with debug_info, not stripped
root@ubuntu:# ldd Qcmbr
not a dynamic executable
root@ubuntu:# readelf -a Btdiag
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x2400
Start of program headers: 64 (bytes into file)
Start of section headers: 45936 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 26
Section header string table index: 25
root@ubuntu:# readelf -a Qcmbr
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: AArch64
Version: 0x1
Entry point address: 0x401578
Start of program headers: 64 (bytes into file)
Start of section headers: 95592 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 36
Section header string table index: 35
※ 실행 파일 Btdiag가 ELF 헤더에서 ET_DYN (Shared object)로 출력되는 이유

https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
실행 파일 런타임 중 dynamic linking할 shared object 확인
사실 shared object의 symbolic link이다.
root@ubuntu:# readelf -d Qcmbr | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libglib-2.0.so.0]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
root@ubuntu:# readelf -d Btdiag | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libbluetooth.so.3]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-aarch64.so.1]
3. 디버깅 방향 설정
sensors.imx8.so 파일이 빌드되어 생성되도록 작성한 Android.mk에서
LOCAL_SHARED_LIBRARIES에 공유 라이브러리 목록이 작성돼 있었다.
현재 "/system/bin/sh: No such file or directory" 에러에서 찾는 파일들이
LOCAL_SHARED_LIBRARIES 목록에 있는 파일들은 아닐까?

이 파일 경로를 찾고, 아래 shared object를 그러한 방식으로 저장해면 에러 해결되지 않을까?
[libglib-2.0.so.0] X
[librt.so.1] -> librt-2.27.so
[libc.so.6] O
[libpthread.so.0] -> libpthread-2.27.so
[libbluetooth.so.3] X
[libc.so.6] -> libc-2.27.so
[ld-linux-aarch64.so.1] -> ld-2.27.so
| shared object (shared library) | 경로 |
| liblog | /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/system/lib/liblog.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/system/lib64/liblog.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj/lib/liblog.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj/SHARED_LIBRARIES/liblog_intermediates/liblog.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj_arm/lib/liblog.so |
| libcutils | /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/system/lib/libcutils.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/system/lib64/libcutils.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj/lib/libcutils.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj/SHARED_LIBRARIES/liblog_intermediates/libcutils.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj_arm/lib/libcutils.so |
| libdl | /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/system/lib/libdl.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/system/lib64/libdl.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj/lib/libdl.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj/SHARED_LIBRARIES/liblog_intermediates/libdl.so /usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj_arm/lib/libdl.so |
./system/lib/liblog.so는 ARM 아키텍처 기반
root@ubuntu:# readelf -h liblog.so
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 52 (bytes into file)
Start of section headers: 87940 (bytes into file)
Flags: 0x5000200, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 27
Section header string table index: 26
※ .deb 파일
.deb 파일: debian linux OS에서 실행 가능한 코드 번들
Ubuntu는 debian linux 기반의 리눅스 배포판 OS이다.
따라서 Ubuntu에서도 .deb 파일 실행 가능
.deb 파일 형태로 다운로드
4. shared object 파일(aarch64 아키텍처 기반) 다운로드 및 저장
[libglib-2.0.so.0] X
https://howtoinstall.co/en/gcc-arm-linux-gnueabihf
http://213.146.141.13/package/details/Ubuntu1910/ubuntu_focal_main/x86-64/libglib2.0-dev/2.64.2
=> aarch64 버전 .deb 파일 다운로드 후
.deb 파일 설치가 아닌 압축 풀기
# mkdir ./mydir
# dpkg-deb -x libglib2.0-0_2.66.8-1_arm64.deb ./mydir

root@ubuntu:# readelf -h libglib-2.0.so.0.6600.8
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x1cd30
Start of program headers: 64 (bytes into file)
Start of section headers: 1251312 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 7
Size of section headers: 64 (bytes)
Number of section headers: 26
Section header string table index: 25
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf
[librt.so.1] -> librt-2.27.so
[libc.so.6] O
=> 기본 탑재
[libpthread.so.0] -> libpthread-2.27.so
[libbluetooth.so.3] X
https://github.com/d34th4ck3r/Hcidump-in-Android/tree/master/libs/armeabi
=> ARM 아키텍처 기반
혹은 .deb 파일 다운로드 후 풀기
https://ubuntu.pkgs.org/18.04/ubuntu-main-arm64/libbluetooth3_5.48-0ubuntu3_arm64.deb.html
root@ubuntu:# mkdir ./mydir
root@ubuntu:# dpkg-deb -x libbluetooth3_5.48-0ubuntu3_arm64.deb ./mydir
root@ubuntu:/mydir/usr/lib/aarch64-linux-gnu# ls
bluetooth libbluetooth.so.3 libbluetooth.so.3.18.16
root@ubuntu:/mydir/usr/lib/aarch64-linux-gnu# readelf -h libbluetooth.so.3
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x6b00
Start of program headers: 64 (bytes into file)
Start of section headers: 138856 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 6
Size of section headers: 64 (bytes)
Number of section headers: 23
Section header string table index: 22
[libc.so.6] -> libc-2.27.so
[ld-linux-aarch64.so.1] -> ld-2.27.so
5. 빌드 및 포팅
빌드 아티팩트 생성
6. shared object 파일 경로 재설정
dynamic linking할 shared object 파일을
system/lib 디렉토리에 옮겼으나 여전히 No such file or directory 에러 발생
타겟보드가 아닌 vmware guest OS에서 테스트하며 원인 찾아보자
Btdiag 실행 파일 실행 시, 필요한 shared library 이름이 에러 로그로 출력됐다.
필요한 shared library들을 /lib 디렉토리에 복사한 이후 정상 실행됐다.
root@ubuntu:# ./Btdiag
./Btdiag: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory
root@ubuntu:# ./Btdiag
./Btdiag: error while loading shared libraries: libbluetooth.so.3: cannot open shared object file: No such file or directory
root@ubuntu:# ./Btdiag
./Btdiag: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
root@ubuntu:# ./Btdiag
Require at least 5 arguments.
Example of client mode, Btdiag usage:
- BT FTM mode for serial:
./Btdiag UDT=yes PORT=2390 IOType=SERIAL DEVICE=/dev/ttyUSB0 BAUDRATE=115200
- BT FTM mode for USB:
./Btdiag UDT=yes PORT=2390 IOType=USB DEVICE=hci0
따라서, 타겟 보드에서도 shared object 파일 경로를 올바르게 변경해보자
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/system/lib (실패)
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/vendor/lib (실패)
./vendor/lib에서
원본 shared object 파일명을 symbolic link 파일명으로 바꾸고 symbolic link 삭제 (실패)
sensors.imx.so 파일 있는 경로대로 똑같이 진행 (실패)
root@ubuntu:/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro# find ./ -name sensors.imx8.so
./symbols/vendor/lib/hw/sensors.imx8.so
./symbols/vendor/lib64/hw/sensors.imx8.so
./obj/PACKAGING/target_files_intermediates/ccimx8xsbcpro-target_files-eng.root/VENDOR/lib/hw/sensors.imx8.so
./obj/PACKAGING/target_files_intermediates/ccimx8xsbcpro-target_files-eng.root/VENDOR/lib64/hw/sensors.imx8.so
./obj/SHARED_LIBRARIES/sensors.imx8_intermediates/PACKED/sensors.imx8.so
./obj/SHARED_LIBRARIES/sensors.imx8_intermediates/sensors.imx8.so
./obj/SHARED_LIBRARIES/sensors.imx8_intermediates/LINKED/sensors.imx8.so
./vendor/lib/hw/sensors.imx8.so
./vendor/lib64/hw/sensors.imx8.so
./obj_arm/SHARED_LIBRARIES/sensors.imx8_intermediates/PACKED/sensors.imx8.so
./obj_arm/SHARED_LIBRARIES/sensors.imx8_intermediates/sensors.imx8.so
./obj_arm/SHARED_LIBRARIES/sensors.imx8_intermediates/LINKED/sensors.imx8.so
gust OS에서 target으로 shared object 복사
https://blog.csdn.net/JaniceZhou37/article/details/112018341
※ 단서
실행 파일을 리눅스 file 명령어로 분석하면 /lib/ld-linux-aarrch64.so.1 경로 확인할 수 있다.
root@ubuntu:# file Btdiag
Btdiag: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=5773c7f71d08ee1da53e8b765fcc0fdf65862c26, stripped
아래 방법은 target 보드 reset하면 adb push한 파일들이 사라짐
root@ubuntu:/# mkdir lib
root@ubuntu:/# cp -r libpthread.so.0 libpthread-2.27.so libbluetooth.so.3 libbluetooth.so.3.18.16 libc.so.6 libc-2.27.so ld-linux-aarch64.so.1 ld-2.27.so ./lib
root@ubuntu:/# tar jcvf lib.tar.bz2 ./lib
./lib/
./lib/libpthread.so.0
./lib/ld-linux-aarch64.so.1
./lib/libbluetooth.so.3
./lib/libc.so.6
./lib/libbluetooth.so.3.18.16
./lib/libpthread-2.27.so
./lib/ld-2.27.so
./lib/libc-2.27.so
C:\>adb shell
ccimx8xsbcpro:/ # mount -o rw, remount /
ccimx8xsbcpro:/ # exit
C:\>adb push lib.tar.bz2 /
C;\>adb push Btdiag /data
C:\>adb shell
ccimx8xsbcpro:/ # tar jxvf lib.tar.bz2
ccimx8xsbcpro:/ # cd /data
ccimx8xsbcpro:/data # chmod 545 Btdiag
ccimx8xsbcpro:/data # ./Btdiag
7. shared object 파일 빌트인
Makefile 변수 확인
/usr/local/dea-9.0-r3/build/core/product_config.mk
TARGET_DEVICE := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEVICE)
/usr/local/dea-9.0-r3/build/core/envsetup.mk
ifeq (,$(strip $(OUT_DIR)))
ifeq (,$(strip $(OUT_DIR_COMMON_BASE)))
OUT_DIR := $(TOPDIR)out
else
OUT_DIR := $(OUT_DIR_COMMON_BASE)/$(notdir $(PWD))
endif
endif
TARGET_OUT_ROOT := $(OUT_DIR)/target
TARGET_PRODUCT_OUT_ROOT := $(TARGET_OUT_ROOT)/product
PRODUCT_OUT := $(TARGET_PRODUCT_OUT_ROOT)/$(TARGET_DEVICE)
ex) Makefile cp 명령어 사례

https://www.idchg.com/info/292339/
ex) Makefile에 mkdir 명령어 사용
root@ubuntu:# mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE set file mode (as in chmod), not a=rwx - umask
-p, --parents no error if existing, make parent directories as needed
-v, --verbose print a message for each created directory
-Z set SELinux security context of each created directory
to the default type
--context[=CTX] like -Z, or if CTX is specified then set the SELinux
or SMACK security context to CTX
--help display this help and exit
--version output version information and exit
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/mkdir>
or available locally via: info '(coreutils) mkdir invocation'
/usr/local/dea-9.0-r3/system/core/rootdir/Android.mk
# Put it here instead of in init.rc module definition,
# because init.rc is conditionally included.
#
# create some directories (some are mount points) and symlinks
LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \
sbin dev proc sys system data odm oem acct config storage mnt $(BOARD_ROOT_EXTRA_FOLDERS)); \
ln -sf /system/bin $(TARGET_ROOT_OUT)/bin; \
ln -sf /system/etc $(TARGET_ROOT_OUT)/etc; \
ln -sf /data/user_de/0/com.android.shell/files/bugreports $(TARGET_ROOT_OUT)/bugreports; \
ln -sf /sys/kernel/debug $(TARGET_ROOT_OUT)/d; \
ln -sf /storage/self/primary $(TARGET_ROOT_OUT)/sdcard
ifdef BOARD_USES_VENDORIMAGE
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/vendor
else
LOCAL_POST_INSTALL_CMD += ; ln -sf /system/vendor $(TARGET_ROOT_OUT)/vendor
endif
ifdef BOARD_USES_PRODUCTIMAGE
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/product
else
LOCAL_POST_INSTALL_CMD += ; ln -sf /system/product $(TARGET_ROOT_OUT)/product
endif
ifdef BOARD_USES_METADATA_PARTITION
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/metadata
endif
sbin dev proc sys system data odem 등이 아래 경로의 파일 시스템 구성과 비슷하다.
위 Android.mk로 파일 시스템 구성하는 것으로 판단했다.

BOARD_USES_VENDORIMAGE 등 변수 정의
/usr/local/dea-9.0-r3/build/core/envsetup.mk
BOARD_USES_VENDORIMAGE :=
ifdef BOARD_PREBUILT_VENDORIMAGE
BOARD_USES_VENDORIMAGE := true
endif
ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
BOARD_USES_VENDORIMAGE := true
endif
ifeq ($(TARGET_COPY_OUT_VENDOR),vendor)
BOARD_USES_VENDORIMAGE := true
else ifdef BOARD_USES_VENDORIMAGE
$(error TARGET_COPY_OUT_VENDOR must be set to 'vendor' to use a vendor image)
endif
/system/bin/sh: ./Btdiag: Permission denied
원인: /lib 디렉토리 하위 파일 접근 권한 문제
타겟보드 파일 시스템에서 /lib 디렉토리 권한 상승
--- init.rc 2022-12-19 00:01:34.058363885 -0800
+++ init.rc_rev1 2023-05-25 16:07:26.764048646 -0700
@@ -196,6 +196,10 @@
+# @author:
+# @date:
+# @brief: set authorize
+ chmod 0655 -R ./lib
service sysinfo /vendor/bin/sysinfo
user root
ccimx8xsbcpro:# df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 507900 8196 499704 2% /
tmpfs 921896 460 921436 1% /dev
tmpfs 921896 0 921896 0% /mnt
/dev/block/mmcblk0p3 2064208 1171664 892544 57% /system
/dev/block/mmcblk0p5 111088 72312 38776 66% /vendor
/dev/block/mmcblk0p4 1998672 3580 1995092 1% /cache
/dev/block/mmcblk0p10 10728348 71488 10656860 1% /data
/data/media 10728348 71488 10656860 1% /mnt/runtime/default/emulated
/dev/block/vold/public:179,97 31284704 2159872 29124832 7% /mnt/media_rw/sdcard1
/mnt/media_rw/sdcard1 31284704 2159872 29124832 7% /mnt/runtime/default/sdcard1
ccimx8xsbcpro:# mount -o remount,rw /vendor
ccimx8xsbcpro:# cd /vendor/firwmare
ccimx8xsbcpro:# chmod 775 rampatch_tlv_3.2.tlv

https://android.googlesource.com/platform/system/core/+/master/init/README.md
ex)
mount </sys/fs > </dev > <디렉토리 경로>
root@ubuntu:/usr/local/dea-9.0-r3/system/core/rootdir# cat init.rc | grep mount
mount cpuset none /dev/cpuset nodev noexec nosuid
mount cgroup2 cg2_bpf /dev/cg2_bpf nodev noexec nosuid
ccimx8xsbcpro:# cd /dev
ccimx8xsbcpro:# ls
cg2_bpf ...
ccimx8xsbcpro:/sys/fs # ls
bpf cgroup ext4 f2fs fuse pstore selinux
8. 테스트
8-1. 디렉토리 생성
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/root/ 경로에 디렉토리 생성
패치 파일 (원본: /usr/local/dea-9.0-r3/system/core/rootdir/Android.mk)
--- Android.mk 2022-10-10 19:10:15.874668217 -0700
+++ Android.mk_rev1 2023-05-15 19:15:55.298446270 -0700
@@ -97,6 +97,14 @@
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/metadata
endif
+# @author:
+# @date:
+# @brief: copy shared objects to $(TARGET_ROOT_OUT)
+ifdef BOARD_USES_BTDIAG_QCMBR
+ LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/pyh
+endif
+
+
# For /odm partition.
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/odm
# For Treble Generic System Image (GSI), system-as-root GSI needs to work on
패치 파일 (원본: /usr/local/dea-9.0-r3/build/core/envsetup.mk)
--- envsetup.mk 2021-04-06 23:45:19.792493096 -0700
+++ envsetup.mk_rev1 2023-05-15 19:39:55.870989687 -0700
@@ -286,6 +286,11 @@
$(error TARGET_COPY_OUT_VENDOR must be set to 'vendor' to use a vendor image)
endif
+# @author:
+# @date:
+# @bref: set a variable for Android.mk
+BOARD_USES_BTDIAG_QCMBR := true
+
###########################################
# Now we can substitute with the real value of TARGET_COPY_OUT_PRODUCT
ifeq ($(TARGET_COPY_OUT_PRODUCT),$(_product_path_placeholder))
테스트 결과
디렉토리 생성 완료

8-2. 디렉토리 복사
/usr/local/dea-9.0-r3/build/core/lib 디렉토리를
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/root/ 경로에 복사
Makefile 변수 확인
/usr/local/dea-9.0-r3/build/core/main.mk
BUILD_SYSTEM := $(TOPDIR)build/make/core
lib.tar.bz2 이동 및 압축 풀기
root@ubuntu:/# cd /usr/local/dea-9.0-r3/build/make/core
root@ubuntu:/usr/local/dea-9.0-r3/build/make/core# tar jxvf lib.tar.bz2
※ shared object 파일이 담긴 lib 디렉토리를 그대로 복사하면 안된다. 반드시 압축 파일 생성 및 이동해야 $(TARGET_ROOT_OUT) 경로에 lib 디렉토리 생성된다.
패치 파일 (원본: /usr/local/dea-9.0-r3/system/core/rootdir/Android.mk)
--- Android.mk 2023-05-15 22:42:56.059241262 -0700
+++ Android.mk_rev1 2023-05-15 22:45:51.070046559 -0700
@@ -97,6 +97,15 @@
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/metadata
endif
+# @author:
+# @date:
+# @brief: copy shared objects to $(TARGET_ROOT_OUT)
+ifdef BOARD_USES_BTDIAG_QCMBR
+ #LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/pyh
+ LOCAL_POST_INSTALL_CMD += ; cp -prf $(BUILD_SYSTEM)/lib $(TARGET_ROOT_OUT)
+endif
+
+
# For /odm partition.
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/odm
# For Treble Generic System Image (GSI), system-as-root GSI needs to work on
테스트 결과
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/root
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/recovery/root 경로에 디렉토리 복사 완료
타겟 보드 파일 시스템에도 디렉토리 확인
ccimx8xsbcpro:/lib # ls
ld-2.27.so libbluetooth.so.3.18.16 libglib-2.0.so.0 libpcre.so.3.13.3 librt-2.27.so
ld-linux-aarch64.so.1 libc-2.27.so libglib-2.0.so.0.6600.8 libpthread-2.27.so librt.so.1
libbluetooth.so.3 libc.so.6 libpcre.so.3 libpthread.so.0
실행파일 실행 시
/system/bin/sh: Permission denied 에러 발생했다.
원인: shared object 파일 실행 권한 문제
ccimx8xsbcpro:/lib # ls -al
total 3352
drwxrwxrwx 2 root root 320 1970-01-01 00:00 .
drwxrwxrwx 21 root root 1000 2023-05-18 08:54 ..
-rw-r--r-- 1 root root 124784 1970-01-01 00:00 ld-2.27.so
lrwxrwxrwx 1 root root 10 1970-01-01 00:00 ld-linux-aarch64.so.1 -> ld-2.27.so
lrwxrwxrwx 1 root root 23 1970-01-01 00:00 libbluetooth.so.3 -> libbluetooth.so.3.18.16
-rw-r--r-- 1 root root 140328 1970-01-01 00:00 libbluetooth.so.3.18.16
-rw-r--r-- 1 root root 1341248 1970-01-01 00:00 libc-2.27.so
lrwxrwxrwx 1 root root 12 1970-01-01 00:00 libc.so.6 -> libc-2.27.so
lrwxrwxrwx 1 root root 23 1970-01-01 00:00 libglib-2.0.so.0 -> libglib-2.0.so.0.6600.8
-rw-r--r-- 1 root root 1252976 1970-01-01 00:00 libglib-2.0.so.0.6600.8
lrwxrwxrwx 1 root root 17 1970-01-01 00:00 libpcre.so.3 -> libpcre.so.3.13.3
-rw-r--r-- 1 root root 399240 1970-01-01 00:00 libpcre.so.3.13.3
-rw-r--r-- 1 root root 134688 1970-01-01 00:00 libpthread-2.27.so
lrwxrwxrwx 1 root root 18 1970-01-01 00:00 libpthread.so.0 -> libpthread-2.27.so
-rw-r--r-- 1 root root 27448 1970-01-01 00:00 librt-2.27.so
lrwxrwxrwx 1 root root 13 1970-01-01 00:00 librt.so.1 -> librt-2.27.so
해결법: 해당 파일들 실행 권한 부여
ccimx8xsbcpro:/lib # ls -al
total 3352
drwxrwxrwx 2 root root 320 1970-01-01 00:00 .
drwxrwxrwx 21 root root 1000 2023-05-18 08:54 ..
-rwxrwxrwx 1 root root 124784 1970-01-01 00:00 ld-2.27.so
lrwxrwxrwx 1 root root 10 1970-01-01 00:00 ld-linux-aarch64.so.1 -> ld-2.27.so
lrwxrwxrwx 1 root root 23 1970-01-01 00:00 libbluetooth.so.3 -> libbluetooth.so.3.18.16
-rwxrwxrwx 1 root root 140328 1970-01-01 00:00 libbluetooth.so.3.18.16
-rwxrwxrwx 1 root root 1341248 1970-01-01 00:00 libc-2.27.so
lrwxrwxrwx 1 root root 12 1970-01-01 00:00 libc.so.6 -> libc-2.27.so
lrwxrwxrwx 1 root root 23 1970-01-01 00:00 libglib-2.0.so.0 -> libglib-2.0.so.0.6600.8
-rwxrwxrwx 1 root root 1252976 1970-01-01 00:00 libglib-2.0.so.0.6600.8
lrwxrwxrwx 1 root root 17 1970-01-01 00:00 libpcre.so.3 -> libpcre.so.3.13.3
-rwxrwxrwx 1 root root 399240 1970-01-01 00:00 libpcre.so.3.13.3
-rwxrwxrwx 1 root root 134688 1970-01-01 00:00 libpthread-2.27.so
lrwxrwxrwx 1 root root 18 1970-01-01 00:00 libpthread.so.0 -> libpthread-2.27.so
-rwxrwxrwx 1 root root 27448 1970-01-01 00:00 librt-2.27.so
lrwxrwxrwx 1 root root 13 1970-01-01 00:00 librt.so.1 -> librt-2.27.so
※ 에러
1) packge architecture does not match system

강제로 설치
또 다른 에러 발생
root@ubuntu:# sudo dpkg -i --force-architecture libglib2.0-0_2.56.4-0ubuntu0.18.04.9_arm64.deb
dpkg: warning: overriding problem because --force enabled:
dpkg: warning: package architecture (arm64) does not match system (amd64)
Selecting previously unselected package libglib2.0-0:arm64.
(Reading database ... 693901 files and directories currently installed.)
Preparing to unpack libglib2.0-0_2.56.4-0ubuntu0.18.04.9_arm64.deb ...
Unpacking libglib2.0-0:arm64 (2.56.4-0ubuntu0.18.04.9) ...
dpkg: error processing package libglib2.0-0:arm64 (--install):
package libglib2.0-0:arm64 2.56.4-0ubuntu0.18.04.9 cannot be configured because libglib2.0-0:amd64 is at a different version (2.56.1-2ubuntu1)
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
Errors were encountered while processing:
libglib2.0-0:arm64
tar 파일 형태로 다시 다운로드 받은 후, 설치가 아닌 tar 파일 열어서 shared object 파일을 타겟보드에서 사용했다.
2) Read-only file system
ccimx8xsbcpro:/ # ls -al
drwxr-xr-x 2 root root 320 1970-01-01 00:00 lib
ccimx8xsbcpro:/ # cd lib
ccimx8xsbcpro:/lib # ls -al
total 3352
drwxr-xr-x 2 root root 320 1970-01-01 00:00 .
drwxrwxrwt 20 root root 980 1970-01-01 00:00 ..
-rw-r--r-- 1 root root 124784 1970-01-01 00:00 ld-2.27.so
lrwxrwxrwx 1 root root 10 1970-01-01 00:00 ld-linux-aarch64.so.1 -> ld-2.27.so
lrwxrwxrwx 1 root root 23 1970-01-01 00:00 libbluetooth.so.3 -> libbluetooth.so.3.18.16
-rw-r--r-- 1 root root 140328 1970-01-01 00:00 libbluetooth.so.3.18.16
-rw-r--r-- 1 root root 1341552 1970-01-01 00:00 libc-2.27.so
lrwxrwxrwx 1 root root 12 1970-01-01 00:00 libc.so.6 -> libc-2.27.so
lrwxrwxrwx 1 root root 23 1970-01-01 00:00 libglib-2.0.so.0 -> libglib-2.0.so.0.6600.8
-rw-r--r-- 1 root root 1252976 1970-01-01 00:00 libglib-2.0.so.0.6600.8
lrwxrwxrwx 1 root root 17 1970-01-01 00:00 libpcre.so.3 -> libpcre.so.3.13.3
-rw-r--r-- 1 root root 399240 1970-01-01 00:00 libpcre.so.3.13.3
-rw-r--r-- 1 root root 134688 1970-01-01 00:00 libpthread-2.27.so
lrwxrwxrwx 1 root root 18 1970-01-01 00:00 libpthread.so.0 -> libpthread-2.27.so
-rw-r--r-- 1 root root 27448 1970-01-01 00:00 librt-2.27.so
lrwxrwxrwx 1 root root 13 1970-01-01 00:00 librt.so.1 -> librt-2.27.so
ccimx8xsbcpro:/lib # cd ..
ccimx8xsbcpro:/ # chmod 777 lib
chmod: chmod 'lib' to 40777: Read-only file system
현재 파일 시스템이 read-only로 mount 되어 있으므로, read-write로 remount 진행했다.
ccimx8xsbcpro:/ # mount -o remount,rw /
ccimx8xsbcpro:/ chmod 777 ./lib
※ 참고
No such file or directory 에러 원인
https://developer.arm.com/documentation/ka004651/latest
https://docs.oracle.com/cd/E19683-01/817-3677/6mj8mbtbe/index.html
ELF / Executable / shared object file 설명
https://leekeezz.tistory.com/34
https://www.youtube.com/watch?v=PDkKz3zQVls
ldd 명령어 not a dynamic executable 해결법
https://blog.csdn.net/Chris_zhangrx/article/details/114396042
Android.mk 변수(LOCAL_SHARED_LIBRARY) 설명
https://developer.android.com/ndk/guides/android_mk?hl=ko
https://github.com/android/ndk/issues/993
.deb 설치 시 does not match system 에러 해결법
https://blue-mina.tistory.com/92
https://github.com/kubernetes/minikube/issues/10001
공유 라이브러리
https://cho001.tistory.com/122
공유 라이브러리 만드는 법
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=muri1004&logNo=221202776906
리눅스 ld 명령어에 -shared 옵션 추가해서 사용
Q. 현재 만들어진 shared object들이 Makefile에서 ld 명령어로 생성된건가?
A. Android.mk로 빌드되어 생성된다. 모듈(.so 파일) 형태로 생성
ex) sensors.imx8.so
.so 파일 저장 경로
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj_arm/SHARED_LIBRARIES/sensors.imx8_intermediates/sensors.imx8.so
HAL의 Makefile에서 shared object 빌드
/usr/local/dea-9.0-r3/vendor/nxp-opensource/imx/libsensors_sensorhub/Android.mk
# HAL module implemenation, not prelinked, and stored in
# hw/<SENSORS_HARDWARE_MODULE_ID>.<ro.product.board>.so
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_TAGS := eng
LOCAL_VENDOR_MODULE := true
LOCAL_SRC_FILES := \
sensors.cpp \
SensorBase.cpp \
InputEventReader.cpp
LOCAL_C_INCLUDES += hardware/libhardware/include \
system/core/include
#ifeq ($(BOARD_USE_LEGACY_SENSOR),true)
# LOCAL_CFLAGS += -DCONFIG_LEGACY_SENSOR
# LOCAL_SRC_FILES += FSLSensorsHub.cpp
# LOCAL_SRC_FILES += PressSensor.cpp
# LOCAL_SRC_FILES += LightSensor.cpp
#endif
#ifeq ($(BOARD_USE_SENSOR_PEDOMETER),true)
# LOCAL_CFLAGS += -DCONFIG_SENSOR_PEDOMETER
# LOCAL_SRC_FILES += Stepdetector.cpp
# LOCAL_SRC_FILES += Stepcounter.cpp
#endif
ifeq ($(BOARD_USE_SENSOR_BNO055),true)
LOCAL_CFLAGS += -DCONFIG_SENSOR_BNO055
LOCAL_SRC_FILES += FSLSensorsHub.cpp
endif
ifeq ($(BOARD_USE_SENSOR_BH1721),true)
LOCAL_CFLAGS += -DCONFIG_SENSOR_BH1721
LOCAL_SRC_FILES += LightSensor.cpp
endif
LOCAL_SHARED_LIBRARIES := liblog libcutils libdl
include $(BUILD_SHARED_LIBRARY)
※ Android.mk, 모듈(.so 파일)
https://developer.android.com/ndk/guides/android_mk?hl=ko
https://source.android.com/docs/core/architecture/hal/archive?hl=ko#hal-module
| [Android.mk] 모듈 관련 변수 | 설명 |
| LOCAL_MODULE | 모듈(.so 파일) 이름 설정 ex) LOCAL_MODULE := sensors.imx8 sensors.imx8.so라는 모듈 생성 |
| LOCAL_SRC_FILES | 모듈로 생성할 소스 파일 목록 |
| LOCAL_SHARED_LIBRARIES | 모듈이 런타임 시 종속되는 공유 라이브러리 목록 |
| [Android.mk] NDK에서 정의한 include 변수 | 설명 |
| include $(BUILD_SHARED_LIBRARY) | 앞서 LOCAL_XXX 변수로 설정한 모듈 정보를 가지고 모듈 빌드 방법을 결정한다. 최소 LOCAL_MODULE, LOCAL_SRC_FILES 변수 값은 설정돼 있어야 한다. |
빌드하면 아래 경로에 모듈 생성됐다.
/usr/local/dea-9.0-r3/out/target/product/ccimx8xsbcpro/obj_arm/SHARED_LIBRARIES/sensors.imx8_intermediates/sensors.imx8.so
생성된 모듈은 안드로이드에 의해 dynamic linking 된다.
'안드로이드 BSP' 카테고리의 다른 글
| /lib/libc.so.6: version 'GLIBC_2.28' not found (required by /lib/libglib-2.0.so.0) (0) | 2023.05.17 |
|---|
- Total
- Today
- Yesterday
- 최대한 갈 수 있을 때까지 이동
- 알고리즘
- 특정 문자열
- BFS
- 이분탐색
- C++
- binary search
- deque
- 정수자료형
- 퀵정렬
- 중복결과배제
- 중복순열
- 십일조
- BackTracking
- SW Expert Academy
- unordered_set
- 크로스컴파일
- 인접리스트
- Hal
- 자릿수
- range-based for loop
- 정렬
- 스택
- 최대한 갈 수 있을 때 까지 이동
- 재귀
- 합병정렬
- dfs
- 브루트포스
- 특정 조건따라 이동
- Set
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
