2024/2/16

test build android 14 for raspberry pi 4

因為要試試看 Android 12, 13, 14 的差異,所以用 raspberry pi 來測試。
順便紀錄一下很久沒做android (上次到 android 9) 之後,覺得是新的東西。
先照: 果然 prequreirement package 有新的:
sudo apt-get install bc coreutils dosfstools e2fsprogs fdisk kpartx mtools ninja-build pkg-config python3-pip
sudo pip3 install meson mako jinja2 ply pyyaml dataclasses
以 ubunutu 22.04,已經 build 過 android12 的系統。
結果缺 mtools (mcopy command). 和 pip install 的 meson, mako, ply.
結果用 pip3 install 還是 build fail,最後是用 apt (deb) 的 package 才 build OK

bionic/apex

結果是一種file format.從Android 10 就有了。
這種file 是用來更新用(?)
以往的 apk 都是用在 application 更新,所以都是由 package manager 負責。
但是如果是系統 component (例如native service),不是由 vm run 的程式,就沒版辦法了。
這個 apex 系統就是為了這個目的。
apex 檔案裡面主要是一個 ext4 的 img file,裡面包含需要的 program. so 和一些config file。
android 另外新增一個 apexd 服務,boot 時會檢查 /apex/ 目錄下有沒有 *.apex 檔案。
有的話就 把img loop mount,然後叫起裡面的服務。

另外,他也支援更新。因為 /apex 目錄是 ro,所以安裝都放在其他位置(/data ?)。
apexd 會去見查 /data 下有沒有 /apex/ 內檔案的對應新版本,有就用,沒有就用 /apex/ 下的。

結果在 android 14 上,幾乎所有東西都 apex 化了。
framework 裡的 service,甚至一些 apk 也都包裝成 apex.
out 目錄中,有一個 apex 目錄。裡面很多 componments folder.


raspberry-vanilla 開機失敗。
試試看: android-rpi。

update: 開機成功。
失敗是因為使用 pi4, 2GB 版本,logcat 一直出現 oom, 最後 watchdog 出現 wait too long,然後 goodbye 重新啟動 dalvik ? activitymanager.
改用 4GB 版本直接開啟 OK


lunch aosp_rpi4_tv 的話,build fail:
ERROR: files are incompatible: android.hardware.camera.provider@2.5::ICameraProvider/legacy/0 is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.gatekeeper@1.0::IGatekeeper/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.graphics.allocator@4.0::IAllocator/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.graphics.composer@2.4::IComposer/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.keymaster@4.1::IKeymasterDevice/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.tv.cec@1.0::IHdmiCec/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.usb.gadget@1.2::IUsbGadget/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.camera.provider@2.5::ICameraProvider/legacy/0 is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.gatekeeper@1.0::IGatekeeper/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.graphics.allocator@4.0::IAllocator/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.graphics.composer@2.4::IComposer/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.keymaster@4.1::IKeymasterDevice/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.tv.cec@1.0::IHdmiCec/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.usb.gadget@1.2::IUsbGadget/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.camera.provider@2.5::ICameraProvider/legacy/0 is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.gatekeeper@1.0::IGatekeeper/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.graphics.composer@2.4::IComposer/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.keymaster@4.1::IKeymasterDevice/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.tv.cec@1.0::IHdmiCec/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.usb.gadget@1.2::IUsbGadget/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.camera.provider@2.5::ICameraProvider/legacy/0 is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.gatekeeper@1.0::IGatekeeper/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.graphics.allocator@4.0::IAllocator/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.graphics.composer@2.4::IComposer/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.keymaster@4.1::IKeymasterDevice/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.tv.cec@1.0::IHdmiCec/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
android.hardware.usb.gadget@1.2::IUsbGadget/default is deprecated in compatibility matrix at FCM Version 8; it should not be served.
The following instances are in the device manifest but not specified in framework compatibility matrix:
    android.hardware.camera.provider@2.5::ICameraProvider/legacy/0
    android.hardware.gatekeeper@1.0::IGatekeeper/default
    android.hardware.graphics.allocator@4.0::IAllocator/default
    android.hardware.graphics.composer@2.4::IComposer/default
    android.hardware.keymaster@4.1::IKeymasterDevice/default
    android.hardware.tv.cec@1.0::IHdmiCec/default
    android.hardware.usb.gadget@1.2::IUsbGadget/default
    android.hardware.wifi.supplicant.ISupplicant/default (@1)
