查看: 30787|回复: 7

Hikey 970 编译烧写 AOSP 9.0 (亲测整理)

[复制链接]

1

主题

2

回帖

17

积分

新手上路

Rank: 1

积分
17
发表于 2019-12-25 10:39:31 | 显示全部楼层 |阅读模式
本帖最后由 风火轮用户41363 于 2019-12-26 09:53 编辑

此资料为作者根据目前互联网上的一些博客文章,经过亲自动手实践、汇总并加以提炼而成,互联网上的资料有些写得不正确,也有一些遗漏,本文全面的总结了基于 AOSP android-9.0.0_r8 分支代码如何编译以及烧写到 Hikey 970 当中。

      文中的 $AOSP_ROOT 指代的是用户自身的 AOSP 9 源码目录。


1. 获取源码

1.1 获取 AOSP 源码

路径:$AOSP_ROOT

  1. $ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-9.0.0_r8 --no-repo-verify --repo-branch=stable
  2. $ git clone https://github.com/96boards-hikey/android-manifest.git -b hikey970_v1.0 .repo/local_manifests
  3. $ repo sync -j4
复制代码

手动修复点:

  1. $ cd $AOSP_ROOT/device/linaro/hikey

  2. $ git diff
  3. diff --git a/manifest.xml b/manifest.xml
  4. index fb88f0d..e15f51b 100644
  5. --- a/manifest.xml
  6. +++ b/manifest.xml
  7. @@ -62,4 +62,13 @@
  8.              <instance>default</instance>
  9.          </interface>
  10.      </hal>
  11. +    <hal format="hidl">
  12. +        <name>android.hardware.wifi.hostapd</name>
  13. +        <transport>hwbinder</transport>
  14. +        <version>1.0</version>
  15. +        <interface>
  16. +            <name>IHostapd</name>
  17. +            <instance>default</instance>
  18. +        </interface>
  19. +    </hal>
  20. </manifest>
  21. diff --git a/sepolicy/hostapd.te b/sepolicy/hostapd.te
  22. index 86b985a..78b135c 100644
  23. --- a/sepolicy/hostapd.te
  24. +++ b/sepolicy/hostapd.te
  25. @@ -1,11 +1,11 @@
  26. # TODO(b/36657258): Remove data_between_core_and_vendor_violators once
  27. # hostapd no longer directly accesses /data outside /data/vendor.
  28. -typeattribute hostapd data_between_core_and_vendor_violators;
  29. +#typeattribute hostapd data_between_core_and_vendor_violators;
  30. # hostapd can read and write WiFi related data and configuration.
  31. -allow hostapd wifi_data_file:file rw_file_perms;
  32. -r_dir_file(hostapd, wifi_data_file)
  33. +#allow hostapd wifi_data_file:file rw_file_perms;
  34. +#r_dir_file(hostapd, wifi_data_file)

  35. # hostapd wants to create the directory holding its control socket.
  36. -allow hostapd hostapd_socket:dir create_dir_perms;
  37. +#allow hostapd hostapd_socket:dir create_dir_perms;
  38. # hostapd needs to create, bind to, read, and write its control socket.
  39. -allow hostapd hostapd_socket:sock_file create_file_perms;
  40. +#allow hostapd hostapd_socket:sock_file create_file_perms;
复制代码


1.2 获取 bootloader 源码

路径:$AOSP_ROOT/bootloader

  1. $ sudo apt install uuid-dev build-essential
  2. $ sudo apt install libssl-dev
  3. $ git clone https://github.com/96boards-hikey/tools-images-hikey970.git
  4. $ git clone https://github.com/96boards-hikey/OpenPlatformPkg.git -b hikey970_v1.0
  5. $ git clone https://github.com/96boards-hikey/arm-trusted-firmware.git -b hikey970_v1.0
  6. $ git clone https://github.com/96boards-hikey/l-loader.git -b hikey970_v1.0
  7. $ git clone https://github.com/96boards-hikey/edk2.git -b hikey970_v1.0
  8. $ git clone https://github.com/96boards-hikey/uefi-tools.git -b hikey970_v1.0
  9. $
  10. $ cd edk2
  11. $ ln -sf ../OpenPlatformPkg
复制代码

手动修复点:

  1. $ cd $AOSP_ROOT/bootloader/l-loader

  2. $ git diff build_uefi.sh
  3. diff --git a/build_uefi.sh b/build_uefi.sh
  4. index 3449246..e7e957d 100755
  5. --- a/build_uefi.sh
  6. +++ b/build_uefi.sh
  7. @@ -43,7 +43,8 @@ case "${SELECT_GCC}" in
  8.         CROSS_COMPILE=aarch64-linux-gnu-
  9.         ;;
  10. "LINARO_GCC_7_1")
  11. -       AARCH64_GCC_7_1=/opt/toolchain/gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu/bin/
  12. +       # AARCH64_GCC_7_1=/opt/toolchain/gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu/bin/
  13. +        AARCH64_GCC_7_1=/home/hand/workspace/aosp/bootloader/gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu/bin/
  14.         PATH=${AARCH64_GCC_7_1}:${PATH} && export PATH
  15.         export AARCH64_TOOLCHAIN=GCC5
  16.         CROSS_COMPILE=aarch64-linux-gnu-
