2016年9月23日 星期五

[Ubuntu Snappy 2] - trace the booting process

最近新的 Ubuntu Core 16 Image release 了,這是就我知道的第一版 base on Snappy 2.x 的 Ubuntu core image (Snappy 2.x 是利用 snapd 管理套件, Snappy 1.x 沒研究), 詳情可見這封 mail :
https://lists.snapcraft.io/archives/snapcraft/2016-September/001166.html

小弟花了一點時間看一下他的 boot process 在此作一下記錄以免大腦記憶体不足被 garbage collection 清掉。

Ubuntu core image divides the storage to 2 partition: "writable" and "system-boot" 給 KVM 和給 raspberry pi 3 的 image 其 boot partition label 看起來不同,反正就是一個 boot ,一個 system.

boot partition:
  • /boot/grub/grubenv decides the kernel and core snap which will be loop mounted by grub.
  • /boot/grub/grub.cfg loop mount kernel snap to specify the position of kernel and initramfs image.

在writable partition 中的 kernel snap 中取得 kernel 及 initramfs ,在 initramfs 中 再 mount OS snap:

mount "${writable_mnt}/system-data/var/lib/snapd/snaps/${snap_core}" "$rootmnt"

這裡我覺得可以在開發時將 OS snap 轉成 ext4 image,然後 mount 成 rw ,這樣比較方便,只是 size 會從 75mb 擴增到 242mb。

然後其 initramfs 應該是來自於這裡:
最後就是進到 systemd 再把 snapd 叫起來。

2016年9月18日 星期日

Ubuntu Phone - install Ubuntu on Meizu Pro5 Android edition

最近看到 #phone-phone mailing list[1] 上面有人分享如何將 Meizu Pro5 Android Edition 刷成 Ubuntu Edition,因為手上沒有以 Android 版本出貨的 Meizu Pro5 所以無法實測其方法,但看來是可行的。

因為 Ubuntu Phone Edition 基本上是買不到了,就一定會有人想嘗試從 Android Edition 刷過去,此篇想用小弟的經驗嘗試分析在刷機的前後可能會遇到的問題,供想刷機的人作參考。

任何自行刷機的行為需自行負擔其風險,本人不保証任何保固上面的問題。

以下列出目前有出貨的手機:

  • BQ Krillin
    • 太舊了,不想討論
  • Meizu MX4 (Arale)
    • MTK solution
    • 刷 Factory images 需要用到MTK提供的 flash-tool
      • 本人經驗,不同的 SoC 對應的 flash-tool 版本可能不同,我之前用的是 v5.1452.00.100
  • BQ M10 (frieza)
    • MTK solution
      • 刷 Factory images 需要用到MTK提供的 flash-tool
        • 本人經驗,不同的 SoC 對應的 flash-tool 版本可能不同,我之前用的是 v5.1520.00.100
  • Meizu Pro5 (Turbo)
    • 2Samsung solution
      • 直接用 fastboot 刷 factory image 即可
factory images 就是每個 partition image file, 然後用工具刷進去,就可以出廠了。以上只有 Pro5 可以用 fastboot 直接刷每一個 partition,最方便而且他是最新的一支 Ubuntu phone 所以拿它來刷還滿合理。

上面的 Krillin, Arale and Turbo 是 device name,也就是在 image server 上面的 device 對應,ubuntu-device-flash 的 --device 要輸入的也就是它們。


目前來說,每支 Ubuntu Edition 的 partition size 都跟 Android Edition 不同,因為 Ubuntu 需要的 system partition(2.5G) 及 cache partition (700MB) 比較大。 為何? 因為在 recovery 中作 update 時,要拿 cache partition 來作 buffer。 那問題就來了~ 原本 Pro5 的 cache partition 只有 500mb,有點危險。 system partition Android Edition, AFAIK 原本就給 2.5G,所以沒有問題。

Cache partition 太小會怎樣? 你在 OTA 的時後, tarballs 會被放在 cache partition,然後 recovery mode 的時後拿來 update (請見 ubuntu-phone-recovery),cache 太小就無法 OTA ,聰明的看官應該已經想到應對的方式了..... 對,手動 update 可以解決這個問題,一樣請見 ubuntu-phone-recovery

BTW.... bootloader 就在 device tarball 裡面呀? 那是不是可以直接刷 bootloader 就好? 嗯.... 刷 bootloader 一不小心就變磚了,而且我也不知道 pro5 Android edition 的 bootloader partition 可不可以刷,所以... 科科

再來就是要把 partitions 一個一個刷進去,可以用 [1] 的方法,也可以用小弟的 repack-factory image tool [2] ,直接從 OTA server 上把 images 拉下來打包成 factory images ,然後用 fastboot 刷進去。

以上再次申明,因小弟沒有 Android Edition,所以只在 Ubuntu Edition 上測試過,如果有勇者嘗試了,再請分享結果吧 :)

[1] https://lists.launchpad.net/ubuntu-phone/msg22248.html
[2] https://github.com/alex-tu-cc/ubuntu_phone_tools

2016年7月10日 星期日

Ubuntu Phone - recovery