Suggested fix:
1. Update deprecated HALs to the latest version.
2. Check for any typos in device manifest or framework compatibility matrices with FCM version >= 8.
3. For new platform HALs, add them to any framework compatibility matrix with FCM version >= 8 where applicable.
4. For device-specific HALs, add to DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE or DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE.: Success
INCOMPATIBLE
16:15:08 ninja failed with: exit status 1                                                                                                                                                 
#### failed to build some targets (43:52 (mm:ss)) ####   
update: 錯了,上面的error 是因為用 "m" 來build 導致的。
如果 follow 原 po 的說明,用
make bootimage systemimage vendorimage -j$(nproc)
就沒有 build fail 了。


android14 的話,還需要 texlive-full ,領外 meson 也要 0.6以上,所以 ubuntu 20.04 的話,apt 的 meson 版本不夠 (0.52),要用 pip 的版本才夠。
另外,要用 python3,所以乾脆整個系統都用 python3 了: python-is-python3

2024/2/7

LVGL set font and filesystem

ref: 會遭遇兩個問題:
  • 如何讀入字型檔
  • 如何設定字型
讀入就跟 filesystem 有關。
filesystem 就跟 platform 有關,是用 windows, linux 還是 mcu,filesystem 的 api 不一樣。
lvgl 用 lv_conf.h 來設定用哪個 api:
/*File system interfaces for common APIs */

/*API for fopen, fread, etc*/
#define LV_USE_FS_STDIO 1
#if LV_USE_FS_STDIO
    #define LV_FS_STDIO_LETTER 'A'     /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
    #define LV_FS_STDIO_PATH ""         /*Set the working directory. File/directory paths will be appended to it.*/
    #define LV_FS_STDIO_CACHE_SIZE 0    /*>0 to cache this number of bytes in lv_fs_read()*/
#endif

/*API for open, read, etc*/
#define LV_USE_FS_POSIX 0
#if LV_USE_FS_POSIX
    #define LV_FS_POSIX_LETTER 'A'     /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
    #define LV_FS_POSIX_PATH ""         /*Set the working directory. File/directory paths will be appended to it.*/
    #define LV_FS_POSIX_CACHE_SIZE 0    /*>0 to cache this number of bytes in lv_fs_read()*/
#endif

/*API for CreateFile, ReadFile, etc*/
#define LV_USE_FS_WIN32 0
#if LV_USE_FS_WIN32
    #define LV_FS_WIN32_LETTER '\0'     /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
    #define LV_FS_WIN32_PATH ""         /*Set the working directory. File/directory paths will be appended to it.*/
    #define LV_FS_WIN32_CACHE_SIZE 0    /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
那個 LETTER 不是代表 windows 的 A 槽,B槽。而是用來代表 device.
像我用 ubuntu,試過用 "A:~/font.bin" 不行,一定要寫full path: "A:\home\charles\font.bin",然後用的是 FS_STDIO (會用 fopen())

load font 之後放進style,再把 style 設定到 object。
設定 font 跟 style 的 code:
     lv_font_t *myfont = lv_font_load("A:/home/charles/font.bin");
     static lv_style_t style;
     lv_style_init(&style);
     lv_style_set_text_font(&style,myfont);
要注意 stype 要是 static,因為之後系統會 periodically render 畫面,那時候會 access style 變數。如果是 local 變數,已經 free 調的話,就會出現 segment fault

