系统版本:Ubuntu18.04-64
编译器版本:gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)
uboot版本:2018.07 -linux4sam_6.0
板子型号:at91sama5d3x-xplained
MCU型号:sama5d36
1、uboot目录如下:
2、在configs/ 文件夹下面有官方的默认配置
# To put environment variables in nandflash (default):
sama5d3_xplained_nandflash_defconfig
# To put environment variables in SD/MMC card:
sama5d3_xplained_mmc_defconfig
编译 SAMA5D3-Xplained board:
选择nandflash启动
make sama5d3_xplained_nandflash_defconfig
make
3、官网下载的uboot,基本可以跑起来,通过串口可以看到打印的信息,DDR2和NAND Flash驱动可能没有问题,可以正常使用,厂家自己设计的网络驱动,LED 驱动根据型号做适配及裁剪;
编译出的文件u-boot.bin烧录进去,可以看到串口打印的信息
U-Boot 2018.07-linux4sam_6.0 (Oct 11 2019 - 23:57:20 -0700)
CPU: SAMA5D36
Crystal frequency: 12 MHz
CPU clock : 528 MHz
Master clock : 132 MHz
DRAM: 256 MiB
NAND: 256 MiB
MMC: Atmel mci: 0, Atmel mci: 1
Loading Environment from NAND... OK
In: serial@ffffee00
Out: serial@ffffee00
Err: serial@ffffee00
Netjack: macb_eth_probe phy-mode=mii,devname=ethernet@f0028000
eth0: ethernet@f0028000 [PRIME]macb_eth_probe phy-mode=rmii,devname=ethernet@f802c000
, eth1: ethernet@f802c000
Hit any key to stop autoboot: 0
=> pri
arch=arm
baudrate=115200
board=sama5d3_xplained
board_name=sama5d3_xplained
bootargs=console=ttyS0,115200 earlyprintk mtdparts=atmel_nand:256k(bootstrap)ro,768k(uboot)ro,256K(env_redundant),256k(env),512k(dtb),6M(kernel)ro,-(rootfs) rootfstype=ubifs ubi.mtd=6 root=ubi0:rootfs
bootcmd=tftp 0x21000000 at91-sama5d3_xplained.dtb;tftp 0x22000000 zImage;bootz 0x22000000 - 0x21000000
bootdelay=3
cpu=armv7
eth1addr=AA:AB:C1:D2:E6:C6
ethact=ethernet@f0028000
ethaddr=EE:AB:C1:D2:E6:C6
ethprime=ethernet@f0028000
fdtcontroladdr=2fb16b08
gatewayip=192.168.1.1
ipaddr=192.168.1.100
ipaddr1=192.168.2.100
netmask=255.255.255.0
serverip=192.168.1.108
soc=at91
stderr=serial@ffffee00
stdin=serial@ffffee00
stdout=serial@ffffee00
vendor=atmel
Environment size: 778/131067 bytes
=>
4、关键文件说明
scripts/config_whitelist.txt 全部的宏定义列表
SAMA5D3_XPLAINED BOARD
M: Bo Shen <voice.shen@atmel.com>
S: Maintained
F: board/atmel/sama5d3_xplained/sama5d3_xplained.c
F: include/configs/sama5d3_xplained.h
F: configs/sama5d3_xplained_mmc_defconfig
F: configs/sama5d3_xplained_nandflash_defconfig
arch/arm/mach-at91/spl_at91.c
arch/arm/mach-at91/include/mach/at91_common.h //公共函数声明头文件
sama5d3.h //CPU基地址
sama5_boot.h //启动方式
include/configs at91-sama5_common.h //CPU系列公共配置
5、裁剪的文件列表
//============================================
决定uboot编译配置的文件,编译选项宏定义在这个几个文件中查找
include/configs/at91-sama5_common.h
include/configs/sama5d3_xplained.h
configs/sama5d3_xplained_nandflash_defconfig
//
CONFIG_DM_ETH //支持设备树,网络配置从设备树里面读取
这版uboot中支持设备树功能,让uboot变得轻巧了,不再很臃肿和笨拙。
6、设备树修改,更改网络的MAC接口方式
arch/arm/dts
Makefile
dtb-$(CONFIG_TARGET_SAMA5D3_XPLAINED) += \
at91-sama5d3_xplained.dtb
macb0: ethernet@f0028000 {
phy-mode = "mii"; //更改PHY的接口方式
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
ethernet-phy@7 {
reg = <0x7>;
};
};
7、uboot既然是裸跑程序,肯定有个main函数;先从main函数入手,查看如何进行外设初始化,GPIO、网卡等;
void board_init_r(gd_t *new_gd, ulong dest_addr)
{
/*
* Set up the new global data pointer. So far only x86 does this
* here.
* TODO(sjg@chromium.org): Consider doing this for all archs, or
* dropping the new_gd parameter.
*/
#if CONFIG_IS_ENABLED(X86_64)
arch_setup_gd(new_gd);
#endif
#ifdef CONFIG_NEEDS_MANUAL_RELOC
int i;
#endif
#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
gd = new_gd;
#endif
gd->flags &= ~GD_FLG_LOG_READY;
#ifdef CONFIG_NEEDS_MANUAL_RELOC
for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
init_sequence_r[i] += gd->reloc_off;
#endif
//所有的初始化都靠这个数组
if (initcall_run_list(init_sequence_r))
hang();
/* NOTREACHED - run_main_loop() does not return */
hang();
}
//在结构体中顺序执行函数
//在结构体中顺序执行函数
//摘抄部分代码,数组中有很多设备,进行初始化
static init_fnc_t init_sequence_r[] = {
/* PPC has a udelay(20) here dating from 2002. Why? */
#ifdef CONFIG_CMD_NET
initr_ethaddr,// 网络设备信息初始化
#endif
#ifdef CONFIG_CMD_NET
INIT_FUNC_WATCHDOG_RESET
initr_net, //初始化网络设备,uboot打印读取到的网卡信息
#endif
PHY的初始化流程
eth_initialize();//网络设备第一级初始化
eth_common_init();//网络设备第二级初始化
miiphy_init();//网络设备第三级初始化
phy_init();//
phy_davicom_init();//网络设备第四级初始化
phy_micrel_ksz8xxx_init();//
MDIO mii MAC+PHY=网卡芯片,前5个寄存器所有PHY芯片是相同的;
8、设置板级硬件时钟配置
arch/arm/mach-at91/spl_atmel.c
void board_init_f(ulong dummy)
{
int ret;
switch_to_main_crystal_osc();
#ifdef CONFIG_SAMA5D2
configure_2nd_sram_as_l2_cache();
#endif
#if !defined(CONFIG_AT91SAM9_WATCHDOG)
/* disable watchdog */
at91_disable_wdt();
#endif
/* PMC configuration */
at91_pmc_init();
at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
matrix_init();
redirect_int_from_saic_to_aic();
timer_init();
board_early_init_f();
mem_init();
ret = spl_init();
if (ret) {
debug("spl_init() failed: %d\n", ret);
hang();
}
preloader_console_init();
}
9、CPU相关设置
arch/arm/cpu/armv7
10、板级信息
board/atmel/sama5d3_xplained/sama5d3_xplained.c
int board_init(void)
{
/* adress of boot parameters */
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
#ifdef CONFIG_NAND_ATMEL
sama5d3_xplained_nand_hw_init();//Nand Flash初始化
#endif
#ifdef CONFIG_CMD_USB
sama5d3_xplained_usb_hw_init();//USB初始化
#endif
#ifdef CONFIG_GENERIC_ATMEL_MCI
sama5d3_xplained_mci0_hw_init();//EMMC初始化
#endif
return 0;
}
11、PHY 9031的RESET脚使用CPU控制,PHY 8081的电源和RESET使用CPU控制,为保证时序,系统上电后,优先给PHY芯片的RST脚拉高;
uboot下面控制GPIO的操作
board/atmel/sama5d3_xplained/sama5d3_xplained.c
添加代码
tatic void sama5d3_xplained_phy_hw_init(void)
{
//GPIO寄存器配置,输出内部上拉功能;
at91_set_pio_periph(AT91_PIO_PORTE, 9, 1); /* GPIO output up*/
at91_set_pio_periph(AT91_PIO_PORTC, 18, 1); /* GPIO output up*/
at91_set_pio_periph(AT91_PIO_PORTC, 31, 1); /* GPIO output up*/
at91_set_pio_periph(AT91_PIO_PORTB, 12, 1); /* LED GPIO output up*/
//输出对应的电平
at91_set_pio_output(AT91_PIO_PORTE, 9, 1); //micrel ksz9031 reset gpio
at91_set_pio_output(AT91_PIO_PORTC, 18, 0); //micrel ksz8081 power gpio
at91_set_pio_output(AT91_PIO_PORTC, 31, 1); //micrel ksz8081 reset gpio
at91_set_pio_output(AT91_PIO_PORTB, 12, 0); //Board led on
}
int board_init(void)
{
/* adress of boot parameters */
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
#ifdef CONFIG_NAND_ATMEL
sama5d3_xplained_nand_hw_init();
#endif
#ifdef CONFIG_CMD_USB
sama5d3_xplained_usb_hw_init();
#endif
#ifdef CONFIG_GENERIC_ATMEL_MCI
sama5d3_xplained_mci0_hw_init();
#endif
// add by for Jack phy init gpio
//把GPIO初始化函数添加到开发板的初始化函数中调用
sama5d3_xplained_phy_hw_init();
return 0;
}
12、官网uboot下载链接为:
https://www.linux4sam.org/bin/view/Linux4SAM/U-Boot
关注微信公众号,回复“空片烧录”,免费下载烧录教程文档。