Difference between revisions of "Template:S5P6818BuildFromSource/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
 
Line 35: Line 35:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===编译U-Boot===
+
===编译Linux kernel 4.4.y===
下载U-Boot源代码并编译,注意分支是nanopi2-lollipop-mr1:
+
====编译内核====
 +
* 下载内核源代码
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git clone https://github.com/friendlyarm/uboot_nanopi2.git
+
git clone https://github.com/friendlyarm/linux.git
cd uboot_nanopi2
+
cd linux
git checkout nanopi2-lollipop-mr1
+
git checkout nanopi2-v4.4.y
make s5p6818_nanopi3_config
+
make CROSS_COMPILE=arm-linux-
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
NanoPC-T2内核所属的分支是nanopi2-v4.4.y,在开始编译前先切换分支。
 +
* 编译Ubuntu内核
 +
<syntaxhighlight lang="bash">
 +
touch .scmversion
 +
make ARCH=arm64 nanopi3_linux_defconfig
 +
make ARCH=arm64
 +
</syntaxhighlight>
 +
编译成功结束后,新生成的内核是 arch/arm64/boot/Image,目录arch/arm64/boot/dts/nexell/下还包括新的DTB文件(s5p6818-nanopi3-rev*.dtb),用于替换掉SD卡boot分区下对应的文件。<br />
  
编译成功结束后您将获得u-boot.bin,您可以通过fastboot来更新正在运行的NanoPC-T3板上SD的U-Boot,方法如下:<br />
+
====如何使用新编译的内核====
1) 在电脑上先用命令 sudo apt-get install android-tools-fastboot 安装 fastboot 工具;<br />
+
* 更新SD卡上的内核
2) 用串口配件连接NanoPC-T3和电脑,在上电启动的2秒内,在串口终端上按下回车,进入 u-boot 的命令行模式;<br />
+
如果您是使用SD卡启动Ubuntu系统,则在PC上复制编译生成的Image和DTB文件到SD卡的boot分区(即分区1,设备是/dev/sdX1)即可。
3) 在u-boot 命令行模式下输入命令 fastboot 回车,进入 fastboot 模式;<br />
+
 
4) 用microUSB线连接NanoPC-T3和电脑,在电脑上输入以下命令烧写u-boot.bin:<br />
+
* 更新eMMC上Ubuntu的内核
 +
从eMMC启动时可通过以下方法来更新内核:<br />
 +
1) 启动完成后,系统通常会自动mount eMMC的boot分区(设备是/dev/mmcblk0p1), 可输入命令mount来查看; <br />
 +
2) 连接网络,使用scp/ftp等方式复制新编译的Image和DTB文件并替换boot分区下的文件; <br />
 +
3) 也可以将编译好的内核复制到SD卡或U盘,然后在板止复制到boot分区下; <br />
 +
4) 更新完成后,输入 reboot 命令重启即可,注意不要直接断电或按Reset键,否则可能会损坏文件. <br />
 +
 
 +
* 使用新的内核来生成boot.img
 +
如果要生成直接烧写eMMC的文件,则需要使用新编译的内核来生成boot.img,然后复制到烧写用的SD卡即可直接烧写到eMMC. <br />
 +
对于Ubuntu, 则需要使用按以下方法来生成boot.img : <br />
 +
1) 下载debian_nanopi2
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
fastboot flash bootloader u-boot.bin
+
git clone https://github.com/friendlyarm/debian_nanopi2.git
 
</syntaxhighlight>
 
</syntaxhighlight>
<br />
+
2) 复制用于新的zImage和DTB文件到debian_nanopi2/boot/, ; <br />
注意:您不能直接使用dd来更新SD卡,否则有可能会导致无法正常启动。<br />
+
3) 生成Debian的 boot.img
 +
<syntaxhighlight lang="bash">
 +
cd debian_nanopi2
 +
mkdir rootfs
 +
./build.sh
 +
</syntaxhighlight>
 +
新的 boot.img 在 debian_nanopi2/sd-fuse_nanopi2/debian 下. <br />
 +
其中命令"mkdir rootfs"只是创建一个空的目录使得build.sh可以运行,因此生成的其它文件比如rootfs.img不能使用。
  
===准备mkimage===
+
====编译U-Boot====
 +
下载U-Boot v2016.01源代码并编译,注意分支是nanopi2-v2016.01
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/u-boot.git
 +
cd u-boot
 +
git checkout nanopi2-v2016.01
 +
make make s5p6818_nanopi3_defconfig
 +
make CROSS_COMPILE=aarch64-linux-
 +
</syntaxhighlight>
 +