下面用 example 的 label 為例子,設定 style:
    lv_obj_t * label1 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP);     /*Break the long lines*/
    lv_label_set_recolor(label1, true);                      /*Enable re-coloring by commands in the text*/
    lv_label_set_text(label1, "TEST MY FONT");
    lv_obj_set_width(label1, 150);  /*Set smaller width to make the lines wrap*/
    lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_align(label1, LV_ALIGN_CENTER, 0, -40);
    
    lv_obj_add_style(label1,&style,0);

2024/1/31

HUB8735 - Ameba Pro2 - AMB82 MINI

不曉得是不是一樣的東西。

不過說除了用 Arduino IDE 之外,也可以用 Standard SDK.
然後就是說參考: 就 follow Project README: clone , untar tools, export PATH.
然後就可以開始 build example 了。
因為 build 最後的 tool 有分 linux 版的 *.linux 和 windows 版的 *.exe。
這個 repo 的 linux file attibute 沒有設定對,build 的時候會出現 Error。
所以先去把所有的 *.linux 加上 execution.
開始 build..
cd ambpro2_sdk/project/realtek_amebapro2_v0_example/GCC-RELEASE/build/
cmake .. -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake -DVIDEO_EXAMPLE=ON
cmake --build . --target flash_nn -j4
build 完,會是剛剛 --target 寫的 flash_nn.bin

燒錄是 tools/Pro2_PG_tool,把 zip 解開。把剛剛build 好的 flash_nn.bin copy 過來。
和用 Arduino IDE 一樣, HUB 8735 進入 download mode:
  • 短路 A5, 3V3 pin
  • 按一下 reset buuton
dmesg 看一下是 ttyUSB?

README 的說明 -b 2000000,會出現 ucf fail,看 ./uartfwburn.linux --help, -b 是 baudrate 的意思。
所以改成 9612000 後成功:
~/ambpro2_sdk/tools/Pro2_PG_tool _v1.3.0$ ./uartfwburn.linux -p /dev/ttyUSB0 -f flash_ntz.nn.bin -b 921600 -U
/dev/ttyUSB0 opened
ping ok
ucfg ok
Uart boot 
programing	[========================================] 100%        77824/       77824 bytes
programing done.
uboot ok
reset device
/dev/ttyUSB0 opened
ping ok
ucfg ok
download to offset 0x0
masked area [0x0, 0x0]
dowload 0, [0x0, 0xd9e000]
fw_len = 0xd9e000
programing	[========================================] 100%     14286848/    14286848 bytes
programing done.
done for download 0
download success
然後把 A5. 3V3 短路 pin 解開。reset
用 uart 115200 看到開機 log:
== Rtl8735b IoT Platform ==

[Normal mode]
BootFromNORFlash
[Start Boot ROM...]
=== Load PARTBL ===
=== Load Done ===
=== Load ISP_IQ ===
[fcs chk pass]
ISP_IQ @ 0x8401080, 0x2cf80, 0x0
mfcs_data version 0x00010001
fcs_data version 0x00010101
=== Process ISP_IQ ===
=== Load Done ===
=== Load BL ===
[Image Start Table @ 0x18200]
=== Load Done ===

== Boot Loader ==
Jul 12 2023:11:11:05
=== Load FCS Para ===
=== Load Done ===
[crc pass]
=== Load ISP_IQ Sensor ===
ISP_IQ @ 0x8401080, 0x2cf80
=== Process ISP_IQ ===
=== Load Done ===
=== Load FW1 ===
FW_ISP_IQ @ 0x8081080, 0x2ef80
=== Process FW_ISP_IQ ===
DRAM_TYPE is DDR2 128MB.
ddr_freq = 533
VOE flash @ 0x80b0080, 0x7ef80
FCS KM_status 0x00002081 err 0x0000200a
Wait KM fcs done 0 us
FCS TM_status 0x003f0000 
store fcs data for application 
RAM TM_STATUS 0x00bf0000 status 0x00000080
RAM TM_STATUS 0x00bf1208 err 0x00001208
read fcs_status 0x000000bf
                                                                                                                                               read fcs_status 0x000000bf