想要 hack 手機最快速的方式應該是從 recovery 下手,目前 Ubuntu phone 都有在官網上 release adb shell enabled 的 recovery image [1],可以用 fastboot 輕易燒入。

進入 recovery 後,可以借由 ubuntu-device-flash update 的動作了解其如何將 image 更新進去,了解之後要修改 image 內容就容易多了。

本文將簡介其運作,如想深入了解請自行 adb shell 進去 recovery 研究看看。

目前 phablet 6.x common tree 已將部份 recovery 需要的修改收錄進去,從 diff 可以看到有一個 system-image-upgrader 負責 OTA update 的動作,大致上整個 process 為:

 * u-d-f 將 ubuntu tarball, device tarball, custom tarball 從 system-image.ubuntu.com 上拉下來放到 device 裡 /cache/recovery 中並建立 ubuntu_command 檔。
 * system-image-upgrader 讀取 ubuntu_command 裡命令將 tarball 解開並將 放到 /system partition 裡。

如此一來,也可以在其他的 Android phone 上運用相同的方式,將 ubuntu tarball, custom tarball 塞進 /system 或是學 Nexus 4 將 system partition 用 loop mount 的方式放到 ubuntu.img。

接下來就只要煩腦 device tarball 就好了。 device tarball 裡包括了 kernel 及 Android 所需的各 partition 的 image 及一個減肥過的 android 放在 /var/lib/lxc/android/system.img (refer to [2])

Android code tree 的 Ubuntu phone patch 可以在 phablet 6.x common tree [3] 找到,另外 phablet_6.0.0_r1 是一個 fake device 用來假裝一個 Android 6.x device,這樣其他 Android 6.x device code tree 如果其 Merge base 是 AOSP 6.0.0_r1 就可以直接 merge 它取得 Ubuntu 為 Android 6.x 所作的修改。

這樣一來應該就可以 build 出 system.img 了,但是不是可以開機,還要看其廠商給的 Android code tree (BSP AOSP code tree) 是不是改了原本 AOSP 的 HAL,甚致有可能需要改到 hybris[4] 來迎合廠商的修改。

好像寫超過 recovery 的範圍了,反正 recovery 就只用來 OTA update,基本上只要recovery 的動作正常,就算其他 partition 都是空的,也可以透過 recovery 將其全都填上需要的內容。

另外官方的 ubuntu-device-flash 目前只支持三個 tarball 同时更新,但在開發階段可能只需要更新 custom tarball 或是 device tarball,覺得每次都要刷三個 tarball 有點浪費時間的話,可以手動修改 ubuntu_command 或是使用 這個小 tool [5] 去 update 單一個 tarball.

題外話:
如果想要刷回 Android edition ,通常先刷 Android 的 recovery ,再用其 recovery update 就可以了,但要小心的部份是 Android 的更新包中有時後會有 bootloader或preloader 的更新,最好把它拿掉,因為會導致 Ubuntu repartition 的設定不見。 說白了,就是把 system 及 boot partition 換掉,就可以回到 Android 了 (其他 partition 都共用)。

[1] https://wiki.ubuntu.com/Touch/Devices
[2] https://developer.ubuntu.com/en/phone/devices/porting-new-device/
[3] https://code-review.phablet.ubuntu.com/#/admin/projects/aosp/platform/manifest
[4] https://launchpad.net/~libhybris-maintainers/libhybris/+git/libhybris
[5] https://github.com/alex-tu-cc/ubuntu_phone_tools/blob/master/update_tarball.sh

Other refs:
https://wiki.ubuntu.com/Touch/MaintainingCodePhablet

2016年6月14日 星期二

Ubuntu Phone - porting - emulator

其實對 emulator 之前沒什麼研究,依official wiki 中步驟[1]抓來的 android code tree 是phablet-4.4.2_r1 [2],看來 wiki 中的 "Building from scratch" 就是抓 phablet 4.4.2_r1 來 build emulator。
如果是直接裝 ubuntu-emulator 其 dependency ubuntu-emulator-runtime.deb 就會把prebuild 的 emulator 放在下面
/usr/share/android/emulator/out/host/linux-x86/bin/emulator-x86
/usr/share/android/emulator/out/host/linux-x86/bin/emulator-arm
然後執行 "ubuntu-emulator run" 時 [2] 時再去執行相對位置的 emulator-*.

如此看來如果要把 Ubuntu emulator 升級當作一個 reference device 的話,可以拉新的 AOSP code,build 出其 emulator binary,還可以升級goldfish kernel [3] 到3.18 or 4.4.  最新的 emulator kernel 已改為 ranchu [6].

目前新的 AOSP tree 不再包含 qemu [4], 而是直接放一個 prebuilt emulator [5]所以可能需要再另外把它拉回來build。

keep updating .....
(
emulator 還不能動:
https://hackpad.com/Phablet-Ubuntu-Touch-z2FB0yq24Eq
)

[1] https://wiki.ubuntu.com/Touch/Emulator
[2] http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/wily/goget-ubuntu-touch/wily/files/head:/ubuntu-emulator/
[3] https://android.googlesource.com/kernel/goldfish.git
[4] https://android.googlesource.com/platform/external/qemu
[5] https://android.googlesource.com/platform/prebuilts/android-emulator
[6] https://groups.google.com/forum/#!topic/android-emulator-dev/dltBnUW_HzU

