Difference between revisions of "APITestPage"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
 
(126 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[How to build FriendlyELEC FriendlyWRT|English]]
 
  
==FriendlyWRT简介==
+
{{RockchipUnbrick|NanoPC-T4}}
FriendlyWRT是友善电子基于OpenWrt定制的系统,完全开源,用于企业物联网二次开发,个人定制NAS,家庭物联网网关等。
+
TODO <br />
+
==下载体验版固件==
+
TODO <br />
+
解压后用 dd 或者 win32image 烧写到 SD 卡。
+
==帐户与密码==
+
用户名: root<br />
+
密码: fa<br />
+
<br />
+
==获取项目源代码==
+
===安装 repo 工具===
+
首先需要安装 repo 工具:
+
<syntaxhighlight lang="bash">
+
git clone https://github.com/friendlyarm/repo
+
cp repo/repo /usr/bin/
+
</syntaxhighlight>
+
===下载项目源代码===
+
有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:
+
====方法一:使用网盘里的repo压缩包====
+
网盘下载地址: [http://download.friendlyarm.com/{{#replace:{{#replace:{{BASEPAGENAME}}| |}}|/zh|}} 点击进入]<br />
+
文件位于网盘的以下路径:sources/friendlywrt-YYYYMMDD.tar (YYYYMMDD表示打包的日期)<br />
+
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作:
+
<syntaxhighlight lang="bash">
+
tar xvf /path/to/netdisk/sources/friendlywrt-YYYYMMDD.tar
+
cd friendlywrt
+
repo sync -l
+
</syntaxhighlight>
+
用此方法得到的源代码版本是repo打包时的版本,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync, 例如:
+
<syntaxhighlight lang="bash">
+
cd friendlywrt
+
repo sync
+
</syntaxhighlight>
+
====方法二:从github下载====
+
<syntaxhighlight lang="bash">
+
mkdir friendlywrt
+
cd friendlywrt
+
repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master -m h3.xml --repo-url=https://github.com/friendlyarm/repo
+
repo sync -c
+
</syntaxhighlight>
+
====同步项目到最新版本====
+
<syntaxhighlight lang="bash">
+
cd friendlywrt
+
repo sync -c
+
</syntaxhighlight>
+
同步过程中,由于网络原因出现中断,可以使用下面脚本同步代码:
+
<syntaxhighlight lang="bash">
+
#! /bin/bash
+
repo sync -c
+
while [ $? -ne 0 ];
+
do 
+
    repo sync -c
+
done
+
</syntaxhighlight>
+
 
+
==如何编译==
+
===搭建编译环境===
+
在PC的Ubuntu系统下 (建议使用版本18.04-64bit),执下以下命令安装所需的软件:
+
<syntaxhighlight lang="bash">
+
sudo apt-get install repo git-core gitk git-gui gcc-arm-linux-gnueabihf u-boot-tools device-tree-
+
compiler gcc-aarch64-linux-gnu mtools parted libudev-dev libusb-1.0-0-dev python-linaro-image-
+
tools linaro-image-tools autoconf autotools-dev libsigsegv2 m4 intltool libdrm-dev curl sed make
+
binutils build-essential gcc g++ bash patch gzip bzip2 perl tar cpio python unzip rsync file bc wget
+
libncurses5 libqt4-dev libglib2.0-dev libgtk2.0-dev libglade2-dev cvs git mercurial rsync openssh-
+
client subversion asciidoc w3m dblatex graphviz python-matplotlib libc6:i386 libssl-dev texinfo
+
liblz4-tool genext2fs lib32stdc++6 swig python-dev python3-dev exfat-fuse exfat-utils
+
</syntaxhighlight>
+
 
+
===查看帮助===
+
不带参数执行 build.sh,默认是打印帮助信息:
+
<syntaxhighlight lang="bash">
+
./build.sh
+
</syntaxhighlight>
+
显示的帮助信息如下:
+
<syntaxhighlight lang="bash">
+
USAGE: ./build.sh <parameter>
+
 
+
# 选择目标的硬件平台:
+
  ./build.sh friendlyelec_h3_series.mk
+
 
+
# 编译各个模块:
+
  ./build.sh all                -编译所有组件
+
  ./build.sh uboot              -单独编译uboot
+
  ./build.sh kernel            -单独编译kernel
+
  ./build.sh friendlywrt        -单独编译friendlywrt
+
  ./build.sh sd-img            -生成sd启动的镜像文件
+
  ./build.sh emmc-img          -生成用于安装到emmc的镜像文件 (镜像文件需要dd到sd卡,通过sd卡启动安装程序)
+
# 清理:
+
  ./build.sh cleanall
+
</syntaxhighlight>
+
===全自动方式编译===
+
初次编译,需要选择目标的硬件平台,当前只有H3可用,后续会加入更多的硬件支持:
+
<syntaxhighlight lang="bash">
+
./build.sh friendlyelec_h3_series.mk
+
</syntaxhighlight>
+
执行上述命令,会自动编译所有组件,其中包括u-boot, kernel 和 friendlywrt,并生成sd启动的烧写镜像文件。
+
===编译单独的模块===
+
====kernel====
+
<syntaxhighlight lang="bash">
+
./build.sh kernel
+
</syntaxhighlight>
+
====u-boot====
+
<syntaxhighlight lang="bash">
+
./build.sh uboot
+
</syntaxhighlight>
+
====friendlywrt====
+
<syntaxhighlight lang="bash">
+
./build.sh friendlywrt
+
</syntaxhighlight>
+
===生成sdcard固件===
+
<syntaxhighlight lang="bash">
+
sudo ./build.sh sd-img
+
</syntaxhighlight>
+
打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:<br />
+
<syntaxhighlight lang="bash">
+
Run the following for sdcard install:
+
    sudo dd if=out/h3-sd-friendlywrt-4.14-armhf-20190807.img bs=1M of=/dev/sdX
+
</syntaxhighlight>
+
===生成emmc (eflasher) 固件===
+
<syntaxhighlight lang="bash">
+
sudo ./build.sh emmc-img
+
</syntaxhighlight>
+
打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:<br />
+
<syntaxhighlight lang="bash">
+
Run the following for sdcard install:
+
    sudo dd if=out/h3-eflasher-friendlywrt-4.14-armhf-20190807.img bs=1M of=/dev/sdX
+
</syntaxhighlight>
+
用此sd卡启动eflasher系统,执行eflasher命令,将系统写入emmc,之后就可以拨掉sd卡,从emmc启动friendlywrt了。
+
==friendlywrt定制与开发==
+
===源代码目录结构===
+
<syntaxhighlight lang="bash">
+
├── friendlywrt
+
│  ├── friendlywrt -> friendlywrt源代码
+
|  └── configs -> 保存预设好的friendlywrt defconfig文件
+
│  ├── build.sh -> 全自动编译脚本
+
│  ├── device/friendlyelec -> 用于适配友善电子开发板的相关文件
+
│  ├── kernel -> 内核
+
│  └── u-boot -> u-boot
+
│  └── scripts -> 打包img的相关脚本
+
</syntaxhighlight>
+
===配置friendlywrt的软件包===
+
* 使用make menuconfig更改配置
+
<syntaxhighlight lang="bash">
+
cd friendlywrt
+
make menuconfig
+
</syntaxhighlight>
+
* 另存你个人的软件包配置
+
<syntaxhighlight lang="bash">
+
make menuconfig
+
./scripts/diffconfig.sh > ../configs/my_config
+
</syntaxhighlight>
+
* 让以后的编译使用你的friendlywrt配置
+
编辑以下文件:
+
<syntaxhighlight lang="bash">
+
device/friendlyelec/h3/friendlyelec_h3_series.mk
+
</syntaxhighlight>
+
将TARGET_FRIENDLYWRT_CONFIG的值改为你的配置。
+
* 重新编译friendlywrt并制成sd启动镜像
+
<syntaxhighlight lang="bash">
+
./build.sh friendlywrt
+
./build.sh sd-img
+
</syntaxhighlight>
+
===固化个人文件到friendlywrt===
+
将文件或目录放入以下目录即可,打包img时会把它们都打包进去:
+
<syntaxhighlight lang="bash">
+
device/friendlyelec/h3/common-files
+
</syntaxhighlight>
+
也可以放在新建的目录里,然后编辑以下文件:
+
<syntaxhighlight lang="bash">
+
device/friendlyelec/h3/friendlyelec_h3_series.mk
+
</syntaxhighlight>
+
在文件中新增一行 (XXX替换为你的目录名):
+
<syntaxhighlight lang="bash">
+
FRIENDLYWRT_FILES+=(device/friendlyelec/h3/XXX)
+
</syntaxhighlight>
+
===修改friendlywrt系统的默认配置(如网络、防火墙等)===
+
进入如下目录:
+
<syntaxhighlight lang="bash">
+
device/friendlyelec/h3/default-settings/files/root/board
+
</syntaxhighlight>
+
编辑你所用的开发板目录所在的配置文件即可,比如下面是NanoPi-R1的配置文件:
+
<syntaxhighlight lang="bash">
+
NanoPi-R1
+
└── etc
+
    └── config
+
        ├── network
+
        └── system
+
</syntaxhighlight>
+
===更改u-boot和kernel配置===
+
同样是编辑如下文件:
+
<syntaxhighlight lang="bash">
+
device/friendlyelec/h3/friendlyelec_h3_series.mk
+
</syntaxhighlight>
+
可通过以下设置,将uboot的配置改为你自已的:
+
<syntaxhighlight lang="bash">
+
TARGET_UBOOT_CONFIG=nanopi_h3_defconfig
+
</syntaxhighlight>
+
可通过以下设置,将kernel的配置改为你自已的:
+
<syntaxhighlight lang="bash">
+
TARGET_KERNEL_CONFIG=sunxi_defconfig
+
</syntaxhighlight>
+
===更换其他源代码===
+
编辑如下 xml 文件,即可替换 kernel 、uboot以及friendlywrt的源代码:
+
<syntaxhighlight lang="bash">
+
.repo/manifests/h3.xml
+
</syntaxhighlight>
+
想了解 xml 文件各个节点的含义和用法,请参考:[https://gerrit.googlesource.com/git-repo/+/refs/heads/master/docs/manifest-format.md repo Manifest Format]<br />
+
编辑完成后,需要用 repo 命令同步一下,比如更换了 kernel 的源代码,用以下命令同步一次:
+
<syntaxhighlight lang="bash">
+
repo sync --force-sync kernel
+
</syntaxhighlight>
+
同步后单独重新内核即可:
+
<syntaxhighlight lang="bash">
+
./build.sh kernel
+
</syntaxhighlight>
+
 
+
==参考资料==
+
[https://source.android.com/setup/develop/repo repo使用指南]<br />
+

Latest revision as of 09:23, 4 June 2024

1 Unbricking Method

If the ROM is not installed correctly, causing the development board to become bricked, and you might not have the opportunity to reinstall the ROM via an SD card, you need to enter Maskrom mode to unbrick it by erasing the storage device.

1.1 Windows Users

1.1.1 Download Required Files

  • Get the necessary tools: Visit here, find RKDevTool_v3.19_for_window.zip and DriverAssitant_v5.12.zip in the 05_Tools directory, and download them to your local machine.
  • Install Rockchip USB driver and RKDevTool: Extract DriverAssitant_v5.12.zip to install the Rockchip USB driver, and extract RKDevTool_v3.19_for_window.zip to obtain the Rockchip flashing tool RKDevTool.
  • Get the loader: Visit here, enter the tools directory corresponding to your CPU model, and download MiniLoaderAll.bin.

1.1.2 Enter Maskrom Mode to Erase the Storage Device

  • Connect NanoPC-T4 to your computer using a USB data cable.
  • Start RKDevTool on your computer.
  • Disconnect the power from NanoPC-T4, hold down the MASK button, connect the power, and release the button when you see Found One MASKROM Device displayed at the bottom of the interface, as shown below:

Rkdevtool found one maskrom device.png

  • Click the Advanced Function tab in the RKDevTool interface.
  • In the Boot text box, select MiniLoaderAll.bin, then click the Download button.
  • Select EMMC, click Switch Storage, then click the EraseAll button to erase the eMMC.

Rkdevtool erase emmc.png

  • At this point, NanoPC-T4 is restored to its initial state and can be normally booted via SD card or eMMC.

1.2 Linux/Mac Users

1.2.1 Download the Required Files

  • Get the necessary tools: Visit here and find upgrade_tool_v2.30_for_linux.tgz (or for Mac users, select upgrade_tool_v2.25_for_mac.tgz) in the 05_Tools directory and download it locally.
  • Get the loader: Visit here, enter the tools directory corresponding to your CPU model, and download MiniLoaderAll.bin.

1.2.2 Installation for upgrade_tool

The following commands are for Linux, with only slight differences in file and directory names for Mac users:

tar xzf upgrade_tool_v2.30_for_linux.tgz
cd upgrade_tool_v2.30_for_linux
sudo cp upgrade_tool /usr/local/sbin/
sudo chmod 755 /usr/local/sbin/upgrade_tool

1.2.3 Enter Maskrom Mode to Erase the Storage Device

  • Connect NanoPC-T4 to the computer using a USB data cable.
  • Disconnect the power from NanoPC-T4, hold down the MASK button, connect the power, and release the button after 4 seconds.
  • Check the connection with the following command:
upgrade_tool LD

A result similar to "DevNo=1 Vid=0x2207,Pid=0x350b,LocationID=13 Mode=Maskrom SerialNo=" indicates that the device has been detected.

  • Erase the eMMC with the following command:
upgrade_tool EF MiniLoaderAll.bin
  • At this point, NanoPC-T4 has been restored to its initial state and can boot the system normally via SD card or eMMC.