Difference between revisions of "Template:S5P6818BuildFromSource/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(如何使用新编译的内核)
(updated by API)
 
(8 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
首先下载并解压编译器:
 
首先下载并解压编译器:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/prebuilts.git
+
git clone https://github.com/friendlyarm/prebuilts.git -b master --depth 1
sudo mkdir -p /opt/FriendlyARM/toolchain
+
cd prebuilts/gcc-x64
sudo tar xf prebuilts/gcc-x64/aarch64-cortexa53-linux-gnu-6.4.tar.xz -C /opt/FriendlyARM/toolchain/
+
cat toolchain-6.4-aarch64.tar.gz* | sudo tar xz -C /
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 36: Line 36:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===编译Linux kernel 4.4.y===
+
===编译 FriendlyCore/Lubuntu/EFlasher的内核源代码 ===
 
====编译内核====
 
====编译内核====
 
* 下载内核源代码
 
* 下载内核源代码
Line 52: Line 52:
 
编译成功结束后,新生成的内核是 arch/arm64/boot/Image,目录arch/arm64/boot/dts/nexell/下还包括新的DTB文件(s5p6818-nanopi3-rev*.dtb),用于替换掉SD卡boot分区下对应的文件。<br />
 
编译成功结束后,新生成的内核是 arch/arm64/boot/Image,目录arch/arm64/boot/dts/nexell/下还包括新的DTB文件(s5p6818-nanopi3-rev*.dtb),用于替换掉SD卡boot分区下对应的文件。<br />
  
====如何使用新编译的内核====
+
====Linux下使用新编译的内核====
 
* 更新SD卡上的内核
 
* 更新SD卡上的内核
 
如果您是使用SD卡启动Ubuntu系统,则在PC上复制编译生成的Image和DTB文件到SD卡的boot分区(即分区1,设备通常是/dev/sdX1)即可。
 
如果您是使用SD卡启动Ubuntu系统,则在PC上复制编译生成的Image和DTB文件到SD卡的boot分区(即分区1,设备通常是/dev/sdX1)即可。
  
* 更新eMMC上Ubuntu的内核
+
* 更新eMMC系统上的内核
 
从eMMC启动时可通过以下方法来更新内核:<br />
 
从eMMC启动时可通过以下方法来更新内核:<br />
 
1) 启动完成后,系统通常会自动mount eMMC的boot分区(设备是/dev/mmcblk0p1), 可输入命令mount来查看; <br />
 
1) 启动完成后,系统通常会自动mount eMMC的boot分区(设备是/dev/mmcblk0p1), 可输入命令mount来查看; <br />
 
2) 连接网络,使用scp/ftp等方式复制新编译的Image和DTB文件并替换boot分区下的文件; <br />
 
2) 连接网络,使用scp/ftp等方式复制新编译的Image和DTB文件并替换boot分区下的文件; <br />
3) 也可以将编译好的内核复制到SD卡或U盘,然后在板止复制到boot分区下; <br />
+
3) 也可以将编译好的内核复制到SD卡或U盘,然后到开发板上复制到boot分区下; <br />
 
4) 更新完成后,输入 reboot 命令重启即可,注意不要直接断电或按Reset键,否则可能会损坏文件. <br />
 
4) 更新完成后,输入 reboot 命令重启即可,注意不要直接断电或按Reset键,否则可能会损坏文件. <br />
  
 
* 使用新的内核来生成boot.img
 
* 使用新的内核来生成boot.img
如果要生成直接烧写eMMC的文件,则需要使用新编译的内核来生成boot.img,然后复制到烧写用的SD卡即可直接烧写到eMMC. <br />
+
请参考这个git仓库: https://github.com/friendlyarm/sd-fuse_s5p6818<br />
对于Ubuntu, 则需要使用按以下方法来生成boot.img : <br />
+
 
1) 下载debian_nanopi2
+
===编译Android7的内核源代码 ===
 +
Android 7.1.2源代码已包含预先编译好的内核,如果需要进行定制,可根据以下方法编译内核。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/debian_nanopi2.git
+
git clone https://github.com/friendlyarm/linux.git -b nanopi2-v4.4.y --depth 1
 +
cd linux
 +
touch .scmversion
 +
make ARCH=arm64 nanopi3_nougat_defconfig
 +
make ARCH=arm64
 
</syntaxhighlight>
 
