编译环境
- Ubuntu-18.04.1
- 16GB RAM
下载源码
目前所用的源码版本为H6-2018-1-2,大家可以到香橙派官网下载,顺便记录下这个源码编译所遇到的一些坑。
下载源码所得的目录
lemon@ubuntu:~/Develop/H6_Android_Source_Code$ ls
H6-2018-1-2.tar.gzaa H6-2018-1-2.tar.gzad H6-2018-1-2.tar.gzag H6-2018-1-2.tar.gzaj H6-2018-1-2.tar.gzam
H6-2018-1-2.tar.gzab H6-2018-1-2.tar.gzae H6-2018-1-2.tar.gzah H6-2018-1-2.tar.gzak H6-2018-1-2.tar.gzan
H6-2018-1-2.tar.gzac H6-2018-1-2.tar.gzaf H6-2018-1-2.tar.gzai H6-2018-1-2.tar.gzal
lemon@ubuntu:~/Develop/H6_Android_Source_Code$
将多个压缩文件合并成一个
lemon@ubuntu:~/Develop/H6_Android_Source_Code$ cat H6-2018-1-2.tar.gza* > OrangePi_Lite2.tar
lemon@ubuntu:~/Develop/H6_Android_Source_Code$ ls
H6-2018-1-2.tar.gzaa H6-2018-1-2.tar.gzad H6-2018-1-2.tar.gzag H6-2018-1-2.tar.gzaj H6-2018-1-2.tar.gzam
H6-2018-1-2.tar.gzab H6-2018-1-2.tar.gzae H6-2018-1-2.tar.gzah H6-2018-1-2.tar.gzak H6-2018-1-2.tar.gzan
H6-2018-1-2.tar.gzac H6-2018-1-2.tar.gzaf H6-2018-1-2.tar.gzai H6-2018-1-2.tar.gzal OrangePi_Lite2.tar
lemon@ubuntu:~/Develop/H6_Android_Source_Code$
解压出来,得到android和lichee目录,其中android是Android系统目录,lichee包含uboot、kernel等一些文件。
lemon@ubuntu:~/Develop/H6_Android_Source_Code$ tar xf OrangePi_Lite2.tar -C ../OrangePi_Lite2/
lemon@ubuntu:~/Develop/H6_Android_Source_Code$ cd ../OrangePi_Lite2/
lemon@ubuntu:~/Develop/OrangePi_Lite2$ ls
android lichee
lemon@ubuntu:~/Develop/OrangePi_Lite2$
安装Git方便代码管理,这个建议都使用git来进行代码管理,优点不说了,网上一大堆。
lemon@ubuntu:~/Develop/OrangePi_Lite2$ sudo apt-get install git
设置好Git的用户名和邮箱
创建仓库,加入源码的提交,作为First Commit,基础代码
lemon@ubuntu:~/Develop/OrangePi_Lite2$ git init
Initialized empty Git repository in /home/lemon/Develop/OrangePi_Lite2/.git/
lemon@ubuntu:~/Develop/OrangePi_Lite2$
lemon@ubuntu:~/Develop/OrangePi_Lite2$ ll
total 20
drwxr-xr-x 5 lemon lemon 4096 Sep 1 09:58 ./
drwxr-xr-x 4 lemon lemon 4096 Sep 1 09:23 ../
drwxr-xr-x 28 lemon lemon 4096 Nov 22 2017 android/
drwxr-xr-x 7 lemon lemon 4096 Sep 1 09:58 .git/
drwxr-xr-x 8 lemon lemon 4096 Nov 22 2017 lichee/
lemon@ubuntu:~/Develop/OrangePi_Lite2$
lemon@ubuntu:~/Develop/OrangePi_Lite2$ git add .
lemon@ubuntu:~/Develop/OrangePi_Lite2$ git commit -m "Init Code"
安装jdk环境,编译Android 7.0 的源码需要安装openjdk-8-jdk
lemon@ubuntu:~$ sudo apt-get install openjdk-8-jdk
lemon@ubuntu:~$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.18.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
lemon@ubuntu:~$
安装编译依赖
sudo apt-get install git gnupg flex bison gperf build-essential \
zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache \
libgl1-mesa-dev libxml2-utils xsltproc unzip
安装u-boot-tools工具
lemon@ubuntu:~$ sudo apt-get install u-boot-tools
编译内核源码:
lemon@ubuntu:~/Develop/OrangePi_Lite2/lichee$ ./build.sh config
Welcome to mkscript setup progress
All available chips:
0. sun50iw1p1
1. sun50iw2p1
2. sun50iw6p1
3. sun8iw11p1
4. sun8iw12p1
5. sun8iw6p1
6. sun8iw7p1
7. sun8iw8p1
8. sun9iw1p1
Choice: 2
All available platforms:
0. android
1. dragonboard
2. linux
3. eyeseelinux
Choice: 0
All available business:
0. 5.1
1. 4.4
2. 7.x
Choice: 2
LICHEE_BUSINESS=7.x
using kernel 'linux-3.10':
select arch by kernel version and chip
==================================
INFO: ----------------------------------------
INFO: build lichee ...
INFO: chip: sun50iw6p1
INFO: platform: android
INFO: business: 7.x
INFO: kernel: linux-3.10
INFO: arch: arm64
INFO: board:
INFO: output: out/sun50iw6p1/android/
INFO: ----------------------------------------
INFO: build buildroot ...
installing external toolchain
please wait for a few minutes ...
INFO: build buildroot OK.
INFO: build kernel ...
INFO: prepare toolchain ...
cat: /home/lemon/Develop/OrangePi_Lite2/lichee/linux-3.10/.config: No such file or directory
no file name,use gz
Building kernel
/home/lemon/Develop/OrangePi_Lite2/lichee/linux-3.10/output/lib/modules/3.10.65
Copy rootfs for arm64
Using default config sun50iw6p1smp_android_7.x_defconfig ...
第一次编译报错
output/lib/modules/3.10.65/dma-buf-test-exporter.ko'
make: Leaving directory '/home/lemon/Develop/OrangePi_Lite2/lichee/linux-3.10/modules/gpu'
[GPU]: mali-t720 device driver has been built.
regenerate rootfs cpio
15757 blocks
17099 blocks
awk: line 2: function strtonum never defined
awk: line 2: function strtonum never defined
ERROR: build kernel Failed
解决办法:
sudo apt-get install gawk
修改之后编译成功
make: Leaving directory '/home/lemon/Develop/OrangePi_Lite2/lichee/linux-3.10/modules/gpu'
[GPU]: mali-t720 device driver has been built.
regenerate rootfs cpio
15757 blocks
17099 blocks
build_ramfs
Copy boot.img to output directory ...
Copy modules to target ...
sun50iw6p1 compile Kernel successful
INFO: build kernel OK.
INFO: build rootfs ...
INFO: skip make rootfs for android
INFO: build rootfs OK.
----------------------------------------
build sun50iw6p1 android 7.x lichee OK
----------------------------------------
配置成功之后,下次可以直接在lichee目录下运行./build.sh将继续采用上一次的.config的配置,如果改动了,就需要重新选择。
编译u-boot
lemon@ubuntu:~/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07$ make distclean && make sun50iw6p1_config && make -j8
Makefile:1216: *** missing separator. Stop.
我擦编译又报错,查看发现编译脚本多了一行无用的脚本。
lemon@ubuntu:~/Develop/OrangePi_Lite2$ git diff lichee/brandy/u-boot-2014.07/Makefile
diff --git a/lichee/brandy/u-boot-2014.07/Makefile b/lichee/brandy/u-boot-2014.07/Makefile
index 295d766..b2cb3b2 100755
--- a/lichee/brandy/u-boot-2014.07/Makefile
+++ b/lichee/brandy/u-boot-2014.07/Makefile
@@ -1213,7 +1213,7 @@ TAG_SUBDIRS := $(u-boot-dirs) include $(SPLDIR)
FIND := find
FINDFLAGS := -L
--R --c++-kinds=+p --fields=+iaS --extra=+q
+#-R --c++-kinds=+p --fields=+iaS --extra=+q
tags ctags:
ctags -w -o ctags `$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) \
-name '*.[chS]' -print`
这里建议采用Notepad++打开.diff的后缀文件,修改哪里一目了然。
修改之后Uboot编译成功
LD examples/standalone/hello_world
OBJCOPY examples/standalone/hello_world.bin
OBJCOPY examples/standalone/hello_world.srec
LD u-boot
OBJCOPY u-boot.srec
OBJCOPY u-boot.bin
./tools/add_hash_uboot.sh -f u-boot.bin -m uboot
build_uboot
'u-boot.bin' -> 'u-boot-sun50iw6p1.bin'
'u-boot-sun50iw6p1.bin' -> '/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../tools/pack/chips/sun50iw6p1/bin/u-boot-sun50iw6p1.bin'
if [ -z "" ]; then \
cp -v u-boot-"sun50iw6p1".bin /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../tools/pack/chips/"sun50iw6p1"/bin/u-boot-"sun50iw6p1".bin; \
else \
cp -v u-boot-"sun50iw6p1".bin /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../tools/pack/chips/"sun50iw6p1"/bin/u-boot-"sun50iw6p1"-.bin; \
fi
'u-boot-sun50iw6p1.bin' -> '/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../tools/pack/chips/sun50iw6p1/bin/u-boot-sun50iw6p1.bin'
lemon@ubuntu:~/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07$
编译boot0
lemon@ubuntu:~/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07$ make distclean && make sun50iw6p1_config && make spl
/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../gcc-linaro/bin/arm-linux-gnueabi-gcc -E -include /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/include/u-boot/u-boot.lds.h -DSBROMSWADDR="(0x20A00)" -ansi -D__ASSEMBLY__ -P - </home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/main/sboot.lds >/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/sboot.lds
/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../gcc-linaro/bin/arm-linux-gnueabi-ld /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/dram/sun50iw6p1/dram/libchipid.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/dram/sun50iw6p1/dram/libdram.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/flash/libflash.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/keyladder/libkeyladder.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/libs/libgeneric.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/load/libload.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/main/libmain.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/openssl/libopenssl.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/spl/libsource_spl.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/spl/lib/libgeneric.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/arch/arm/cpu/armv7/sun50iw6p1/nand/libnand.o /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/arch/arm/cpu/armv7/sun50iw6p1/mmc/libmmc.o -L /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/gcc-linaro/bin/../lib/gcc/arm-linux-gnueabi/4.6.3 -lgcc -T/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/sboot.lds -o sboot.axf -Map sboot.map
/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../gcc-linaro/bin/arm-linux-gnueabi-objcopy -O binary /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/sboot.axf /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/sboot.bin
/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/../../tools/add_hash.sh -f /home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../bootloader/uboot_2014_sunxi_spl/sunxi_spl/sbrom/sboot.bin -m sboot
build_sboot
'sboot_sun50iw6p1.bin' -> '/home/lemon/Develop/OrangePi_Lite2/lichee/brandy/u-boot-2014.07/../../tools/pack/chips/sun50iw6p1/bin/sboot_sun50iw6p1.bin'
编译Android源码
lemon@ubuntu:~/Develop/OrangePi_Lite2/android$ source ./build/envsetup.sh
including device/asus/fugu/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips64/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/google/dragon/vendorsetup.sh
including device/htc/flounder/vendorsetup.sh
including device/huawei/angler/vendorsetup.sh
including device/lge/bullhead/vendorsetup.sh
including device/linaro/hikey/vendorsetup.sh
including device/moto/shamu/vendorsetup.sh
including device/softwinner/cheetah-cmcc-p1/vendorsetup.sh
including device/softwinner/cheetah-p1/vendorsetup.sh
including device/softwinner/common/vendorsetup.sh
including device/softwinner/petrel-cmcc-p1/vendorsetup.sh
including device/softwinner/petrel-p1/vendorsetup.sh
including sdk/bash_completion/adb.bash
lemon@ubuntu:~/Develop/OrangePi_Lite2/android$ lunch petrel_fvd_p1-eng
/bin/bash: python: command not found
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.0
TARGET_PRODUCT=petrel_fvd_p1
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a7
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=NRD91N
OUT_DIR=out
============================================
lemon@ubuntu:~/Develop/OrangePi_Lite2/android$ extract-bsp
/bin/bash: python: command not found
/home/lemon/Develop/OrangePi_Lite2/android/device/*/petrel-p1/bImage copied!
/home/lemon/Develop/OrangePi_Lite2/android/device/*/petrel-p1/modules copied!
安装python
lemon@ubuntu:~/Develop/OrangePi_Lite2/android/device$ sudo apt-get install python
安装python之后执行命令正常
lemon@ubuntu:~/Develop/OrangePi_Lite2/android$ extract-bsp
/home/lemon/Develop/OrangePi_Lite2/android/device/*/petrel-p1/bImage copied!
/home/lemon/Develop/OrangePi_Lite2/android/device/*/petrel-p1/modules copied!
继续执行make进行编译
lemon@ubuntu:~/Develop/OrangePi_Lite2/android$ make -j8 && pack
[ 0% 364/39294] host Java: antlr-runtime (out/host/common/obj/JAVA_LIBRARIES/antlr-runtime_intermediates/classes)
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
[ 1% 591/39294] Lex: libaidl-common <= system/tools/aidl/aidl_language_l.ll
FAILED: /bin/bash -c "prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/host/linux-x86/obj/STATIC_LIBRARIES/libaidl-common_intermediates/aidl_language_l.cpp system/tools/aidl/aidl_language_l.ll"
flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
Aborted (core dumped)
[ 1% 591/39294] host Java: guavalib (out/host/common/obj/JAVA_LIBRARIES/guavalib_intermediates/classes)
warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
[ 1% 591/39294] target Java: core-all (out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/classes)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
ninja: build stopped: subcommand failed.
build/core/ninja.mk:148: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1
#### make failed to build some targets (01:45 (mm:ss)) ####
又报错。。。百度了下,这是Ubuntu 18.04的锅,需要编译之前执行export LC_ALL=C
export LC_ALL=C
最终踩过了这么多坑,终于编译成功
usbtool.fex Len: 0x23600
aultools.fex Len: 0x2847b
aultls32.fex Len: 0x24d23
cardtool.fex Len: 0x11e00
cardscript.fex Len: 0x779
sunxi_mbr.fex Len: 0x10000
dlinfo.fex Len: 0x4000
arisc.fex Len: 0x6
bootloader.fex Len: 0x7d7400
Vbootloader.fex Len: 0x4
env.fex Len: 0x20000
Venv.fex Len: 0x4
boot.fex Len: 0x106d800
Vboot.fex Len: 0x4
system.fex Len: 0x259c2a74
Vsystem.fex Len: 0x4
verity_block.fex Len: 0x1045b4
Vverity_block.fex Len: 0x4
recovery.fex Len: 0x12cd000
Vrecovery.fex Len: 0x4
sysrecovery.fex Len: 0xb
diskfs.fex Len: 0x200
BuildImg 0
Dragon execute image.cfg SUCCESS !
----------image is at----------
/home/lemon/Develop/OrangePi_Lite2/lichee/tools/pack/sun50iw6p1_android_petrel-p1_uart0.img
pack finish