编译成功结束后您将获得fip-nonsecure.img,可以通过fastboot、sd-fuse_s5p6818和eflasher ROM来更新板上的U-Boot v2016.01。<br />
 +
需要特别注意的是,不同版本的U-Boot不能交叉更新,不能使用fastboot更新现在运行的U-Boot v2014.07,也不能使用fip-nonsecure.img去替换一个ROM中的u-boot.bin,否则会导致系统无法正常启动。
 +
 
 +
===编译Linux kernel===
 +
====准备mkimage====
 
编译内核需要用到U-Boot中的工具mkimage,因此,在编译内核uImage前,您需要保证您的主机环境可以成功运行它。<br />
 
编译内核需要用到U-Boot中的工具mkimage,因此,在编译内核uImage前,您需要保证您的主机环境可以成功运行它。<br />
 
你可以直接使用命令 sudo apt-get install u-boot-tools 来安装,也可以自己编译并安装:
 
你可以直接使用命令 sudo apt-get install u-boot-tools 来安装,也可以自己编译并安装:
Line 65: Line 102:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===编译Linux kernel===
 
 
====编译内核====
 
====编译内核====
 
* 下载内核源代码
 
* 下载内核源代码
Line 105: Line 141:
 
         (0)  Display In  [0=Display 0, 1=Display 1]
 
         (0)  Display In  [0=Display 0, 1=Display 1]
 
               Resolution (1920 * 1080p)  --->
 
               Resolution (1920 * 1080p)  --->
make uImage
 
</syntaxhighlight>
 
* 编译Ubuntu Core内核
 
本部分的编译方法和编译Debian内核是相似的,只需要使用不同的2个内核配置即可。<br />
 
LCD 输出:
 
<syntaxhighlight lang="bash">
 
make nanopi3_core-qt_defconfig
 
</syntaxhighlight>
 
HDMI输出:
 
<syntaxhighlight lang="bash">
 
make nanopi3_core-qt_hdmi_defconfig
 
</syntaxhighlight>
 
选择自己需要的内核配置后,使用以下命令即可编译生成uImage。
 
<syntaxhighlight lang="bash">
 
touch .scmversion
 
 
make uImage
 
make uImage
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 182: Line 203:
 
其中 “/opt/FriendlyARM/s5p6818/android” 是指Android源代码的TOP目录,使用参数“-h”可查看帮助。<br />
 
其中 “/opt/FriendlyARM/s5p6818/android” 是指Android源代码的TOP目录,使用参数“-h”可查看帮助。<br />
 
编译成功结束后,会显示生成的内核模块。
 
编译成功结束后,会显示生成的内核模块。
 +
 +
====编译U-Boot====
 +
下载U-Boot源代码并编译,注意分支是nanopi2-lollipop-mr1:
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/friendlyarm/uboot_nanopi2.git
 +
cd uboot_nanopi2
 +
git checkout nanopi2-lollipop-mr1
 +
make s5p6818_nanopi3_config
 +
make CROSS_COMPILE=arm-linux-
 +
</syntaxhighlight>
 +
 +
编译成功结束后您将获得u-boot.bin,您可以通过fastboot来更新正在运行的NanoPC-T3板上SD的U-Boot,方法如下:<br />
 +
1) 在电脑上先用命令 sudo apt-get install android-tools-fastboot 安装 fastboot 工具;<br />
 +
2) 用串口配件连接NanoPC-T3和电脑,在上电启动的2秒内,在串口终端上按下回车,进入 u-boot 的命令行模式;<br />
 +
3) 在u-boot 命令行模式下输入命令 fastboot 回车,进入 fastboot 模式;<br />
 +
4) 用microUSB线连接NanoPC-T3和电脑,在电脑上输入以下命令烧写u-boot.bin:<br />
 +
<syntaxhighlight lang="bash">
 +
fastboot flash bootloader u-boot.bin
 +
</syntaxhighlight>
 +
<br />
 +
注意:您不能直接使用dd来更新SD卡,否则有可能会导致无法正常启动。<br />
  
 
===编译Android===
 
===编译Android===

Revision as of 06:29, 25 December 2017

1 如何编译系统

1.1 安装交叉编译器

首先下载并解压编译器:

git clone https://github.com/friendlyarm/prebuilts.git
sudo mkdir -p /opt/FriendlyARM/toolchain
sudo tar xf prebuilts/gcc-x64/arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz -C /opt/FriendlyARM/toolchain/

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

export PATH=/opt/FriendlyARM/toolchain/4.9.3/bin:$PATH
export GCC_COLORS=auto

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

. ~/.bashrc

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

arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/4.9.3/libexec/gcc/arm-cortexa9-linux-gnueabihf/4.9.3/lto-wrapper
Target: arm-cortexa9-linux-gnueabihf
Configured with: /work/toolchain/build/src/gcc-4.9.3/configure --build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=arm-cortexa9-linux-gnueabihf --prefix=/opt/FriendlyARM/toolchain/4.9.3
--with-sysroot=/opt/FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root --enable-languages=c,c++
--with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=vfpv3 --with-float=hard
...
Thread model: posix
gcc version 4.9.3 (ctng-1.21.0-229g-FA)

1.2 编译Linux kernel 4.4.y

1.2.1 编译内核

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

NanoPC-T2内核所属的分支是nanopi2-v4.4.y,在开始编译前先切换分支。

  • 编译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 如何使用新编译的内核

  • 更新SD卡上的内核

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

  • 更新eMMC上Ubuntu的内核

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

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

如果要生成直接烧写eMMC的文件,则需要使用新编译的内核来生成boot.img,然后复制到烧写用的SD卡即可直接烧写到eMMC.
对于Ubuntu, 则需要使用按以下方法来生成boot.img :
1) 下载debian_nanopi2

git clone https://github.com/friendlyarm/debian_nanopi2.git

2) 复制用于新的zImage和DTB文件到debian_nanopi2/boot/, ;
3) 生成Debian的 boot.img

cd debian_nanopi2
mkdir rootfs
./build.sh

新的 boot.img 在 debian_nanopi2/sd-fuse_nanopi2/debian 下.
其中命令"mkdir rootfs"只是创建一个空的目录使得build.sh可以运行,因此生成的其它文件比如rootfs.img不能使用。

1.2.3 编译U-Boot

下载U-Boot v2016.01源代码并编译,注意分支是nanopi2-v2016.01

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

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

1.3 编译Linux kernel

1.3.1 准备mkimage

编译内核需要用到U-Boot中的工具mkimage,因此,在编译内核uImage前,您需要保证您的主机环境可以成功运行它。
你可以直接使用命令 sudo apt-get install u-boot-tools 来安装,也可以自己编译并安装:

cd uboot_nanopi2
make CROSS_COMPILE=arm-linux- tools
sudo mkdir -p /usr/local/sbin && sudo cp -v tools/mkimage /usr/local/sbin

1.3.2 编译内核

  • 下载内核源代码
git clone https://github.com/friendlyarm/linux-3.4.y.git
cd linux-3.4.y
git checkout nanopi2-lollipop-mr1

NanoPC-T3内核所属的分支是nanopi2-lollipop-mr1,在开始编译前先切换分支。

  • 编译Android内核
make nanopi3_android_defconfig
touch .scmversion
make uImage
  • 编译Debian内核
make nanopi3_linux_defconfig
touch .scmversion
make uImage

编译成功结束后,新生成的内核烧写文件为 arch/arm/boot/uImage,此内核支持LCD输出,用于替换掉SD卡boot分区下的uImage。
如果要支持HDMI,则需要使用 nanopi3_linux_hdmi_defconfig, 具体如下:

make nanopi3_linux_hdmi_defconfig
touch .scmversion
make uImage

使用新的uImage 替换SD卡boot分区下的uImage.hdmi 即可支持HDMI 720p,如果要支持1080p,则需要修改内核配置:

touch .scmversion
make nanopi3_linux_hdmi_defconfig
make menuconfig
  Device Drivers -->
    Graphics support -->
      Nexell Graphics -->
        [ ] LCD
        [*] HDMI
        (0)   Display In  [0=Display 0, 1=Display 1]
              Resolution (1920 * 1080p)  --->
make uImage

1.3.3 如何使用新编译的内核

  • 更新SD卡上的内核

如果您是使用SD卡启动Android,则在PC上复制为Android编译的uImage到SD卡的boot分区(即分区1,设备是/dev/sdX1)即可。
如果您是使用SD卡启动Debian系统,则需要编译好用于HDMI的uImage后替换SD卡boot分区下的uImage.hdmi,然后编译用于LCD的uImage并替换SD卡boot分区下的uImage。

  • 更新eMMC上Android的内核

如果只想单独更新eMMC上的内核来测试,则需要先正常启动板,然后mount eMMC的boot分区,使用新编译的uImage来替换原有文件,完成后reboot即可。
从eMMC启动时可通过以下方法来更新内核:
1) 启动完成后,需要手动mount eMMC的boot分区(设备是/dev/mmcblk0p1), 可通过串口在板上操作:

su
mount -t ext4 /dev/block/mmcblk0p1 /mnt/media_rw/sdcard1/

2) 连接USB,在PC端Ubuntu下使用adb push命令复制新编译的uImage到已mount的boot分区下;

adb push uImage /mnt/media_rw/sdcard1/