</syntaxhighlight>
2) 复制用于新的Image和DTB文件到debian_nanopi2/boot/, ; <br />
+
编译成功结束后,新生成的内核是 arch/arm64/boot/Image,目录arch/arm64/boot/dts/nexell/下还包括新的DTB文件(s5p6818-nanopi3-rev*.dtb)。
3) 生成Debian的 boot.img
+
如果只想调试内核,可通过 adb 来快速更新。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd debian_nanopi2
+
adb root; adb shell mkdir /storage/sdcard1/; adb shell mount -t ext4 /dev/block/mmcblk0p1 /storage/sdcard1/;
mkdir rootfs
+
adb push arch/arm64/boot/Image arch/arm64/boot/dts/nexell/s5p6818-nanopi3-rev*.dtb /storage/sdcard1/
./build.sh
+
 
</syntaxhighlight>
 
</syntaxhighlight>
新的 boot.img 在 debian_nanopi2/sd-fuse_nanopi2/debian 下. <br />
+
内核开发/调试完成后,如果想生成用于烧写的boot.img,可复制内核Image和DTB文件到Android7源代码目录 device/friendlyelec/nanopi3/boot,然后开始编译Android7。
其中命令"mkdir rootfs"只是创建一个空的目录使得build.sh可以运行,因此生成的其它文件比如rootfs.img不能使用。
+
  
====编译U-Boot====
+
===编译 Android7/FriendlyCore/Lubuntu/EFlasher的U-Boot源代码 ===
 
下载U-Boot v2016.01源代码并编译,分支是nanopi2-v2016.01,与S5P4418相同。
 
下载U-Boot v2016.01源代码并编译,分支是nanopi2-v2016.01,与S5P4418相同。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 86: Line 89:
 
cd u-boot
 
cd u-boot
 
git checkout nanopi2-v2016.01
 
git checkout nanopi2-v2016.01
make s5p6818_nanopi3_defconfig
+
make s5p6818_nanopi3_config
 
make CROSS_COMPILE=aarch64-linux-
 
make CROSS_COMPILE=aarch64-linux-
 
</syntaxhighlight>
 
</syntaxhighlight>
编译成功结束后您将获得fip-nonsecure.img,可以通过fastboot、sd-fuse_s5p6818和eflasher ROM来更新板上的U-Boot v2016.01。<br />
+
编译成功结束后您将获得fip-nonsecure.img,可以通过fastboot、sd-fuse_s5p6818和eflasher来更新板上的U-Boot v2016.01。<br />
 +
For Android7: 可复制fip-nonsecure.img到Android7源代码目录 device/friendlyelec/nanopi3/boot,然后重新编译Android7。<br />
 
需要特别注意的是,不同版本的U-Boot不能交叉更新,不能使用fastboot更新现在运行的U-Boot v2014.07,也不能使用fip-nonsecure.img去替换一个ROM中的u-boot.bin,否则会导致系统无法正常启动。
 
需要特别注意的是,不同版本的U-Boot不能交叉更新,不能使用fastboot更新现在运行的U-Boot v2014.07,也不能使用fip-nonsecure.img去替换一个ROM中的u-boot.bin,否则会导致系统无法正常启动。
  
Line 103: Line 107:
 
更多说明可查看 https://source.android.com/source/initializing.html; <br />
 
更多说明可查看 https://source.android.com/source/initializing.html; <br />
  
====下载Android7.1.2源代码====
+
====下载Android7源代码====
 +
有以下两种途径获取 Android7 的源代码,都需要联网:
 +
* '''使用网盘里的git repo压缩包'''
 +
