2025/7/7

TP-LINK TL-WN725N, RTL8188EU , on ubuntu 24.04

是 ubuntu-24.04-preinstalled-server-arm64-orangepi-5-plus...
dmesg
[  954.209502] usb 4-1: new high-speed USB device number 4 using ehci-platform
[  954.355029] usb 4-1: New USB device found, idVendor=0bda, idProduct=8179, bcdDevice= 0.00
[  954.355048] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  954.355058] usb 4-1: Product: 802.11n NIC
[  954.355067] usb 4-1: Manufacturer: Realtek
[  954.355075] usb 4-1: SerialNumber: 00E04C0001
[  954.499151] usb 4-1: RTL8188EU rev D (TSMC) romver 0, 1T1R, TX queues 2, WiFi=1, BT=0, GPS=0, HI PA=0
[  954.499173] usb 4-1: RTL8188EU MAC: e8:94:f6:0b:34:f5
[  954.499184] usb 4-1: rtl8xxxu: Loading firmware rtlwifi/rtl8188eufw.bin
[  954.499387] usb 4-1: Firmware revision 11.1 (signature 0x88e1)
[  955.112461] rtl8xxxu 4-1:1.0 wlxe894f60b34f5: renamed from wlan0
原來 loading firmware failed,所以
apt install firmware-realtek
他說是 virtual package,選一個 armbian-firmware,install 玩重新插拔 wifi usb.dmesg 就完成了。
然後 ip link 就可以看到 wlxe894f60b34f5

然後開始
harles-chang@orangepi5-plus:~$ nmcli device wifi list
IN-USE  BSSID              SSID                 MODE   CHAN  RATE        SIGNAL>
        54:78:C9:D4:03:EE  123456789012         Infra  1     65 Mbit/s   100   >
..
然後就可以連線了:
sudo nmcli device wifi connect "ssid" password "thepassword"

2025/7/2

gemini cli, ssh 通過auth

ref: 使用 gemini-cli 要先通過google account 認證。auth 的時候會開啟 browser。
但是在 ssh remote 就沒辦法開啟。
所以可以用上面 ref 的方法。
但是第一步browser 開啟的url 可以直接用 "gemini --debug" 模式啟動 gemini,就會在auth 的時候把 url 印出來。
copy 出來用 browser 打開,login google account, sign in 後,browser 會被重導到一格localhost 的位址,把這個位址 copy 下來。
用 ref 的方法,到 ssh remote 去用 curl 打開就可以。

做上面的事情的時候,gemini 都不能關掉,一職到 gemini 由 waiting 變成 authorize 後才可以關掉。



25/7/16 update

果然 cli 然後要人家開browser未免太無...
所以 0.1.11 版之後,支援no browser
NO_PROWSER=true gemini
這樣啟動後,就會出現一個 url,要你用 browser 去 login,login 玩會顯示一個 code,把她貼回來。

2025/7/1

Windows 登入 Samba 一直失敗

Windows 的網路芳鄰就是很多事,又蠢。
所以常常發生記住錯誤認證,導致無法登入 samba share 的問題,處理這種問題真是浪費生命。

處理方法就是就是把windows 記住的認證/連線刪除。
要用 net use
C:\net use
狀態       本機        遠端                    網路

-------------------------------------------------------------------------------
OK           N:        \\ABC\abc                 Microsoft Windows Network

中斷連線               \\192.168.145.150\MyShare Microsoft Windows Network
命令已經成功完成。
刪除 150 那個
C:\net use \\192.168.145.150\MyShare /delete
\\192.168.145.150\MyShare 已經刪除。
這樣,在重新開啟 檔案夾,用 \\192.168.145.150\charles-chang 加上 username,確保跟 username 比對。
dialog 又會出現 default,錯的 workgroup,username用 \\workgroup\charles-chang 指定用 workgroup (samba defatul)。
之後dialog 就會一直說你錯,但是你就一直按確認,大約3次,他就認輸了,用你心輸入的 username/password 登入。

軟體開發人員還是不要再用windows 了....

2025/6/28

some memo, gen key, sign key and gradlew