3) 也可以将编译好的内核复制到SD卡或U盘,然后在板上复制到boot分区下;
4) 更新完成后,输入 reboot 命令重启即可,注意不要直接断电或按Reset键,否则可能会损坏文件。

  • 更新eMMC上Debian的内核

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

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

如果要生成直接烧写eMMC的文件,则需要使用新编译的内核来生成boot.img,然后复制到烧写用的SD卡即可直接烧写到eMMC.
对于Android,将新的uImage复制Android源码的device/friendly-arm/nanopi3/boot/ 下,然后编译Android即可获得新的boot.img .
对于Debian, 则需要使用按以下方法来生成boot.img :
1) 下载debian_nanopi2

git clone https://github.com/friendlyarm/debian_nanopi2.git

2) 复制用于HDMI的uImage到debian_nanopi2/boot/uImage.hdmi, 复制用于LCD的 uImage到debian_nanopi2/boot/uImage ;
3) 生成Debian的 boot.img

cd debian_nanopi2
mkdir rootfs
./build.sh

新的 boot.img 在 debian_nanopi2/sd-fuse_nanopi2/debian 下.
其中命令"mkdir rootfs"只是创建一个空的目录使得build.sh可以运行,因此生成的其它文件比如rootfs.img不能使用。

1.3.4 编译内核模块

Android包含内核模块,位于system分区的 /lib/modules/ 下,如果您有新的内核模块或者内核配置有变化,则需要重新编译。
首先编译内核源代码中的模块:

cd linux-3.4.y
make CROSS_COMPILE=arm-linux- modules

另外有2个内核模块的源代码位于Android源代码中,可使用以下命令来编译:

cd /opt/FriendlyARM/s5p6818/android
./vendor/friendly-arm/build/common/build-modules.sh

其中 “/opt/FriendlyARM/s5p6818/android” 是指Android源代码的TOP目录,使用参数“-h”可查看帮助。
编译成功结束后,会显示生成的内核模块。

1.3.5 编译U-Boot

下载U-Boot源代码并编译,注意分支是nanopi2-lollipop-mr1:

git clone https://github.com/friendlyarm/uboot_nanopi2.git
cd uboot_nanopi2
git checkout nanopi2-lollipop-mr1
make s5p6818_nanopi3_config
make CROSS_COMPILE=arm-linux-

编译成功结束后您将获得u-boot.bin,您可以通过fastboot来更新正在运行的NanoPC-T3板上SD的U-Boot,方法如下:
1) 在电脑上先用命令 sudo apt-get install android-tools-fastboot 安装 fastboot 工具;
2) 用串口配件连接NanoPC-T3和电脑,在上电启动的2秒内,在串口终端上按下回车,进入 u-boot 的命令行模式;
3) 在u-boot 命令行模式下输入命令 fastboot 回车,进入 fastboot 模式;
4) 用microUSB线连接NanoPC-T3和电脑,在电脑上输入以下命令烧写u-boot.bin:

fastboot flash bootloader u-boot.bin


注意:您不能直接使用dd来更新SD卡,否则有可能会导致无法正常启动。

1.4 编译Android

  • 搭建编译环境

搭建编译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 libncurses5-dev zlib1g-dev gawk minicom

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

  • 下载源代码

Android源代码的下载需要使用repo,其安装和使用请查看 https://source.android.com/source/downloading.html

mkdir android && cd android
repo init -u https://github.com/friendlyarm/android_manifest.git -b nanopi3-lollipop-mr1
repo sync

其中“android”是指工作目录。

  • 编译系统
source build/envsetup.sh
lunch aosp_nanopi3-userdebug
make -j8

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

filename partition Description
boot.img boot -
cache.img cache -
userdata.img userdata -
system.img system -
partmap.txt - 分区描述文件
  • 烧写到SD卡

如果是采用SD卡启动Android,可复制编译生成的image文件到sd-fuse_s5p6818/android/ 下,使用脚本即可烧到到SD卡,具体请查看#在Linux Desktop下通过脚本制作

  • 烧写到eMMC

成功编译Android后,可过2种方式烧写到eMMC,分别如下:
1) fastboot: 板子从eMMC启动后通过串口快速按任意键进入uboot命令行模式,输入命令fastboot即可启动此方式。
连接USB线,然后PC端输入以下命令:

cd out/target/product/nanopi3
sudo fastboot flash boot boot.img
sudo fastboot flash cache cache.img
sudo fastboot flash userdata userdata.img
sudo fastboot flash system system.img
sudo fastboot reboot

2) 使用SD卡烧写
复制out/target/product/nanopi3下的boot.img, cache.img, userdata.img, system.img, partmap.txt到烧写用SD卡的images/android下,再次烧写即可。