网盘下载地址: [http://download.friendlyelec.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} 点击进入]<br />
 +
文件位于网盘的以下路径:sources/s5pxx18-android-7.git-YYYYMMDD.tar (YYYYMMDD表示打包的日期)<br />
 +
从网盘中获取的压缩包在解压之后,需要执行一下 sync.sh 脚本,会从gitlab上拉取最新的代码:
 +
<syntaxhighlight lang="bash">
 +
tar xvf /path/to/netdisk/sources/s5pxx18-android-7.git-YYYYMMDD.tar
 +
cd s5pxx18-android-7
 +
./sync.sh
 +
</syntaxhighlight>
 +
* '''直接克隆git仓库'''
 
{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:
 
{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://gitlab.com/friendlyelec/s5pxx18-android-7.git --depth 1 -b master
+
git clone https://gitlab.com/friendlyelec/s5pxx18-android-7.git -b master
 
</syntaxhighlight>
 
</syntaxhighlight>
 
由于Android7源代码较大(约8.2GB),下载可能需要较长时间且容易受网络环境的影响而中断,请耐心等待并重试。
 
由于Android7源代码较大(约8.2GB),下载可能需要较长时间且容易受网络环境的影响而中断,请耐心等待并重试。
  
====编译Android7内核====
+
====开始编译====
Android 7.1.2源代码已包含预先编译好的内核,如果需要进行定制,可根据以下方法编译内核。
+
<syntaxhighlight lang="bash">
+
git clone https://github.com/friendlyarm/linux.git -b nanopi2-v4.4.y --depth 1
+
cd linux
+
touch .scmversion
+
make ARCH=arm64 nanopi3_nougat_defconfig
+
make ARCH=arm64
+
</syntaxhighlight>
+
编译成功结束后,新生成的内核是 arch/arm64/boot/Image,目录arch/arm64/boot/dts/nexell/下还包括新的DTB文件(s5p6818-nanopi3-rev*.dtb)。
+
如果只想调试内核,可通过 adb 来快速更新。
+
<syntaxhighlight lang="bash">
+
adb root; adb shell mkdir /storage/sdcard1/; adb shell mount -t ext4 /dev/block/mmcblk0p1 /storage/sdcard1/;
+
adb push arch/arm64/boot/Image arch/arm64/boot/dts/nexell/s5p6818-nanopi3-rev*.dtb /storage/sdcard1/
+
</syntaxhighlight>
+
内核开发/调试完成后,如果想生成用于烧写的boot.img,可复制内核Image和DTB文件到Android源代码目录 device/friendlyelec/nanopi3/boot,然后开始编译Android 7.1.2。
+
 
+
====编译Android====
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd s5pxx18-android-7
 
cd s5pxx18-android-7

Latest revision as of 01:56, 13 March 2023

1 如何编译系统

1.1 安装交叉编译器

1.1.1 安装aarch64-linux-gcc 6.4

首先下载并解压编译器:

git clone https://github.com/friendlyarm/prebuilts.git -b master --depth 1
cd prebuilts/gcc-x64
cat toolchain-6.4-aarch64.tar.gz* | sudo tar xz -C /

然后将编译器的路径加入到PATH中,用vi编辑vi ~/.bashrc,在末尾加入以下内容:

export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin:$PATH
export GCC_COLORS=auto

执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:

. ~/.bashrc

这个编译器是64位的,不能在32位的Linux系统上运行,安装完成后,你可以快速的验证是否安装成功:

aarch64-linux-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/6.4-aarch64/libexec/gcc/aarch64-cortexa53-linux-gnu/6.4.0/lto-wrapper
Target: aarch64-cortexa53-linux-gnu
Configured with: /work/toolchain/build/aarch64-cortexa53-linux-gnu/build/src/gcc/configure --build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=aarch64-cortexa53-linux-gnu --prefix=/opt/FriendlyARM/toolchain/6.4-aarch64
--with-sysroot=/opt/FriendlyARM/toolchain/6.4-aarch64/aarch64-cortexa53-linux-gnu/sysroot --enable-languages=c,c++
--enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-cpu=cortex-a53
...
Thread model: posix
gcc version 6.4.0 (ctng-1.23.0-150g-FA)

1.2 编译 FriendlyCore/Lubuntu/EFlasher的内核源代码

1.2.1 编译内核

  • 下载内核源代码
git clone https://github.com/friendlyarm/linux.git -b nanopi2-v4.4.y --depth 1
cd linux

S5P6818内核所属的分支是nanopi2-v4.4.y,与S5P4418相同,在开始编译前先切换分支。

  • 编译Ubuntu内核
touch .scmversion
make ARCH=arm64 nanopi3_linux_defconfig
make ARCH=arm64

编译成功结束后,新生成的内核是 arch/arm64/boot/Image,目录arch/arm64/boot/dts/nexell/下还包括新的DTB文件(s5p6818-nanopi3-rev*.dtb),用于替换掉SD卡boot分区下对应的文件。

1.2.2 Linux下使用新编译的内核

  • 更新SD卡上的内核

如果您是使用SD卡启动Ubuntu系统,则在PC上复制编译生成的Image和DTB文件到SD卡的boot分区(即分区1,设备通常是/dev/sdX1)即可。

  • 更新eMMC系统上的内核

从eMMC启动时可通过以下方法来更新内核:
1) 启动完成后,系统通常会自动mount eMMC的boot分区(设备是/dev/mmcblk0p1), 可输入命令mount来查看;
2) 连接网络,使用scp/ftp等方式复制新编译的Image和DTB文件并替换boot分区下的文件;
3) 也可以将编译好的内核复制到SD卡或U盘,然后到开发板上复制到boot分区下;
4) 更新完成后,输入 reboot 命令重启即可,注意不要直接断电或按Reset键,否则可能会损坏文件.

  • 使用新的内核来生成boot.img