apksigner 在
./out/host/linux-x86/bin/apksigner 
要用 java 來run,所以要設定好 JAVA_HOME 和 PATH。
在 AOSP 中,lunch 完就都設定好了。
在 AOSP 中signkey 就是:
./out/host/linux-x86/bin/apksigner sign --key build/target/product/security/platform.pk8 \
--cert build/target/product/security/platform.x509.pem \
--out ~/SysApp-signed.apk \
out/target/product/vsoc_x86_64_only/system/priv-app/SysApp/SysApp.apk
platform.pk8 在
./build/make/target/product/security/platform.pk8
./build/make/target/product/security/platform.x509.pem
AOSP 中 OTA 相關的 generate key 說明:Sign build for release

可以使用這個 app 來測試 privilege 的權限:

使用 android-studio 的 java - jetbrain runtime,是在 android-studio/jbr,所以要用 gradlew build 的話,在console就要指定 JAVA_HOME
~/sysapp$ JAVA_HOME=~/android-studio/jbr ./gradlew -version

------------------------------------------------------------
Gradle 8.13
------------------------------------------------------------

Build time:    2025-02-25 09:22:14 UTC
Revision:      073314332697ba45c16c0a0ce1891fa6794179ff

Kotlin:        2.0.21
Groovy:        3.0.22
Ant:           Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM:  21.0.6 (JetBrains s.r.o. 21.0.6+-13391695-b895.109)
Daemon JVM:    /home/charles-chang/android-studio/jbr (no JDK specified, using current Java home)
OS:            Linux 6.11.0-28-generic amd64
這個 folder 是android studio sync 丸的 folder,也就是說 gradle/wrapper/ 下 download 好是當版本的 gradle-wrapper.jar 和 gradle-wrapper.properties



叫 geminil-cli 找到 Makefile 中 signkey 的地方:

Here's a high-level overview of how it works:
  • Build APKs: The build system first compiles your application's source code and resources to create an unsigned APK file.
  • Create Target Files Zip: The build system then creates a "target files" zip archive. This zip file contains all the files that will be included in the final
    system image, including your unsigned APK.
  • Sign Target Files: The sign_target_files_apks script is then called. This script takes the unsigned target files zip as input, signs all the APKs within it usingn
    the keys specified in build/target/product/security/, and produces a new, signed target files zip.
  • Create System Image: Finally, the build system uses the signed target files zip to create the system.img and other partition images.
The following snippet from /mnt/ssd2t/charles-chang/aosp/build/make/core/Makefile (around line 5623) shows how the sign_target_files_apks script is called:
   1 .PHONY: signed-target-files
   2 signed-target-files: $(BUILT_TARGET_FILES_PACKAGE)
   3    @echo"Package target files: $@"
   4 $(hide) ./build/make/tools/releasetools/sign_target_files_apks.py \
   5        --default_key_mappings build/make/target/product/security \
   6       $(INTERNAL_OTA_SIGNING_ARGS) \
   7        -o$(OPTIONS_RECOVERY_AS_BOOT) \
   8       $(BUILT_TARGET_FILES_PACKAGE) $@
In this rule:
  • $(BUILT_TARGET_FILES_PACKAGE) is the unsigned target files zip.
  • ./build/make/tools/releasetools/sign_target_files_apks.py is the signing script.
  • --default_key_mappings build/make/target/product/security tells the script to use the keys in your build/target/product/security directory.
  • $@ represents the output file, which is the signed target files zip.
This signed zip is then used by other parts of the build system to generate the final system images.

2025/6/22

原來有一些遣在的 rule.
packages/app/app-name 這個 app-name 要跟 Android.bp 的

2025/6/19

Cuttlefish Android Emulator

ref: 原來在 aosp 中的 emulator (goldfish) 在run aosp android14 的時候, qemu x86 kernel 一邊沒 lz4,一邊 ramfs 好像不一樣。
然後 aosp source project site 說明 竟然都寫 cuttlefish 了。

cuttlefish 已經是獨立的 project,clone 下來後,build 成 deb,需要 libtinfo5,所以ubuntu24.04 用 libtinfo6 會 build fail。
只好download libtinfo5 的 deb 下來 install,才能 build 成功。
tools/buildutils/build_packages.sh