复制代码


linaro-gcc 获取:

  1. $ wget https://releases.linaro.org/components/toolchain/binaries/7.1-2017.08/aarch64-linux-gnu/gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu.tar.xz
复制代码

1.3 获取 kernel 源码

原生的 kernel 不能 boot 这个版本的 AOSP,会导致各种问题,建议重新 clone linaro 官方针对 hikey970 的 kernel 源码。

路径:$AOSP/kernel

  1. $ cd $AOSP_ROOT/kernel
  2. $ git clone https://github.com/96boards-hikey/linux.git -b hikey970-v4.9 linux
复制代码


2. 编译镜像

2.1 编译 bootloader

命令:

  1. $ $AOSP_ROOT/bootloader/l-loader/build_uefi.sh hikey970
复制代码

生成物:

$AOSP_ROOT/bootloader/l-loader/ptable-aosp-64g.img

$AOSP_ROOT/bootloader/tools-images-hikey970/sec_xloader.img

$AOSP_ROOT/bootloader/l-loader/l-loader.bin

$AOSP_ROOT/bootloader/l-loader/fip.bin


2.2 编译 kernel

命令:

  1. $ cd $AOSP_ROOT/kernel/linux
  2. $ export ARCH=arm64
  3. $ export CROSS_COMPILE=$AOSP_ROOT/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
  4. $ make hikey970_defconfig && make -j4 Image.gz modules
  5. $ make hisilicon/kirin970-hikey970.dtb
复制代码

生成物:

$AOSP_ROOT/kernel/linux/arch/arm64/boot/dts/hisilicon/kirin970-hikey970.dts

$AOSP_ROOT/kernel/linux/arch/arm64/boot/Image.gz-dtb

复制到 AOSP 的对应目录

  1. $ cp $AOSP_ROOT/kernel/linux/arch/arm64/boot/dts/hisilicon/kirin970-hikey970.dtb $AOSP_ROOT/device/linaro/hikey-kernel/kirin970-hikey970.dtb-4.9
  2. $ cp $AOSP_ROOT/kernel/linux/arch/arm64/boot/Image.gz $AOSP_ROOT/device/linaro/hikey-kernel/Image.gz-hikey970-4.9
复制代码

2.3 编译 AOSP

命令:
  1. $ cd $AOSP_ROOT
  2. $ . build/envsetup.sh
  3. $ lunch hikey970-userdebug
  4. $ make -j4
复制代码

生成物:

$AOSP_ROOT/out/target/product/hikey970/boot.img // 这个 boot.img 是通过预编译的 kernel 镜像制作的,并非我们通过源码编译生成的 kernel 镜像,所以不能用

$AOSP_ROOT/out/target/product/hikey970/system.img

$AOSP_ROOT/out/target/product/hikey970/cache.img

$AOSP_ROOT/out/target/product/hikey970/userdata.img

$AOSP_ROOT/out/target/product/hikey970/dt.img


2.4 手动制作 boot.img
这一步建议放到 编译 AOSP 之后执行
  1. $ cd $AOSP_ROOT
  2. $ cp $AOSP_ROOT/out/target/product/hikey970/ramdisk.img $AOSP/ramdisk.img
  3. $ cat $AOSP_ROOT/kernel/linux/arch/arm64/boot/Image $AOSP_ROOT/kernel/linux/arch/arm64/boot/dts/hisilicon/kirin970-hikey970.dtb > $AOSP_ROOT/Image-dtb
  4. $ $AOSP_ROOT/out/host/linux-x86/bin/mkbootimg --kernel Image-dtb --ramdisk ramdisk.img --cmdline "androidboot.hardware=hikey970 firmware_class.path=/system/etc/firmware loglevel=15 buildvariant=userdebug androidboot.selinux=permissive clk_ignore_unused=true initrd=0xBE19D000,0x16677F earlycon=pl011,0xfff32000,115200 console=ttyAMA6 androidboot.serialno=54DA9CD5022525E4 clk_ignore_unused=true" -o boot.img
  5. $ cp $AOSP_ROOT/boot.img $AOSP_ROOT/out/target/product/hikey970/boot_built.img
复制代码


3
. 烧写

首先通过 Hikey970 跳线 引脚 1,3 拉高;引脚 2,4 拉低进入 fastboot 模式,然后运行(注意中间有两次必要的 reboot):
  1. $ cd $AOSP_ROOT/bootloader
  2. $ fastboot flash ptable l-loader/ptable-aosp-64g.img
  3. $ fastboot reboot
  4. $ fastboot flash xloader tools-images-hikey970/sec_xloader.img
  5. $ fastboot flash fip l-loader/fip.bin
  6. $ fastboot flash fastboot l-loader/l-loader.bin
  7. $ fastboot reboot
  8. $ cd $AOSP_ROOT/out/target/product/hikey970
  9. $ fastboot flash boot boot_built.img // 注意这里不要烧写原生 boot.img
  10. $ fastboot flash cache cache.img
  11. $ fastboot flash system system.img
  12. $ fastboot flash userdata userdata.img
