[Linux bottom layer] U-boot compilation and transplantation

System version: Ubuntu 18 04-64

Compiler version: gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)

uboot version: July 2018 - linux4sam_ six

Board model: at91sama5d3x xplained

MCU model: sama5d36

1. The uboot directory is as follows:

2. There are official default configurations under the configurations / folder

   # To put environment variables in nandflash (default):
   sama5d3_xplained_nandflash_defconfig
   # To put environment variables in SD/MMC card:
   sama5d3_xplained_mmc_defconfig
 compile SAMA5D3-Xplained board:

Select nandflash to start
make sama5d3_xplained_nandflash_defconfig
make

3. The uboot downloaded from the official website can basically run. The printed information can be seen through the serial port. DDR2 and NAND Flash drivers may have no problems and can be used normally. The network driver designed by the manufacturer and LED driver are adapted and cut according to the model;

Compiled file u-boot Bin burning in, you can see the information printed by the serial port

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. Description of key documents

scripts/config_whitelist.txt list of all macro definitions

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 / / public function declaration header file

			sama5d3.h	//CPU base address

			sama5_boot.h	//Start mode

include/configs at91-sama5_ common. H / / common configuration of CPU series

5. Cropped file list

//============================================

Determine the file of uboot compilation configuration. The compilation option macro definition is found in these files

include/configs/at91-sama5_common.h

include/configs/sama5d3_xplained.h

configs/sama5d3_xplained_nandflash_defconfig

//

CONFIG_DM_ETH / / the device tree is supported. The network configuration is read from the device tree

This version of uboot supports the device tree function, which makes uboot lightweight and no longer bulky and clumsy.

6. Modify the device tree and change the MAC interface mode of the network

arch/arm/dts

Makefile

dtb-$(CONFIG_TARGET_SAMA5D3_XPLAINED) += \

	at91-sama5d3_xplained.dtb



			macb0: ethernet@f0028000 {

				phy-mode = "mii";	//Change the interface mode of PHY

				#address-cells = <1>;

				#size-cells = <0>;

				status = "okay";



				ethernet-phy@7 {

					reg = <0x7>;

				};

			};

7. Since uboot is a naked running program, there must be a main function; Start with the main function to see how to initialize peripherals, such as GPIO and network card;

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
//All initialization depends on this array


    if (initcall_run_list(init_sequence_r))
        hang();


    /* NOTREACHED - run_main_loop() does not return */
    hang();
}

//Execute functions sequentially in the structure

//Execute functions sequentially in the structure
//Extract part of the code. There are many devices in the array for initialization

static init_fnc_t init_sequence_r[] = {


/* PPC has a udelay(20) here dating from 2002. Why? */
#ifdef CONFIG_CMD_NET
    initr_ethaddr,// Network device information initialization     
#endif


#ifdef CONFIG_CMD_NET
    INIT_FUNC_WATCHDOG_RESET  
    initr_net,          //Initialize the network device and uboot print the read network card information
#endif

Initialization process of PHY
eth_initialize();// First level initialization of network equipment
eth_common_init();// Network device level 2 initialization
miiphy_init();// Third level initialization of network equipment
phy_init();//
phy_davicom_init();// Fourth level initialization of network equipment
phy_micrel_ksz8xxx_init();//
MDIO mii MAC+PHY = network card chip, all PHY chips in the first five registers are the same;

8. Set board level hardware clock configuration

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 related settings

arch/arm/cpu/armv7

10. Board level information

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 initialization
#endif
#ifdef CONFIG_CMD_USB
    sama5d3_xplained_usb_hw_init();//USB initialization
#endif
#ifdef CONFIG_GENERIC_ATMEL_MCI
    sama5d3_xplained_mci0_hw_init();//EMMC initialization
#endif

    return 0;
}

11. The RESET pin of PHY 9031 is controlled by CPU, and the power supply and RESET of PHY 8081 are controlled by CPU. In order to ensure timing, after the system is powered on, the RST pin of PHY chip is preferentially raised;

uboot controls the operation of GPIO

board/atmel/sama5d3_xplained/sama5d3_xplained.c

Add code

tatic void sama5d3_xplained_phy_hw_init(void)
{
    //GPIO register configuration, output internal pull-up function;
    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*/

        //Output corresponding level
    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
        //Middle note, add the GPIO initialization function to the initialization function of the development board.
    sama5d3_xplained_phy_hw_init();


    return 0;
}

12. The download link of uboot on the official website is:

https://www.linux4sam.org/bin/view/Linux4SAM/U-Boot
Pay attention to WeChat official account, reply to "empty film burn", download the burn tutorial document free of charge.

Tags: Linux ARM uboot

Posted by ld0121 on Sat, 16 Apr 2022 03:53:46 +0930