build 完會有這麼多 deb..
  • cuttlefish-orchestration_1.13.0_amd64.deb : 在 google 的 雲端server 用的(?)
  • cuttlefish-base_1.13.0_amd64.deb : 這個就是 emulator 的 deb
  • cuttlefish-integration_1.13.0_amd64.deb : 跟google 雲端上的 emulator溝通用的一些tool
  • base/ cuttlefish-common-build-deps_1.13.0_amd64.deb :
  • cuttlefish-user_1.13.0_amd64.deb : web server 版的 emulator,會run 成一個 web server,用 browser 來操作
  • /frontend/cuttlefish-frontend-build-deps_1.13.0_all.deb :
  • cuttlefish-common_1.13.0_amd64.deb : [DEPRECATED]
所以把 base 和 user 安裝(用 apt),之後,會產生 幾個 group,要把自己加進去:
sudo usermod -aG kvm,cvdnetwork,render $USER
然後因為會產生 /dev/ 下的node,所以要 reboot.

準備 system image,從 aosp build, target 是 aosp_cf_x86_64_phone-trunk-userdebug
build 完aosp source code,就會有 launch_avd 這個 command.
follow google 說明直接 launch 的話,會有 Error:
launch_avd
....
ailed to connect:No such device
[2025-06-19T10:09:00.523729147+00:00 ERROR crosvm] exiting with error 1: the architecture failed to build the vm

Caused by:
    failed to create a PCI root hub: failed to create proxy device: Failed to configure tube: failed to receive packet: Connection reset by peer (os error 104)
Detected unexpected exit of monitored subprocess /home/charles-chang/aosp/out/host/linux-x86/bin/process_restarter
Subprocess /home/charles-chang/aosp/out/host/linux-x86/bin/process_restarter (16314) has exited with exit code 1
Failed to connect:No such device
Client closed the connection
Client closed the connection
Client closed the connection
[2025-06-19T10:09:01.549915546+00:00 ERROR crosvm] exiting with error 1: the architecture failed to build the vm

Caused by:
    failed to create a PCI root hub: failed to create proxy device: Failed to configure tube: failed to receive packet: Connection reset by peer (os error 104)
....
不知道是什麼原因,但是加上 gpumode 之後就可以開起來..
launch_cvd --gpu_mode=gfxstream
...
VIRTUAL_DEVICE_BOOT_STARTED
VIRTUAL_DEVICE_NETWORK_MOBILE_CONNECTED
VIRTUAL_DEVICE_BOOT_COMPLETED
Virtual device booted successfully
依照 google cuttlefish 的說明,這樣啟動的 emulator 是沒有螢幕的,所以用 adb 可以連線。
開啟 webserver 的話,加上 --daemon
launch_cvd --gpu_mode=gfxstream --daemon
...
Virtual device booted successfully
VIRTUAL_DEVICE_BOOT_COMPLETED
這樣會跑在background,用 browser 開啟 http://localhost:8443 就會看到 cvd-1
按下 "connect" 就會出現android 手機畫面..
google 建議用 webrtc,效果會更好。
launch_cvd --gpu_mode=gfxstream -start_webrtc --daemon
停止要用 cvd reset 或 stop_cvd

cuttlefish 使用 virtual network,所以沒版法直接 listen public IP。
如果其他機器要連線,要用 ssh-tunnel:
  • 在 remote mynb 啟動 cuttlefish -start_webrtc
  • 在 local pc 設定 ssl tunnel : ssh -L 50000:localhost:8443 myname@mynb
  • local pc 的 browser 開啟 localhost:50000


cuttlefish 啟動過就會在 $HOME 之下create 一個 cuttlefish 目錄,其中
  • assembly : 設定檔
  • environment : 會有folder env-1,裡面是上次run 的環境變數
  • instance : 會有 folder cvd-1 (emulator id),上次的instance 紀錄
然後在 $HOME 下,會有cuttlefish_XXX link 到 cuttlefish 下的folder/file。
所以一旦emulator 出問題,關掉下次再開也是出問題,用 cvd reset 也無效,就要手動刪掉那些 cvd-1 目錄。

所以在 ~/cuttlefish/instance/cvd-1/ 裡:
  • kernel.log : 就是 kernel message
  • console : 就是 emulator 的 console,會是 link 到 /dev/pty/X,可以用 screen 來開



