RPI: PieOnPi: 从源代码编译整个系统

这里将介绍如何从源代码编译出Raspberry Pi 3 Model B & B+所使用的Android 9 Pie系统。

注:

  1. drm_hwcomposer, mesa 3d & minigbm还需要进一步整理,暂时以二进制的形式提供。
  2. libdrm (device/brobwind/rpi3/hals/display/libdrm 使用的版本为v2.4.96,可以从这里下载:https://dri.freedesktop.org/libdrm/

 

  • 编译环境搭建

编译用的主机使用的当然的是x86_64平台,所使用的操作系统为ubuntu-16.04。

同时,还需要执行如下命令安装相关的编译工具(可以参考:https://source.android.com/setup/build/initializing):

1. 安装JDK

$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk

2. 安装其他工具(基于ubuntu 14.04)

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip

3. 安装repo命令(可以参考这里: https://lug.ustc.edu.cn/wiki/mirrors/help/aosp):

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl -sSL 'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' | base64 -d > ~/bin/repo
$ chmod a+x ~/bin/repo
  • Android 9系统源代码下载

代码可以从https://lug.ustc.edu.cn/wiki/mirrors/help/aosp 或者 https://android.googlesource.com  下载

执行如下命令:

$ repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-9.0.0_r8 --repo-url=git://mirrors.ustc.edu.cn/aosp/tools/repo

下载Raspberry Pi 3设备相关代码:

$ mkdir -pv device/brobwind
$ git clone git://github.com/brobwind/pie-device-brobwind-rpi3 device/brobwind/rpi3

添加本地manifest文件:

$ mkdir -p .repo/local_manifests
$ ln -sv ../../device/brobwind/rpi3/local_manifest.xml .repo/local_manifests/

开始下载代码:

$ repo sync
  • 修改framework代码

下载完所有的代码之后,还需要修改一行framework代码。

Raspberry Pi 3 Model B & B+ GPU支持的最大纹理为:2048×2048, 并且我们配置需要输出为固定的720p(1280×720)分辨率。系统开机时,system_server进程会出现如下异常:

02-09 18:17:28.722   177   177 E BufferLayer: dimensions too large 2560 x 2560
02-09 18:17:28.722   177   177 E SurfaceFlinger: createBufferLayer() failed (Invalid argument)
02-09 18:17:28.723   650   650 E SurfaceComposerClient: SurfaceComposerClient::createSurface error Invalid argument
02-09 18:17:28.724   650   650 E System  : ******************************************
02-09 18:17:28.725   650   650 E System  : ************ Failure starting core service
02-09 18:17:28.725   650   650 E System  : android.view.Surface$OutOfResourcesException
02-09 18:17:28.725   650   650 E System  :  at android.view.SurfaceControl.nativeCreate(Native Method)
02-09 18:17:28.725   650   650 E System  :  at android.view.SurfaceControl.<init>(SurfaceControl.java:590)
02-09 18:17:28.725   650   650 E System  :  at android.view.SurfaceControl.<init>(SurfaceControl.java:60)
02-09 18:17:28.725   650   650 E System  :  at android.view.SurfaceControl$Builder.build(SurfaceControl.java:377)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.wm.DisplayContent.<init>(DisplayContent.java:777)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.wm.RootWindowContainer.createDisplayContent(RootWindowContainer.java:219)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.wm.DisplayWindowController.<init>(DisplayWindowController.java:44)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.am.ActivityDisplay.createWindowContainerController(ActivityDisplay.java:125)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.am.ActivityDisplay.<init>(ActivityDisplay.java:120)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.am.ActivityStackSupervisor.setWindowManager(ActivityStackSupervisor.java:676)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.am.ActivityManagerService.setWindowManager(ActivityManagerService.java:2774)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.SystemServer.startOtherServices(SystemServer.java:871)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.SystemServer.run(SystemServer.java:431)
02-09 18:17:28.725   650   650 E System  :  at com.android.server.SystemServer.main(SystemServer.java:294)
02-09 18:17:28.725   650   650 E System  :  at java.lang.reflect.Method.invoke(Native Method)
02-09 18:17:28.725   650   650 E System  :  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
02-09 18:17:28.725   650   650 E System  :  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)
02-09 18:17:28.726   650   650 I SystemServer: StartInputMethodManagerLifecycle
02-09 18:17:28.726   650   650 I SystemServiceManager: Starting com.android.server.InputMethodManagerService$Lifecycle
02-09 18:17:28.737   650   650 D SystemServerTiming: StartInputMethodManagerLifecycle took to complete: 11ms
02-09 18:17:28.737   650   650 I SystemServer: StartAccessibilityManagerService
02-09 18:17:28.758   650   650 D SystemServerTiming: StartAccessibilityManagerService took to complete: 21ms
02-09 18:17:28.758   650   650 I SystemServer: MakeDisplayReady
02-09 18:17:28.761   650   650 W SystemServer: ***********************************************
02-09 18:17:28.762   650   650 E SystemServer: BOOT FAILURE making display ready
02-09 18:17:28.762   650   650 E SystemServer: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.android.server.wm.DisplayContent.computeScreenConfiguration(android.content.res.Configuration)' on a null object reference
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.server.wm.WindowManagerService.computeNewConfigurationLocked(WindowManagerService.java:4421)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.server.wm.WindowManagerService.computeNewConfiguration(WindowManagerService.java:4411)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.server.am.ActivityManagerService.updateConfiguration(ActivityManagerService.java:22426)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.server.wm.WindowManagerService.displayReady(WindowManagerService.java:4541)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.server.SystemServer.startOtherServices(SystemServer.java:962)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.server.SystemServer.run(SystemServer.java:431)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.server.SystemServer.main(SystemServer.java:294)
02-09 18:17:28.762   650   650 E SystemServer:  at java.lang.reflect.Method.invoke(Native Method)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
02-09 18:17:28.762   650   650 E SystemServer:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)
02-09 18:17:28.764   650   650 D SystemServerTiming: MakeDisplayReady took to complete: 6ms
02-09 18:17:28.764   650   650 I SystemServer: StartStorageManagerService

所以需做如下修改:

相关的patch代码:

diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index cd8fdbf..6918bc3 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -769,7 +769,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
         // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
         // layers the ability to match their parent sizes and be able to skip
         // such arbitrary size settings.
-        mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
+        mSurfaceSize = (int)(Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 1.4);
 
         final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
                 .setSize(mSurfaceSize, mSurfaceSize)
  • 配置编译环境
$ . build/envsetup.sh
$ lunch rpi3-eng

如下图:

  • 编译

 

$ m -j

编译时间:CPU: Intel I5 8500T; RAM: 8G DDR4 2666; HDD: 1T 大概需要1小时32分钟。

 

编译结束之后,会在out/target/product/rpi3下生成如下image:

1. rpiboot.img

2. boot.img

3. system.img

4. vendor.img

5. userdata.img

  • 相关的参考文档
  1. https://lug.ustc.edu.cn/wiki/mirrors/help/aosp
  2. https://gerrit-googlesource.proxy.ustclug.org/
  3. https://source.android.com/setup/build/initializing
  4. https://source.android.com/setup/build/downloading
  5. https://source.android.com/setup/build/building

发表评论