复制代码
然后恢复跳线至引脚 1 拉高;引脚 2,3,4 拉低,重新上电正常开机,不出意外,此时 Hikey970 可以正常 boot 到 Android Launcher 了。


4. 已知问题和解决方法

4.1 WIFI 无法使用

原因是源码中默认的 wpa_supplicant 配置文件缺失,将附件中的 wifi.tar 通过 adb 推送到 /data/misc/ 下,解压缩覆盖 wifi 目录重启系统即可。如果下次重新 flash 过了 userdata 分区,这个步骤还要重新做一遍。


4.2 蓝牙无法搜索设备

logcat 日志中显示 bluetooth 服务出现 crash,原因是 BT 协议栈的 OSI 模块检测内核支持的 BOOT_ALARM 能力时出错,因为 Hikey970 不支持睡眠唤醒。修改方法:

文件:$AOSP_ROOT/system/bt/osi/src/alarm.cc

  1. --- a/system/bt/osi/src/alarm.cc
  2. +++ b/system/bt/osi/src/alarm.cc
  3. @@ -115,11 +115,11 @@ struct alarm_t {
  4. int64_t TIMER_INTERVAL_FOR_WAKELOCK_IN_MS = 3000;
  5. static const clockid_t CLOCK_ID = CLOCK_BOOTTIME;

  6. -#if (KERNEL_MISSING_CLOCK_BOOTTIME_ALARM == TRUE)
  7. +//#if (KERNEL_MISSING_CLOCK_BOOTTIME_ALARM == TRUE)
  8. static const clockid_t CLOCK_ID_ALARM = CLOCK_BOOTTIME;
  9. -#else
  10. -static const clockid_t CLOCK_ID_ALARM = CLOCK_BOOTTIME_ALARM;
  11. -#endif
  12. +//#else
  13. +//static const clockid_t CLOCK_ID_ALARM = CLOCK_BOOTTIME_ALARM;
  14. +//#endif
复制代码

4.3 有时候重新烧写 Hikey970 之后开机停在 boot animation 画面

一个可能的原因是 data 分区损坏,或者在错误的 fastboot 下进行了烧写。将 Hikey970 跳线 1,3拉高,2,4拉低,重新上电之后重新烧写 bootloader,并且在 ptable 以及 fastboot (l-loader)烧写完成之后重新上电,随后烧写 boot.img,system.img,userdata.img 恢复。


附件
WIFI 配置目录,下载并覆盖到 /data/misc/wifi
























https://irext.net
回复

使用道具 举报

0

主题

2

回帖

16

积分

新手上路

Rank: 1

积分
16
发表于 2019-12-28 00:03:19 | 显示全部楼层
覆盖配置了,wifi还是没有搞定呢
回复 支持 反对

使用道具 举报

1

主题

2

回帖

17

积分

新手上路

Rank: 1

积分
17
 楼主| 发表于 2019-12-28 08:50:12 来自手机 | 显示全部楼层
WiFi覆盖之后要去Setting里手动开启的,开启的时候会运行 wpa_supplicant,它会去这个目录里找配置文件。
回复 支持 反对

使用道具 举报

404

主题

246

回帖

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
20409
发表于 2020-3-23 17:12:26 | 显示全部楼层
感谢分享

风火轮微信公众号
回复

使用道具 举报

0

主题

1

回帖

4

积分

新手上路

Rank: 1

积分
4
发表于 2020-3-31 10:11:39 来自手机 | 显示全部楼层
linaro-gcc  具体怎么配置的
回复 支持 反对

使用道具 举报

1

主题

2

回帖

17

积分

新手上路

Rank: 1

积分
17
 楼主| 发表于 2020-4-5 12:55:31 | 显示全部楼层
风火轮用户20640 发表于 2020-3-31 10:11
linaro-gcc  具体怎么配置的

下载 linaro gcc 的 package,解压缩,然后编译的时候把 CROSS_COMPILE 指向它的目录就行了。
https://irext.net
回复 支持 反对

使用道具 举报

0

主题

2

回帖

10

积分

新手上路

Rank: 1

积分
10
发表于 2021-4-22 10:28:26 | 显示全部楼层
楼主,请问需要升级kernel到比较新的版本,从原生kernel中升级可行吗?步骤是什么呢
回复 支持 反对

使用道具 举报

0

主题

1

回帖

206

积分

中级会员

Rank: 3Rank: 3

积分
206
发表于 2023-11-24 16:31:24 | 显示全部楼层
楼主,请问开发板是在哪里购买呢?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|风火轮WIKI|手机版|小黑屋|深圳风火轮团队 ( 粤ICP备17095099号 )

GMT+8, 2024-5-9 02:21 , Processed in 0.063728 second(s), 19 queries .

快速回复 返回顶部 返回列表
 
【客服1】 商务合作 15289193
【客服2】 业务洽谈 13257599
【客服3】 售前咨询 510313198
【邮箱】
smartfire@smartfire.cn