emulator 是否run 的起來,竟然和host和 android image 有關,使用 Adnroid-14 AOSP build 出來的 aosp_cf image,在有些pc 上可以 run,有些不行,有些要加 --gpu_mode,有些不能加。
而且 run 起來後,app 啟動計次顯示就會發生問題,系統反應也變慢。
但是使用 -b android-latest-release 的image則幾乎所有機器都沒問題,而且只需要加 --start_webrtc 就可以,不用管 --gpu_mode,cuttlefish 會自己偵測。

2025/6/15

Build image from AOSP and run on emulator

ref:
想要build aosp 在 emulator 跑,測試 user build 和 userdebug build 的差異。
然後..
先 clone source..
mkdir aosp && cd aosp
repo init -u https://android.googlesource.com/platform/manifest -b android-14.0.0_r75 --depth=1
repo sync -c --no-tags --no-clone-bundle -j3
超過 3 就會有 resource limiit error,其實最後還是用1。
中途出現一些 checkout error,把整個source code 刪除,留下 .repo 目錄,再 sync 一次就 OK

然後做 lunch,這個有點問題
source buile/envsetup.sh
lunch
出現一堆,但是都沒有類似說明的 x86_64,ref:how do I build android emulator from source 的說明。
有些 lunch target 本來就不會show,所以試試看
lunch sdk_phone64_x86_64-trunk_staging-user
竟然 OK 了。-- 嘗試 userdebug, eng 也都 OK
把 printconfig列出來確認:
============================================
PLATFORM_VERSION_CODENAME=VanillaIceCream
PLATFORM_VERSION=VanillaIceCream
PRODUCT_INCLUDE_TAGS=com.android.mainline mainline_module_prebuilt_nightly
TARGET_PRODUCT=sdk_phone64_x86_64
TARGET_BUILD_VARIANT=user
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-6.8.0-60-generic-x86_64-Ubuntu-24.04.2-LTS
HOST_CROSS_OS=windows
BUILD_ID=AP2A.240805.005.S4
OUT_DIR=out
============================================
如果依照 ref 的說明
lunch aosp_cf_x86_64_only_phone-aosp_current-userdebug
...
build/make/core/release_config.mk:145: error: No release config found for TARGET_RELEASE: aosp_current. Available releases are: ap2a next staging trunk trunk_food trunk_staging.
依照error 說明把 aosp_current 改掉
lunch aosp_cf_x86_64_only_phone-trunk-user
就可以了 (順便測試 user build 也 OK)
============================================
PLATFORM_VERSION_CODENAME=VanillaIceCream
PLATFORM_VERSION=VanillaIceCream
PRODUCT_INCLUDE_TAGS=com.android.mainline mainline_module_prebuilt_nightly
TARGET_PRODUCT=aosp_cf_x86_64_only_phone
TARGET_BUILD_VARIANT=user
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=silvermont
HOST_OS=linux
HOST_OS_EXTRA=Linux-6.8.0-60-generic-x86_64-Ubuntu-24.04.2-LTS
HOST_CROSS_OS=windows
BUILD_ID=AP2A.240805.005.S4
OUT_DIR=out
============================================
cf 就是給 cuttlefish (android emulator name) 用的。



有時候 build 到最後會有Error,說 /dev/loop2 沒有,這是因為沒有 disk 權縣,加入 disk group 就可以了。



google 說以後都要用 AOSP-release 了。
加上用 android 14 的tag, cuttlefish ru 一下就 hang 住,拿 prebuild 的又OK。
查 prebuild 是Android-16,所以 follow aosp 說明...
repo init --partial-clone --no-use-superproject -b android-latest-release -u https://android.googlesource.com/platform/manifest
repo sync -c -j3
依照googlesource 說明
lunch aosp_cf_x86_64_only_phone-aosp_current-userdebug
因為現在 lunch 都不會出現target 讓你選了。

然後就可以用 m 來 build.
ubuntu 24.04 會出現 mount error, ref: permission denied in mount (/):
sudo sysctl -w kernel.apparmor_restrict_unprivileged_unconfined=0
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
或是增加這個檔案到系統,免得每次開機都要重新設:
$ cat /etc/sysctl.d/99-apparmor-unconfined.conf
kernel.apparmor_restrict_unprivileged_unconfined=0
kernel.apparmor_restrict_unprivileged_userns=0

$sudo sysctl --system