== Process VOE IMG ===
[Image Start Table @ 0x20106200]
RAM Load @ 0x812f100->0x20106200, 0x6a58
DDR Load @ 0x8136080->0x70100000, 0x19f574
=== FW Load Done ===

Boot Loader <==

== RAM Start ==
Build @ 15:20:47, Sep 13 2023

$8735b>interface 0 is initialized
interface 1 is initialized
cfg_size_lib = 29, cfg_size_user = 29

Initializing WIFI ...[Driver]: [HALMAC]
 11692M HALMAC_MAJOR_VER = 1
 HALMAC_PROTOTYPE_VER = 4
 HALMAC_MINOR_VER = 20
 HALMAC_PATCH_VER = 
[Driver]: The driver include MP
[Driver]: Ver = libwlan:2023.07.21.14.18_b9.5_a20c848742482c5f0ee2b39dd14c0c200435e46b
- download_firmware_88xx HALMAC_RET_SUCCESS
RFE type = 0
start_addr=(0x4000), end_addr=(0x8000), buffer_size=(0x4000), smp_number_max=(2048)

WIFI initialized
[FAST_CONNECT] Fast connect profile is empty, abort fast connection

init_thread(49), Available heap 0x6b847e0

use ATW0, ATW1, ATWC to make wifi connection
wait for wifi connection...

#
最後的 # 是按下 Enter 後出現的 prompt,因為 README 說要下命令 config wifi..
ATW0=<WiFi_SSID> : Set the WiFi AP to be connected
ATW1=<WiFi_Password> : Set the WiFi AP password
ATWC : Initiate the connection
下完之後,開始 scan , connect...
Interface 0 IP address : 172.24.1.117

init_thread(49), Available heap 0x6b82200
[video_voe_presetting] fps:30  w:1920  h:1080   

 voe heap size = 13455104
fwin(1),enc_en(0),IQ_OFFSET = 0x16520
 fwin(1),enc_en(0),SENSOR_OFFSET = 0x2e560
sensor id 1 iq_data 16520 sensor_data 2e560
hal_voe_ready 0x0 0xbf1208 
 read fcs_status 0x000000bf
[video_init] uvcd iq is null, use default.
[video_init] uvcd SNR is null, use default.
IQ:FW size (98342)
sensor:date 2023/7/18 version:RTL8735B_VOE_1.4.4.0
sensor:FW size (1812)
sensor timestamp: 2023/07/18
iq timestamp: 2023/05/15 14:48:54
ISP:1 ENC:1 H265:1 NN:1
hal_voe_ready 0x0 0xbf1208 
voe   :RTL8735B_VOE_1.4.4.0 
sensor:RTL8735B_VOE_1.4.4.0 
hal   :RTL8735B_VOE_1.4.4.0 
load time sensor:52us iq:2722us itcm:0us dtcm:0us ddr:0us ddr2:0us

RTSP[0] port: 554
fwin(1),enc_en(0),IQ_OFFSET = 0x16520
connect successful sta mode

 fwin(1),enc_en(0),SENSOR_OFFSET = 0x2e560
sensor id 1 iq_data 16520 sensor_data 2e560
hal_voe_ready 0x0 0x1718 
npu[7045d6e0] gck vip_drv_init, video memory heap base: 0x77000000, size: 0x01000000
NN IRQ default priority : 0, set to 9
npu[7045d6e0] HASHMAP 0x0x703fa994(process ID) INIT SUCCESS
npu[7045d6e0] HASHMAP 0x0x703fb6a0(memory wrap) INIT SUCCESS
npu[7045d6e0] HASHMAP 0x0x703fc2ec(network information) INIT SUCCESS
npu[7045d6e0] HASHMAP 0x0x703fcf10(segment information) INIT SUCCESS
VIPLite Drv version 10c00
set yolo confidence thresh to 0.500000
set yolo NMS thresh to 0.300000
Deploy YOLOv4t
...
開啟 vlc 連到 rtsp://172.24.1.117:554,就可以看到 yolov4 objection detection 的輸出。