2016年6月11日 星期六

Ubuntu Phone - porting - tools

工欲善其事,必先利其器,知道工具在那裡並如何使用,會方便很多,這篇文章就用來收集開發時後可以用到的工具,連結等等 ... keep updating...

## Documents
 * https://wiki.ubuntu.com/Touch
  * https://wiki.ubuntu.com/Touch/MaintainingCodePhablet
  * https://wiki.ubuntu.com/Touch/ContainerArchitecture

## Docker which can be used to build AOSP/device tarball.
 * https://hub.docker.com/r/phablet/platform-devel/

## The place to file bug for Ubuntu touch.
 * https://bugs.launchpad.net/canonical-devices-system-image
 * https://bugs.launchpad.net/turbo
 * https://bugs.launchpad.net/avila
 * https://bugs.launchpad.net/arale

## The reference device Sony Z5 for android 6.x (on developing)
 * https://wiki.ubuntu.com/Touch/Devices/minato

## The phablet 6.x common tree.
 * https://code-review.phablet.ubuntu.com/#/admin/projects/aosp/platform/manifest
  * $ repo init -u ssh://<username>@code-review.phablet.ubuntu.com:29418/aosp/platform/manifest \ -b phablet-6.x && repo sync
 * https://wiki.ubuntu.com/Touch/MaintainingCodePhablet

## The server which host device images
 * Global: http://system-image.ubuntu.com/
 * China: http://cn.system-image.ubuntu.com or http://cache-origin.system-image.ubuntu.com

## Tools
 * https://github.com/alex-tu-cc/ubuntu_phone_tools

## Tips
 * How to flash Meizu Pro5 Android edition to Ubuntu?
  * I did not test this way, but it looks good to go.
  * http://askubuntu.com/questions/767323/how-to-install-ubuntu-on-meizu-pro-5-that-was-originally-with-android/767771#767771?newreg=7437cbdaadd6416ea11a98492c08df17

2016年6月7日 星期二

Ubuntu Phone - porting - 緣起

Ubuntu Phone 已經上市一段時間了,但似乎沒看到 community 在 Port 它,可能是實體手機出貨量太少,也可能是 document 不夠(沒看到中文的)導致開發者興趣缺缺,作最僅剩的第三方 phone os,不免覺得有點可惜。其實買 Ubuntu edition phone 滿划算的,因為其可以刷回 Android 版本,但 Android edition 就不行刷到 Ubuntu edition 了(主因為 Ubuntu resize partition)。

但是如果 WIDI support[1][註1] 順暢度達成後,當成一個開發阿宅的隨身小 pc[2],用來 ssh 到家中或是公司的 server ,在外面開會或是在朋友家中也可以當一個臨時的報告用小 pc 也是滿方便的,甚至有些家庭可能就不需要買文書小筆電可以在外用手機,回家變桌機。這實在是個人滿期待看到的結果。

App 生態不完整是當然不流行的一大主因,但個人認為這是鷄跟蛋的問題,就跟 Android 剛出的時後也是被笑完全跟 Iphone 沒得比,但後來也是追上來了。只要有抓到大家想要的點,自然就會有人用了。目前每次 OTA 後,所有裝過的 deb packages 都要重裝是令個人感覺比較不方便的地方,不知道有沒有什麼好方法解決。

因此,我想借這個 blog 來分享一些開發的經驗,所以留言開放大家點歌~哦不,是點主題,看有那些你很想要知道的,但一直找不到資料,我可以盡我所能(=有空的時後)的回答大家。

目前我想先分享一些 porting 上可能會遇到的問題,以及大約的架構 (說得太淺請別笑我,大家切撮指教)

其實有很多問題也可以直接上 mail list [4]上詢問,上面高手如雲。

[1] http://news.softpedia.com/news/ubuntu-touch-ota-11-update-introduces-wireless-display-support-to-ubuntu-phones-504681.shtml
[2] http://www.techrepublic.com/article/ubuntu-convergence-finally-impresses-me/
[3] https://wiki.ubuntu.com/Touch/Devices/minato
[4] https://lists.launchpad.net/ubuntu-phone/

[註1] 因為目前很多手機都將 MHL 功能拿掉,所以目前看來只有 WIDI 比較可行,不過還是有一些手機存在 MHL [3],如果可以順利 porting 完成,可能也有助於手機廠再回頭看 MHL 這塊。

2015年11月15日 星期日

import AOSP to gitlab


AOSP have almost 700 repositories, it is failed to import them into gitlab.

Install from source, it introduced database (postgresql) and redis

Gitlab architecture:


unofficial gitlab docker:

detail description of parameters:

issue "500 error" after import lots of repositories:

It seems be fixed in this issue?

https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/import.md
root@8395b04d4219:/home/git/gitlab# bundle exec rake gitlab:import:repos RAILS_ENV=production

The official docker image give me another issue:
Failed to create repository via gitlab-shell