核心板带有V3S SoC一颗,内置64MByte DDR RAM,MX25L25645G Flash一颗,EPHY已经连接,但是没有sunxi-fel配置,Flash也没有MISO开关。
从头开始创建这个核心板的image。
开发环境
开发环境如上图。使用核心板的DEBUG接口和以太网口,通过USB-UART小板接到上位机的USB口,网线和小交换机接好。上位机运行ubuntu 18.04 x64,创建了一个基于tftpd的TFTP服务器,使用VSCode做源代码编辑。
连好以后,确认各部分连接无误,开始搞起吧。
编译u-boot
u-boot版本
下载u-boot 2017.01-rc2。建立一个文件夹
.../v3s/
然后将u-boot-2017-01-rc2.tar.gz解压到
.../v3s/u-boot
目录下。
设置u-boot默认环境变量
按照 “SPI Flash 系统编译 - Sipeed Wiki” 设置好启动环境变量,感谢Sipeed Wiki的详细描述。
Flash分区在CONFIG_BOOTARGS中,这个设置不能错,要和内核的分区表准确对应才能顺利启动内核。
设置u-boot支持ethernet
因为我的板子没有sunxi-fel接口,因此必须在u-boot中使用带有网络支持的功能,才能使用tftp进行image的下载。参考网上大侠的做法,先修改源码如下。
修改 .../v3s/u-boot/arch/arm/dts/sun8i-v3s-licheepi-zero.dts
修改后的代码粘贴如下。
/*
* Copyright (C) 2016 Icenowy Zheng <icenowy@aosc.xyz>
*
......
......
*/
/dts-v1/;
#include "sun8i-v3s.dtsi"
#include "sunxi-common-regulators.dtsi"
/ {
model = "Lichee Pi Zero";
compatible = "licheepi,licheepi-zero", "allwinner,sun8i-v3s";
aliases {
serial0 = &uart0;
spi0 = &spi0;
/*
For network support to use TFTP
Commented by Luoyuan@2023-05-30
*/
ethernet0 = &emac;
};
chosen {
stdout-path = "serial0:115200n8";
};
};
&mmc0 {
pinctrl-0 = <&mmc0_pins_a>;
pinctrl-names = "default";
broken-cd;
bus-width = <4>;
vmmc-supply = <®_vcc3v3>;
status = "okay";
};
/*
For SPI-NOR-FLASH support
Commented by Luoyuan@2023-05-29
*/
&spi0 {
status = "okay";
};
&uart0 {
pinctrl-0 = <&uart0_pins_a>;
pinctrl-names = "default";
status = "okay";
};
&usb_otg {
dr_mode = "otg";
status = "okay";
};
&usbphy {
usb0_id_det-gpio = <&pio 5 6 GPIO_ACTIVE_HIGH>;
status = "okay";
};
&ohci0 {
dr_mode = "host";
status = "okay";
};
&ehci0 {
dr_mode = "host";
status = "okay";
};
/*
For network file transfer support using TFTP to download
flash image.
Commented by Luoyuan@2023-05-26
*/
&emac {
phy = <&phy0>;
phy-mode = "mii";
allwinner,use-internal-phy;
allwinner,leds-active-low;
status = "okay";
phy0: ethernet-phy@0 {
reg = <1>;
};
};
请注意我所作的几项注释:
ethernet0 = &emac
这里为emac表述段起了个别名”ethernet0“,为了将来在其它文件中进行引用。
&spi0
这里添加了对spi接口的描述,仅有一个标识:status=“okay”。
&emac
这个是关键,emac是ethnernet0的引用主体。
修改 .../v3s/arch/arm/dts/sun8i-v3s.dts
dts分层级描述设备/端口。找到soc的pio段,在uart0_pins_a: uart@0 {} 之前加入emac_rgmii_pins的描述代码,如下所示。
soc {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
ranges;
...
...
...
pio: pinctrl@01c20800 {
compatible = "allwinner,sun8i-v3s-pinctrl";
reg = <0x01c20800 0x400>;
interrupts = <GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_PIO>, <&osc24M>, <&osc32k>;
clock-names = "apb", "hosc", "losc";
gpio-controller;
#gpio-cells = <3>;
interrupt-controller;
#interrupt-cells = <3>;
/*
Ethernet support in u-boot
Commented by Luoyuan@2023-05-29
*/
emac_rgmii_pins: emac0@0 {
allwinner,pins = "PD0", "PD1", "PD2", "PD3",
"PD4", "PD5", "PD7",
"PD8", "PD9", "PD10",
"PD12", "PD13", "PD15",
"PD16", "PD17";
allwinner,function = "emac";
allwinner,drive = <SUN4I_PINCTRL_40_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
uart0_pins_a: uart0@0 {
pins = "PB8", "PB9";
function = "uart0";
bias-pull-up;
};
...
...
...
};
}
make menuconfig
在ubuntu命令行,cd .../v3s/u-boot,运行如下命令。
make LicheePi_Zero_defconfig
make ARCH=arm menuconfig
在menuconfig中,设置对SPI-NOR-Flash的支持和对ethernet的支持。
通用设置
Architecture select,不用说肯定是 ARM architecture。
ARM architecture部分,由LicheePi_Zero_defconfig指定了,注意图中红框内所选项就好,其它的的选项我没有修改。
delay in seconds before automatically booting,默认值为2,我改成了5,也就是说在启动过程中用户进入到u-boot前等待的秒数,改动的原因是默认等待2秒,有时会一闪而过。不改也是可以的。
SPL / TPL
这部分选项挺多的,就不截图了,确保如下选项为[*]。
[*] Enable SPL
[*] Support GPIO
[*] Suport common libraries
[*] Support disk partitions
[*] Support generic libraries
[*] Support MMC
[*] Support power drivers
[*] Support serial
[*] Support SPI flash drivers
Networking support
这个选项中,选中[*] Control TFTP timeout and count through environment。
Device Drivers
选中SPI Flash Support,如下图进行设置,请注意,选中的可以更多,但至少一定要包含图中所选的。
其中SPI flash Bank/Extended address register support是对超过16MByte的flash的支持,而MX25L25645G的容量是32MB,因此这个选项是必要的,否则的话,最大只能访问16MB的flash。
Macronix SPI flash support 和 Winbond SPI flash support 是必要的,这两个都选可以最大程度地兼容起来。
选中[*] Network device support ---> [*] Allwinner Sun8i Ethernet MAC support
选中[*] Serial drivers --->
[*] Require a serial port for console +
[*] Provide a serial driver +
[*] Provide a serial driver in SPL +
-*- NS 16550 UART or compatible
如下图所示。
选中SPI Support ---> [*] Enable Driver Model for SPI drivers + [*] Allwinner SPI driver
编译u-boot
使用make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
开始编译,如果一切顺利的话,就在当前目录下生成了一个名为
u-boot-sunxi-with-spl.bin
的文件,这就是我们需要的u-boot可执行文件。