2024/1/20

HUB 8735

ref: 下載 IDE (linux 用 zip。解開)

安裝 HUB 8735 的 board support package (?):
在 IDE 的 perference -- Settings -- Additional board manager URL 中,填入:
https://github.com/ideashatch/HUB-8735/raw/main/amebapro2_arduino/Arduino_package/ideasHatch.json
然後到 Tools -- Board -- Board Manager ,找 HUB 8735,會出現 ideaHatch Ameba Board,選一版 install (4.0.8-R).

完成後,Tools -- Board 的內容就會多一個 ideaHatch Ameba Boad 可以選。
選 HUB-8735


File -- Example -- AmebaMultimedia -- StreamRTSP -- VideoOnly
開啟 example : streaming server

修改 source code 中的 ssid[],pass[]到家裡的 wifi,
Sketch -- Verify/Compile
開始 make,
出現 Error:
misc/elf2bin.linux: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./misc/elf2bin.linux)
看一下自己系統的 libc 版本:
strings /lib/x86_64-linux-gnu/libc.so.6  | grep GLIBC
..
只有列到 GLIBC_2.30
所以是 ubuntu 版本不夠新(20.04)
ref: Error /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
sources.list 加入
deb http://security.ubuntu.com/ubuntu jammy-security main 
然後 apt update, apt install lib
結果 lib 是很重要的 libary,所以一堆 service 要重開。

之後IDE重 Verify/Compile就 OK 了。

--- 這樣好像會 break distribution,update,upgrade之後,一堆function failed,

硬體接線。

hub 8735 使用 usb-uart 的 5V 就可以驅動了。
所以就順便用 usb-uart 的 5V, GND, TX, RD 接到 板子上。
usb-uart 插入nb,出現 ttyUSB0,
IDE 選 board, port : HUB 8735, ttyUSB0

讓 hub 8735 進入 download mode:

跟接 usb-uart 的四根 pin 的最旁邊的兩 pin : 3.3V, A5 ,短路後,按下正面的 led 旁邊的 button,就會 reboot into download mode.
在 IDE -- script -- upload,開始 build and upload.
IDE log 會出現:
Sketch uses 5054464 bytes (30%) of program storage space. Maximum is 16777216 bytes.
  Enter Flash Mode!
  Start Upload Flash
    Uploading...................upload success
  End Upload Flash
upload 完成,把剛剛的 A5, 3.3V 斷開。
開啟 uart terminal (picocom , 115200),按下正面 reset .. 可以看到開機 log..
    - RTSP -
rtsp://192.168.213.200:
[INFO] 554
開啟 VLC --- Media -- Open Network Stream
填入 rtsp://192.168.213.200:554
play 就可以看到畫面,開啟 VLC 的 codec information :
resolution : 1920x 1080, 30fps



另一種,不用 arduino,用一般mcu programming, gcc build 的方法是 sdk.
這個是 run yolov4 的 example:
20240130 update:

在 linux 的 arduino 安裝hub8735 的 board package 時,版本更新到 4.0.9 了,結果出現 Error,說 ameba_pro2_tools_linux-1.2.13 的 file size 錯,
去 release download gz 後看,果然 json 寫錯了。
後來發現 sha256sum 也錯,只好 fork 自己改,所以那個 json url 要改:
https://raw.githubusercontent.com/checko/HUB-8735/main/amebapro2_arduino/Arduino_package/ideasHatch.json
這樣安裝就 OK 了,所以也做了 pull request,之後應該就會改了吧。
-- size 和 checksum 都錯,有可能是 gz 放錯了,所以還是要等主站確定,ˋ這個只是暫時的方法。


Reatek AMB82 Mini

這個跟 HUB8735 很像,都是用 realtek RTL8735B,但是 GPIO pin 腳好像不一樣。
realtek 也有給他一個 arduino 的 sdk: 用法依樣,把 json 檔的 raw path 寫到 preference...