请参考这个git仓库: https://github.com/friendlyarm/sd-fuse_s5p6818

1.3 编译Android7的内核源代码

Android 7.1.2源代码已包含预先编译好的内核,如果需要进行定制,可根据以下方法编译内核。

git clone https://github.com/friendlyarm/linux.git -b nanopi2-v4.4.y --depth 1
cd linux
touch .scmversion
make ARCH=arm64 nanopi3_nougat_defconfig
make ARCH=arm64

编译成功结束后,新生成的内核是 arch/arm64/boot/Image,目录arch/arm64/boot/dts/nexell/下还包括新的DTB文件(s5p6818-nanopi3-rev*.dtb)。 如果只想调试内核,可通过 adb 来快速更新。

adb root; adb shell mkdir /storage/sdcard1/; adb shell mount -t ext4 /dev/block/mmcblk0p1 /storage/sdcard1/;
adb push arch/arm64/boot/Image arch/arm64/boot/dts/nexell/s5p6818-nanopi3-rev*.dtb /storage/sdcard1/

内核开发/调试完成后,如果想生成用于烧写的boot.img,可复制内核Image和DTB文件到Android7源代码目录 device/friendlyelec/nanopi3/boot,然后开始编译Android7。

1.4 编译 Android7/FriendlyCore/Lubuntu/EFlasher的U-Boot源代码

下载U-Boot v2016.01源代码并编译,分支是nanopi2-v2016.01,与S5P4418相同。

git clone https://github.com/friendlyarm/u-boot.git 
cd u-boot
git checkout nanopi2-v2016.01
make s5p6818_nanopi3_config
make CROSS_COMPILE=aarch64-linux-

编译成功结束后您将获得fip-nonsecure.img,可以通过fastboot、sd-fuse_s5p6818和eflasher来更新板上的U-Boot v2016.01。
For Android7: 可复制fip-nonsecure.img到Android7源代码目录 device/friendlyelec/nanopi3/boot,然后重新编译Android7。
需要特别注意的是,不同版本的U-Boot不能交叉更新,不能使用fastboot更新现在运行的U-Boot v2014.07,也不能使用fip-nonsecure.img去替换一个ROM中的u-boot.bin,否则会导致系统无法正常启动。

1.5 编译Android7.1.2

1.5.1 搭建编译环境

搭建用于编译Android的环境,建议使用64位的Ubuntu 16.04,需要安装如下软件包:

sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zip
sudo apt-get install flex curl libncurses5-dev libssl-dev zlib1g-dev gawk minicom
sudo apt-get install openjdk-8-jdk
sudo apt-get install exfat-fuse exfat-utils device-tree-compiler liblz4-tool

更多说明可查看 https://source.android.com/source/initializing.html;

1.5.2 下载Android7源代码

有以下两种途径获取 Android7 的源代码,都需要联网:

  • 使用网盘里的git repo压缩包

网盘下载地址: 点击进入
文件位于网盘的以下路径:sources/s5pxx18-android-7.git-YYYYMMDD.tar (YYYYMMDD表示打包的日期)
从网盘中获取的压缩包在解压之后,需要执行一下 sync.sh 脚本,会从gitlab上拉取最新的代码:

tar xvf /path/to/netdisk/sources/s5pxx18-android-7.git-YYYYMMDD.tar
cd s5pxx18-android-7
./sync.sh
  • 直接克隆git仓库

{{{1}}} 源代码托管在 gitlab 上,使用以下命令进行下载:

git clone https://gitlab.com/friendlyelec/s5pxx18-android-7.git -b master

由于Android7源代码较大(约8.2GB),下载可能需要较长时间且容易受网络环境的影响而中断,请耐心等待并重试。

1.5.3 开始编译

cd s5pxx18-android-7
source build/envsetup.sh
lunch aosp_nanopi3-userdebug
make -j8

编译成功完成后,目录 out/target/product/nanopi3/ 下包含可用于烧写的image文件。

filename partition Description
bl1-mmcboot.bin raw boot firmware
fip-loader.img raw boot firmware
fip-secure.img raw boot firmware
fip-nonsecure.img raw uboot-v2016.01
env.conf - uboot环境变量,包含Android内核命令行参数
boot.img boot kernel Image, DTBs; logo; Android ramdisk
cache.img cache -
userdata.img userdata -
system.img system -
partmap.txt - 分区描述文件