Others: Android Q on NanoPi Neo – bootloader & kernel 一

嗯,本来是想写一下Android Q的启动流程的,后来发现Android 原生代码里面已经有相关的文档了。

这时引用一下Android原生代码里面的启动流程说明:(相关的文档在system/core/init/README.md中)

Early Init Boot Sequence

————————

The early init boot sequence is broken up into three stages: first stage init, SELinux setup, and

second stage init.

First stage init is responsible for setting up the bare minimum requirements to load the rest of the

system. Specifically this includes mounting /dev, /proc, mounting ‘early mount’ partitions (which

needs to include all partitions that contain system code, for example system and vendor), and moving

the system.img mount to / for devices with a ramdisk.

Note that in Android Q, system.img always contains TARGET_ROOT_OUT and always is mounted at / by the

time first stage init finishes. Android Q will also require dynamic partitions and therefore will

require using a ramdisk to boot Android. The recovery ramdisk can be used to boot to Android instead

of a dedicated ramdisk as well.

First stage init has three variations depending on the device configuration:

1) For system-as-root devices, first stage init is part of /system/bin/init and a symlink at /init

points to /system/bin/init for backwards compatibility. These devices do not need to do anything to

mount system.img, since it is by definition already mounted as the rootfs by the kernel.

2) For devices with a ramdisk, first stage init is a static executable located at /init. These

devices mount system.img as /system then perform a switch root operation to move the mount at

/system to /. The contents of the ramdisk are freed after mounting has completed.

3) For devices that use recovery as a ramdisk, first stage init it contained within the shared init

located at /init within the recovery ramdisk. These devices first switch root to

/first_stage_ramdisk to remove the recovery components from the environment, then proceed the same

as 2). Note that the decision to boot normally into Android instead of booting

into recovery mode is made if androidboot.force_normal_boot=1 is present in the

kernel commandline.

Once first stage init finishes it execs /system/bin/init with the “selinux_setup” argument. This

phase is where SELinux is optionally compiled and loaded onto the system. selinux.cpp contains more

information on the specifics of this process.

Lastly once that phase finishes, it execs /system/bin/init again with the “second_stage”

argument. At this point the main phase of init runs and continues the boot process via the init.rc

scripts.

嗯,主要分三个阶段:

1。first stage

2。selinux

3。second stage

 

  • 为什要使用NanoPi-Neo

众多优点:

1。 便宜,不到一百块人民币

2。支持Usb boot:可以通过Usb接口将bootloader, kernel 写入到设备,直接在内存中运行,便于早期开发调试

3。有个Usb接口支持 otg模式,可以通过Usb接口与Adb进行通信,是这Raspberry Pi 3 Model B / B+不具备的

4。linux kernel主干都支持,拿来就可以直接编译运行,不需要修改一行代码

5。相关linux kernel驱动及dts代码很清晰,容易理解

 

这里,当然是用它来跑跑Android Q native的代码: kernel, init, adb, logcat, netd等,搞一个很简单的,可运行的Android系统。

  • Kernel

这里不再使用Allwinner官方的kernel了,而使用Android代码中的kernel(kernel/common), 取自分支

origin/android-4.19-q, commit id为:

commit 01a3fc70b510b1d1fa0eac60b7fe515f8993d406
Merge: 5b01d52 1a05924
Author: Greg Kroah-Hartman <gregkh@google.com>
Date:   Wed Jul 3 13:20:47 2019 +0200

    Merge 4.19.57 into android-4.19-q
    
    Changes in 4.19.57
        perf ui helpline: Use strlcpy() as a shorter form of strncpy() + explicit set nul

所使用的配置文件为:

  • Android Q代码

这里会使用到android-q-preview-4的代码。

  • 文件目录结构
Android-Q
+-- bionic
...
+-- device
|   `-- brobwind
|       `-- nenopi
+-- kernel-common
|   `-- arch
|       `-- arm
|           +-- config
|           |   `-- sunxi_defconfig
|           `-- boot
|               +-- dts
|               |   `-- sun8i-h3-nanopi-neo.dtb
|               `-- zImage
+-- nanopi-neo
|   +-- boot
|   |   +-- boot.cmd
|   |   +-- boot.scr
|   |   `-- run.sh
|   +-- sunxi-tools
|   |   `-- sunxi-fel
|   `-- u-boot
|       +-- u-boot-sunxi-with-spl.bin
|       `-- tools
|           `-- mkimage
...
`-- system
    `-- core
        `-- init

u-boot 及sunxi-tools的编译参考这篇:

Others: 由FriendlyElec出品的NanoPi NEO

 

 

 

 

 

 

《Others: Android Q on NanoPi Neo – bootloader & kernel 一》有2个想法

  1. 非常不错。

    作为国内另外一家开源硬件厂商,我们想送一块我们的ROCK Pi 4 给博主,微信联系 hipboi 或者 tom # radxa.com.

发表评论

电子邮件地址不会被公开。 必填项已用*标注