加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AM335x U-Boot User's Guide

发布时间:2020-12-15 18:48:16 所属栏目:百科 来源:网络整理
导读:AM335x U-Boot User's Guide Linux PSP This work is licensed under a ? Creative Commons Attribution-ShareAlike 3.0 Unported License. Contents ? [hide] 1 ? U-Boot 1.1 ? Two stage U-Boot design 1.2 ? Building U-Boot 1.2.1 ? Commands 1.3 ? Seri
AM335x U-Boot User's Guide
Linux PSP

This work is licensed under a?Creative Commons Attribution-ShareAlike 3.0 Unported License.

Contents

? [hide]
  • 1?U-Boot
    • 1.1?Two stage U-Boot design
    • 1.2?Building U-Boot
      • 1.2.1?Commands
    • 1.3?Serial port configuration
    • 1.4?Boot Switch Settings
      • 1.4.1?NAND
      • 1.4.2?SPI
      • 1.4.3?UART
      • 1.4.4?SD
    • 1.5?Flashing U-Boot with CCS
    • 1.6?Flashing U-Boot without CCS
      • 1.6.1?UART-Flash Method
      • 1.6.2?SD-Flash-Method
  • 2?Boot Modes
    • 2.1?NAND
      • 2.1.1?Overview
      • 2.1.2?NAND Layout
      • 2.1.3?Writing to Nand
      • 2.1.4?Reading from Nand
      • 2.1.5?Marking a bad block
      • 2.1.6?Viewing bad blocks
      • 2.1.7?Erasing Nand
      • 2.1.8?NAND ECC algorithm selection
      • 2.1.9?BCH Flash OOB Layout
      • 2.1.10?ECC schemes usage table
      • 2.1.11?Flashing Linux Kernel from U-Boot
      • 2.1.12?UBIFS file system flashing
        • 2.1.12.1?UBIFS file system flashing from U-Boot
        • 2.1.12.2?UBIFS file system flashing from Linux
    • 2.2?NOR
    • 2.3?SPI
    • 2.4?UART
      • 2.4.1?Boot Over UART
      • 2.4.2?Flashing images to NAND in UART boot mode
        • 2.4.2.1?Flashing SPL to NAND from U-Boot in UART boot mode
        • 2.4.2.2?Flashing U-Boot to NAND from U-Boot in UART boot mode
    • 2.5?SD (Secured Digital card)
      • 2.5.1?Overview
      • 2.5.2?Read and execute application from SD card
      • 2.5.3?Setting Up Boot Environment on SD Card
      • 2.5.4?Boot using SD card
      • 2.5.5?Flashing images to NAND in SD boot
        • 2.5.5.1?Flashing SPL to NAND from U-Boot in SD boot
        • 2.5.5.2?Flashing U-Boot to NAND from U-Boot in SD boot
      • 2.5.6?ENV on SD card using uEnv.txt
      • 2.5.7?Making use pre-existing uEnv on SD card
    • 2.6?U-Boot Network configuration
    • 2.7?U-Boot Environment Variables
      • 2.7.1?Environment Settings for Ramdisk
      • 2.7.2?Environment Settings for UBIFS Filesystem
      • 2.7.3?Environment Settings for NFS Filesystem
    • 2.8?Booting the kernel

U-Boot

In AM335x the ROM code serves as the 1st stage bootloader. The 2nd and the 3rd stage bootloaders are based on?U-Boot.?In the rest of this document when referring to the binaries,the binary for the 2nd stage is referred to as SPL and the binary for the 3rd stage as simply U-Boot.?SPL is a non-interactive loader and is a specially built version of U-Boot. It is built concurrently when building U-Boot.

The ROM code can load the SPL image from any of the following devices

在AM335X的只读存储器的程序提供第一个阶段的引导,而第二个阶段和第三个阶段的引导程序必须是在U-Boot上面,在本文的其余部分,当提及到二进制文件的时候,第二个阶段的二进制文件是与spl相关的,而第三个阶段的二进制文件就是雨U-boot相关。SPL是一个没有相关性的加载器和一个特定版本的U-Boot。它协调得的编译当编译U-Boot的时候。

Memory devices non XIP (NAND/SDMMC)

The image should have the Image header. The image header is of length 8 byte which has the load address(Entry point) and the size of the image to be copied. RBL would copy the image,whose size is given by the length field in the image header,from the device and loads into the internal memory address specified in the load address field of Image header.

  • Peripheral devices (UART)

RBL loads the image to the internal memory address 0x402f0400 and executes it. No Image Header present.

Two stage U-Boot design

This section gives an overview of the two stage U-Boot approach adopted for AM335X.

The size of the internal RAM in AM335X is 128KB out of which 18KB at the end is used by the ROM code. Also,1 KB at the start (0x402f0000 - 0x402f0400) is secure and it cannot be accessed This places a limit of 109KB on the size of the U-Boot binary which the ROM code can transfer to the internal RAM and use as an initial stack before initialization of DRAM.

Since it is not possible to squeeze in all the functionality that is normally expected from U-Boot in < 110KB (after setting aside some space for stack,heap etc) a two stage approach has been adopted. Initial stage initalize only the required boot devices (NAND,MMC,I@C etc)& 2nd full stage initall all other devices (ethernet,timers,clocks etc). The 1st binary is generated MLO and the 2nd stage is generated as u-boot.img.

由于,它没有必要压榨在所有的机能,平常得期望U-Boot是控制在110KB(通过节省一些堆栈的空间),所以两个阶段的方式就被采取了。在初始化阶段,初始化的仅仅是一个需要启动的设备,如NAND,MMC,I2C 等等,在全部阶段将初始化所有的其他设备包括网络,定时器,时钟等等。第一个阶段产生MLO而第二个阶段产生U-BOOT.IMG

Note

  • When using memory boot (NAND) a header needs to be attached to the SPL binary indicating the load address and the size of the image. SPI boot additionally requires endian conversion before flashing the image.
  • When using peripheral boot (UART) there can be no header as the load address is fixed.

Building U-Boot

Using GNU toolchain for ARM processors from Arago is recommended. Arago Toolchain is available as an Ubuntu executable?here

Assuming the release package is extracted inside directory represented as $AM335x-PSP-DIR: 
  • U-Boot source tarball (u-boot-MM.mm.pp.bb.tar.gz) needs to be extracted on Linux build host. This will create U-Boot source base for AM335x
$ cd $AM335x-PSP-DIR/AM335x-LINUX-PSP-MM.mm.pp.bb/src/u-boot
$ tar -xvzf u-boot-MM.mm.pp.bb.tar.gz

Change to the base of the U-Boot directory.

$ cd ./AM335x-LINUX-PSP-MM.mm.pp.bb/src/u-boot/u-boot-MM.mm.pp.bb

Building into a separate object directory with the "O=" parameter to make is strongly recommended.

Commands

$ rm -rf ./am335x
$ make O=am335x CROSS_COMPILE=arm-arago-linux-gnueabi- ARCH=arm am335x_evm

This will generate two binaries in the am335x directory,MLO and u-boot.img along with other intermediate binaries that may be needed in some cases (see below).

Serial port configuration

Connect a serial cable from the serial port of the EVM (serial port is next to the power switch) to the COM port on either the Windows machine or Linux host depending on where you'll be running the serial terminal software.

For correct operation the serial terminal software should be configured with the following settings:

  • Baud rate: 115,200
  • Data bits: 8
  • Parity: None
  • Stop bits: 1
  • Flow control: None
  • Transmit delay: 0 msec/char,100 msec/line

If Teraterm is being used ensure that the latest version (4.67) of Teraterm is installed. The implementation of the kermit protocol in Teraterm is not reliable in older versions. The latest version of Teraterm 4.67 can be downloaded from?here?Recent Teraterm updates causes slow Binary transfer over UART. In such cases use,Windows in-built HyperTerminal application.

Boot Switch Settings

Switch SW3 is for selecting the boot modes and device selection depends on the DIP switches intended for profile selection on EVMs.

  • Make sure that the EVM boot switch settings are set to required boot mode and then power on the board.

The picture below shows the boot mode configuration switch SW3 on the AM335X EVM.

Note

  • The bootmode setting in this picture is for NAND boot.Nand boot corresponds to(SW3 5:1) 10010


??????? ?

??
RED: circle shows?OFF?and?GREEN?circles shows?ON?switches.

Note

  • ON is labeled on the wrong side of SW3 boot mode switch.
  • Due to heavy pin-muxing,boot device is selectively available on selected AM335x EVMs & profiles. Details about the availability of the peripherals can be found from the?EVM reference manual.

NAND

Switch SW3,SW3[5:1] ==> 10010,other pins should be 0 (i.e. OFF). This sets the Boot mode pins (BTM[4:0]) to NAND boot mode

Note

  • If booting from General purpose Daughter board,select the profile in which NAND is present. For more details refer to?EVM reference manual.

SPI

Switch SW3,SW3[5:1] ==> 10110,other pins should be 0 (i.e. OFF). This Boot mode pins (BTM[4:0]) to SPI boot mode

Note

  • If booting from General purpose Daughter board,select the profile in which SPI is present. For more details refer to?EVM reference manual.

UART

Switch SW3,SW3[5:1] ==> 00001,other pins should be 0 (i.e. OFF). This Boot mode pins (BTM[4:0]) to UART boot mode

SD

Switch SW3,SW3[5:1] ==> 10111,other pins should be 0 (i.e. OFF). This Boot mode pins (BTM[4:0]) to SD boot mode.

Flashing U-Boot with CCS

Note

  • Both the stages of U-Boot need to be flashed on the same media.

You can flash the SPL & U-Boot onto NAND (for NAND boot) using the Flashing Tools provided in the PSP releases.

Refer to?AM335x Flashing Tools Guide?wiki page for instructions on how to flash the pre-built (or compiled) binary to NAND flash (or the recompiled one) with the help of the NAND flash writer.

After flashing the 2 stages use the appropriate switch settings to boot from?NAND?.

Flashing U-Boot without CCS

Note

  • Both the stages of U-Boot need to be flashed on the same media.
  • MLO is the binary for SPL and u-boot.img is the binary for U-Boot

It is possible to flash U-Boot to NAND from the 2nd stage of U-Boot which is loaded over UART or from SD card or previously flashed into NAND. Before proceeding with this please make sure that the 2 binaries for flashing (SPL and U-Boot) have been built.

UART-Flash Method

  1. Configure the board for UART boot as described over?AM335x U-Boot User's Guide#UART.
  2. Boot over UART to load the U-Boot as described over?AM335x U-Boot User's Guide#Boot_Over_UART.
  3. Flashing SPL bootloader?AM335x U-Boot User's Guide#Flashing_SPL_to_NAND_from_U-Boot_in_UART_boot_mode.
  4. Flashing U-Boot bootloader?AM335x U-Boot User's Guide#Flashing_U-Boot_to_NAND_from_U-Boot_in_UART_boot_mode.
  5. After flashing,make the appropriate switch settings to boot from?NAND.

SD-Flash-Method

Make sure the two binaries for NAND boot (SPL and U-Boot) which are required for flashing are present on the SD. Please refer to the section of?building U-Boot?to generate the images.

  1. Boot using SD card to load both the SPL and the U-Boot as described over?AM335x U-Boot User's Guide#Boot_using_SD_card. Do not interrupt the countdown till the?U-Boot#?prompt comes.
  2. Flashing SPL bootloader?AM335x U-Boot User's Guide#Flashing_SPL_to_NAND_from_U-Boot_in_SD_boot.
  3. Flashing 2nd stage bootloader?AM335x U-Boot User's Guide#Flashing_U-Boot_to_NAND_from_U-Boot_in_SD_boot.
  4. After flashing,make the appropriate switch settings to boot from?AM335x U-Boot User's Guide#SD.

Boot Modes

NAND

Note

  • Make sure that NAND is enabled on the EVM. The switch for enabling NAND is shown?here.

This section gives an?overview?of the NAND support in U-Boot. It also describe how to store the kernel image,RAMDISK or the UBIFS filesystem to NAND so as to have a network-free boot right from powering on the board to getting the kernel up and running.

Overview

Micron Nand parts (page size 2KB,block size 128KB) are supported on AM335XEVM platforms.

Note

  • The following sub-sections illustrate the usage of NAND specific commands on AM335XEVM.
  • Refer to?EVM Switch Settings?section for more info on enabling/disabling different boot devices.

NAND Layout

The NAND part on the EVM has been configured in the following manner. The addresses mentioned here are used in the subsequent NAND related commands.


+------------+-->0x00000000-> SPL start         (SPL copy on 1st block)
|            |
|            |-->0x0001FFFF-> SPL end  
|            |-->0x00020000-> SPL.backup1 start (SPL copy on 2nd block)
|            |
|            |-->0x0003FFFF-> SPL.backup1 end  
|            |-->0x00040000-> SPL.backup2 start (SPL copy on 3rd block)
|            |
|            |-->0x0005FFFF-> SPL.backup2 end  
|            |-->0x00060000-> SPL.backup3 start (SPL copy on 4th block)
|            |
|            |-->0x0007FFFF-> SPL.backup3 end
|            |-->0x00080000-> U-Boot start
|            |                                     
|            |-->0x002BFFFF-> U-Boot end  
|            |-->0x00260000-> ENV start
|            |
|            |
|            |-->0x0027FFFF-> ENV end
|            |-->0x00280000-> Linux Kernel start
|            |
|            |
|            |
|            |
|            |-->0x0077FFFF-> Linux Kernel end
|            |-->0x00780000-> File system start
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
+------------+-->0x10000000-> NAND end (Free end)

Writing to Nand

To write len bytes of data from a memory buffer located at addr to the NAND block offset:

U-Boot# nand write <addr> <offset> <len>

Note

  • Offset &?len fields should be in align with 0x800 (2048) bytes. On writing 3000 (0xbb8) bytes,len field can be aligned to 0x1000 ie 4096 bytes. Offset field should be aligned to page start address,multiple of 2048 bytes.

If a bad block is encountered during the write operation,it is skipped and the write operation continues from next 'good' block.

For example,to write 0x40000 bytes from memory buffer at address 0x80000000 to NAND - starting at block 32 (offset 0x400000):

U-Boot# nand write 0x80000000 0x400000 0x40000

Reading from Nand

To read len bytes of data from NAND block at a particular offset to the memory buffer in DDR located at addr:

U-Boot# nand read <addr> <offset> <len>

If a bad block is encountered during the read operation,it is skipped and the read operation continues from next 'good' block.

For example,to read 0x40000 bytes from NAND - starting at block 32 (offset 0x400000) to memory buffer at address 0x80000000:

U-Boot# nand read 0x80000000 0x400000 0x40000

Marking a bad block

Some of the blocks in the NAND may get corrupted over a period of time. In such cases you should explicitly mark such blocks as bad so that the image that you are writing to NAND does not end up getting corrupted.

To forcefully mark a block as bad:

U-Boot# nand markbad <offset> 

For example,to mark block 32 (assuming erase block size of 128Kbytes) as bad block - offset = blocknum * 128 * 1024:

U-Boot# nand markbad 0x400000

Viewing bad blocks

To view the list of bad blocks:

U-Boot# nand bad

Note

  • The user marked bad blocks can be viewed by using this command only after a reset.

Erasing Nand

To erase NAND blocks in a particular the address range or using block numbers:

U-Boot# nand erase <start offset addr> <len>

Note

  • start offset addr & len fields should should align to 0x20000 (64*2048) bytes,i.e. block size 128KB.

This commands skips bad blocks (both factory and user marked) encountered within the specified range.

For example,to erase blocks 32 through 34:

U-Boot# nand erase 0x00400000 0x40000

NAND ECC algorithm selection

NAND flash memory,although cheap,suffers from problems like bit flipping which lead to data corruption. However by making use of some error correction coding (ECC) techniques it is possible to work around this problem.

For the data stored in NAND flash,U-Boot supports following NAND ECC schemes

  1. S/W ECC (Hamming code)
  2. H/W ECC (Hamming code,BCH4,BCH8)

Current releases do not support BCH4.

BCH Flash OOB Layout

For any ECC scheme we need to add some extra data while writing so as to detect and correct (if possible) the errors introduced by the NAND part. In case of BCH scheme some bytes are needed to store the ECC related info.

The section of NAND memory where addition info like ECC data is stored is referred to as Out Of Band or OOB section.

The first 2 bytes are used for Bad block marker – 0xFFFF => Good block

The next ‘N’ bytes is used for BCH bytes

N = B * <Number of 512-byte sectors in a page>

  1. B = 8 bytes per 512 byte sector in BCH4
  2. B = 14 bytes per 512 byte sector in BCH8
  3. B = 26 bytes per 512 byte sector in BCH16

So for a 2k page-size NAND flash with 64-byte OOB size,we will use BCH8. This will consume 2 + (14*4) = 58 bytes out of 64 bytes available.

The NAND flash part used in EVM does not have enough spare area to support BCH16.

ECC Schemes and their context of usage
ECC type Usage
S/W ECC Not used
H/W ECC - Hamming Code Should use this scheme only for flashing the U-Boot ENV variables.
H/W ECC – BCH8 Should use this scheme while flashing any image/binary other than the U-Boot ENV variables.

To select ECC algorithm for NAND:

U-Boot# nandecc [sw | hw <hw_type>] 

Usage:

sw - Set software ECC for NAND hw <hw_type> - Set hardware ECC for NAND <hw_type> - 0 for Hamming code 1 for bch4 2 for bch8 3 for bch16 Currently we support only Software,Hamming Code and BCH8. We do not support BCH4 and BCH16

ECC schemes usage table

ECC schemes usage table
Component Default ECC scheme used by the component ECC scheme to be used to flash the component ECC schemes supported by the component
SPL BCH8 BCH8 BCH8
U-boot Hamming BCH8 Hamming/BCH8
Linux BCH8 BCH8 BCH8
File System NA BCH8 NA
Environment variables NA Hamming NA

Flashing Linux Kernel from U-Boot

TFTP the kernel uImage to DDR.

U-Boot# mw.b 0x82000000 0xff 0x500000  
U-Boot# tftp 0x82000000 <kernel_image>

Now flash the kernel image to NAND at the appropriate offset (refer to?NAND layout?section for the offsets)

U-Boot# nandecc hw 2
U-Boot# nand erase 0x00280000 0x00500000
U-Boot# nand write 0x82000000 0x00280000 0x500000

Note

  • Image_size should be aligned to page size of 2048 (0x800) bytes

UBIFS file system flashing

In AM335X,UBIFS file system is used in NAND flash as it is next generation flash file system.?

1. creating of UBIFS file system image is described over?here

2. Follow the steps mentioned below to Flash UBIFS image

Note: In case of AM335x,file system partition is starting from 0x780000. So from U-Boot,flashing offset for file system from U-Boot is 0x780000 and from Linux MTD partition number 7 should used for flashing file file system.

UBIFS file system flashing from U-Boot

Get the UBIFS image to U-Boot from tftp or MMC/SD or UART. Lets consider an example of MMC card.

Since we copy the data to NAND,Empty/Erase the required RAM. Then,get the UBIFS image to U-Boot

Load the memory with 0xFF

 u-boot# mw.b 0x82000000 0xFF <filesystem_image_size>

filesystem image size?is upward aligned to NAND page size.

Load the UBIFS file system image,in the example below from MMC as

 
 u-boot# mmc rescan
 u-boot# fatload mmc 0 0x82000000 ubi.img

Erase the NAND. Switch to BCH8 ECC and the flash the image assuming NAND partition to be erased starts from "0x780000" and is of size "0xF880000". File system size to be flashed is 0xFC0000 which is upward aligned to NAND block size.

 u-boot# nand erase 0x00780000 0xF880000
 u-boot# nandecc hw 2
 u-boot# nand write 0x82000000 0x780000 0xFC0000


UBIFS file system flashing from Linux

  • Flash the UBI file system image (ubi.img) to MTD partition "X"?
ubiformat /dev/mtd<X> -f ubi.img -s 512 -O 2048

Assuming?7th mtd partition,we can use the following command to flash the ubifs image to partition 7.

#ubiformat /dev/mtd7 -f ubi.img -s 512 -O 2048

NOR

NOT SUPPORTED IN THIS RELEASE

SPI

NOT SUPPORTED IN THIS RELEASE

UART

This section describes how to use UART boot mode using TeraTerm.?

Boot Over UART

Note

  • The release package does not contain the binary for UART boot. Please follow the steps mentioned?here?for compiling u-boot and use the?spl/u-boot-spl.bin?file that is produced.
  1. Switch ON EVM with switch settings for?UART boot. When “CCCC” characters appear on TeraTerm window,from the File Menu select Transfer --> XMODEM --> Send (1K mode)
  2. Select “u-boot-spl.bin” for the transfer
  3. After image is successfully downloaded,the ROM code will boot it.
  4. When “CCCC” characters appear on TeraTerm window,from the File Menu select Transfer --> YMODEM --> Send (1K mode)
  5. Select “u-boot.img” for the transfer
  6. After image is successfully downloaded,U-Boot will boot it.
  7. Hit enter and get to u-boot prompt “U-Boot# ”

Flashing images to NAND in UART boot mode

Before proceeding with any of the commands given in this section please make sure that profile is selected to enable NAND on the EVM. The switch for selecting profile for NAND is described?here.

Boot using UART?boot mode as?here

After the U-Boot prompt?U-Boot#?comes up,the images for the 1st stage and 2nd stage can be flashed to NAND for persistent storage.

Flashing SPL to NAND from U-Boot in UART boot mode

Flash SPL (MLO) to NAND by executing the following commands:

U-Boot# mw.b 0x82000000 0xFF 0x20000
U-Boot# loadb 0x82000000

  • From TeraTerm Menu click “File -> Transfer -> Kermit -> Send”.
  • Select the 1st stage u-boot image “MLO” and click “OPEN” button
  • Wait for download to complete and then run following commands in u-boot prompt
U-Boot# nand erase 0x0 0x20000
U-Boot# nandecc hw 2
U-Boot# nand write.i 0x82000000 0x0 0x20000

If no error messages are displayed the SPL of NAND boot has been successfully transferred to NAND.

Flashing U-Boot to NAND from U-Boot in UART boot mode

Flash the 2nd stage U-Boot (u-boot.img) to NAND by executing the following commands:

U-Boot# mw.b 0x82000000 0xFF 0x40000
U-Boot# loadb 0x82000000

  • From TeraTerm Menu click “File -> Transfer -> Kermit -> Send”.
  • Select the 2nd stage u-boot image “u-boot.img” and click “OPEN” button
  • Wait for download to complete and then run following commands in U-Boot prompt
U-Boot# nand erase 0x80000 0x40000
U-Boot# nandecc hw 2
U-Boot# nand write.i 0x82000000 0x80000 0x40000

If no error messages are displayed the U-boot of NAND boot has been successfully transferred to NAND.

SD (Secured Digital card)

This section gives an overview of the SD (Secured Digital Card) support in U-Boot

Overview

SD (Secured Digital Card) support is available through HSMMC controller.

SD support is available by default in all U-Boot configs.? SD card can be accessed in all other boot modes (NAND/SPI).

Read and execute application from SD card

Please note that the following commands are being executed from the 2nd stage. List files on a FAT32 formatted SD card

U-Boot# mmc rescan
U-Boot# fatls mmc 0

Booting kernel image from the SD card

U-Boot# mmc rescan
U-Boot# fatload mmc 0 0x82000000 uImage
U-Boot# bootm 0x82000000

Booting application (ex. u-boot.img) image from the SD card

U-Boot# mmc rescan
U-Boot# fatload mmc 0 0x82000000 u-boot.img
U-Boot# go 0x82000000

Setting Up Boot Environment on SD Card

This section describes steps to be followed to create a standalone power-on bootable system on SD card.

Prerequisites?Ensure that following is available:

  • A Linux host with fdisk,sfdisk,mkfs.ext3 and mkfs.vfat utilities is available
  • Copy images MLO,u-boot.img,uImage,nfs.tar.gz and mksd-am335x.sh from release package to a directory on this Linux machine. For subsequent description,we will assume these files are copied to /home/am335x. Please refer "Package Contents" section in?AM335x PSP User's Guide?for location of these files.
  • Empty SD card (at least 256MB,preferably 4GB SDHC)
  • A SD memory card reader/programmer to copy files from Linux Host

Note

  • The SD Boot has some specific restriction about the format of the 1st partition and copying the MLO image.
  • So it is recommended that the supplied script mksd-am335x.sh is used for creating partitions and copying files.

Steps

  • Connect the SD memory card using Memory Card reader to the Linux Host
  • Note the name allotted for this device. We assume the device is named as "/dev/sdd"
  • Navigate to the /home/am335x directory where all the mentioned files are copied
  • Ensure that the script mksd-am335x.sh has executable permissions
  • This scripts expects arguments in the following format

./mksd-am335x.sh <sd-device-name> <sd-1st-stage-bootloader> <sd-2nd-stage-bootloader> <kernel-uImage> <filesystem>

  • Note?that the user will require root/sudo permissions
  • In our example,we run the following command

sudo ./mksd-am335x.sh /dev/sdd MLO u-boot.img uImage nfs.tar.gz

  • You will be asked about data getting overwritten,confirm it and the files along with filesystem will be copied to SD card
  • Note that this script will create two primary partitions:
    • 1st partition is formatted as FAT32 containing MLO,uImage files
    • 2nd partition is formatted as ext3 where the filesystem is extracted in root

Boot using SD card

Once the SD card has been setup as described in the previous section make sure the switch setting are set for?SD boot mode?and then plug in the SD card in the MMC/SD card slot on the EVM.

Flashing images to NAND in SD boot

Before proceeding with any of the commands given in this section please make sure that profile is selected to enable NAND on the EVM. The switch for selecting profile for NAND is described?here.

Boot using SD boot mode as?here

After the 2nd stage prompt?U-Boot#?comes up,the images for the 1st stage and 2nd stage can be flashed to NAND for persistent storage.

Flashing SPL to NAND from U-Boot in SD boot

Flash SPL (MLO) to NAND by executing the following commands:

U-Boot# mmc rescan
U-Boot# mw.b 0x82000000 0xFF 0x20000
U-Boot# fatload mmc 0 0x82000000 MLO
U-Boot# nandecc hw 2
U-Boot# nand erase 0x0 0x20000
U-Boot# nand write.i 0x82000000 0x0 0x20000

If no error messages are displayed the SPL of NAND boot has been successfully transferred to NAND.

Flashing U-Boot to NAND from U-Boot in SD boot

Flash the 2nd stage U-Boot (u-boot.img) to NAND by executing the following commands:

U-Boot# mmc rescan
U-Boot# mw.b 0x82000000 0xFF 0x40000
U-Boot# fatload mmc 0 0x82000000 u-boot.img
U-Boot# nandecc hw 2
U-Boot# nand erase 0x80000 0x40000
U-Boot# nand write.i 0x82000000 0x80000 0x40000

If no error messages are displayed the U-boot of NAND boot has been successfully transferred to NAND.

ENV on SD card using uEnv.txt

U-Boot environment variables can be modified using a plain text file named uEnv.txt. The scripts can be used to modify and even over-ride the various parameters like bootargs,TFTP serverip etc. If a command named uenvcmd is defined in the file it will be executed.

Example text file named?uEnv.txt


IMPORTANT

  • The uEnv.txt file should be in?unix?format. Also make sure that there is?an empty line?at the end of the file.


bootargs=console=ttyO0,115200n8 root=/dev/mmcblk0p2 mem=128M rootwait
bootcmd=mmc rescan; fatload mmc 0 0x82000000 uImage; bootm 0x82000000
uenvcmd=boot

The file?uEnv.txt?is automatically loaded from MMC if the bootcmd is run. It can be loaded and put into the environment manually,for example TFTP the file to some location in DDR and then use the following commands (assumption: network setting has already been done using the steps mentioned in this User Guide)

U-Boot# tftp 0x82000000 uEnv.txt

... Make note of the number of bytes downloaded ...

U-Boot# env import -t 0x82000000 number_of_bytes_above

The file can even be placed in the SD card and then bootcmd set to autorun this script if present.

Making use pre-existing uEnv on SD card

uEnv.txt on an SD card can be used to override the env settings saved on a persistent storage like NAND by making use of the following commands

 U-Boot# mmc rescan
 U-Boot# fatload mmc 0 0x81000000 uEnv.txt
 U-Boot# env import -t 0x81000000 $filesize
 U-Boot# boot

U-Boot Network configuration

In order to download the Linux kernel image from the TFTP server and for mounting NFS the network settings in U-Boot need to be configured.

Note

  • Run the following commands from the 2nd stage U-Boot prompt on the serial console.

When booting for the first time,U-Boot tries to fetch the MAC address from the env space. If it returns empty,it will look for MAC address from the eFuse registers in the Control module space and set the "ethaddr" variable in the env appropriately. The ethaddr can also be set using the setenv/saveenv commands. In such cases the user-set MAC address will take effect on subsequent reboot only.

To set a different MAC address use the following command

U-Boot# set ethaddr <random MAC address eg- 08:11:23:32:12:77>

Note

  • When setting a MAC address please ensure that the LSB of the 1st byte if not 1 i.e. when setting the MAC address:?y?in xy:ab:cd:ef:gh:jk has to be an even number. For more info this refer to the wiki pagehttp://en.wikipedia.org/wiki/MAC_address

In case a static ip is not available run the dhcp command to obtain the ip address from the DHCP server on the network to which the EVM is connected.

U-Boot# setenv serverip <tftp server in your network>
U-Boot# netmask 255.255.255.0
U-Boot# dhcp 
U-Boot# saveenv

In case a static ip is available run the following commands

U-Boot# setenv ipaddr <your static ip>
U-Boot# saveenv

This completes the network configuration in U-Boot.

U-Boot Environment Variables

After completing the network configuration and flashing the kernel image and filesystems to flash you need to set some other parameters which are essential for booting the kernel. We make use of a number of existing helper variables that exist in the environment at present. To see what they are set to use the?printenv?command. After setting?bootargs?along with any other variables for your needs you will need to do:

U-Boot# saveenv

In all cases we make use of?optargs?to control passing in of additional arguments and?ip_method?to determine how the kernel will deal with networking PRIOR to userspace spawning init. This does not control for example if a dhcp client will be started as part of the userspace init sequence.

Environment Settings for Ramdisk

In case you are using a RAMDISK as the Linux filesystem:

U-Boot# setenv bootargs ${console} ${optargs} root=/dev/ram rw initrd=${loadaddr},32MB ip=${ip_method}

For booting from NAND:

U-Boot# setenv nand_src_addr 0x00280000
U-Boot# setenv nand_img_siz 0x170000
U-Boot# setenv initrd_src_addr 0x00780000
U-Boot# setenv initrd_img_siz 0x320000
U-Boot# setenv bootcmd 'nand read.i ${kloadaddr} ${nand_src_addr} ${nand_img_siz};nand read.i ${loadaddr} ${initrd_src_addr} ${initrd_img_siz};bootm ${kloadaddr}'

For booting from SD card:

U-Boot# setenv bootcmd 'mmc rescan;run mmc_load_uimage;fatload mmc ${mmc_dev} ${loadaddr} initrd.ext3.gz;bootm ${kloadaddr}' 

Note

  • The sizes of images mentioned in the above commands have to be modified based on the actual image size. Also,it should be aligned to sector size of the flash device used.

Environment Settings for UBIFS Filesystem

  • The U-Boot environment variable?bootargs?contains arguments to be passed to the Linux kernel. The?bootargsvariable here makes use of the?nand_root?variable. The typical format of this variable for a UBIFS root filesystem is:
root=ubi0:<VOLUME NAME> ubi.mtd=<PARTITION_ID>,YYYY rw

The value of?PARTITION_ID?depends on MTD device which holds the rootfs,?YYYY?depends on the page size of the partition and?VOLUME NAME? depends on the volume name given in ubinize.cfg file while creating UBIFS?image as described?here?. In cases where you have multiple UBI volumes,ubi0 would change to the volume with the root partition.

Once?nand_root?is set:

U-Boot# setenv bootcmd run nand_boot

Environment Settings for NFS Filesystem

Note

  • When setting a MAC address please ensure that the LSB of the 1st byte if not 1 i.e. when setting the MAC address:?y?in xy:ab:cd:ef:gh:jk has to be an even number. For more info this refer to the wiki pagehttp://en.wikipedia.org/wiki/MAC_address
  • If you need to use a separate server for TFTP and NFS please see how to use the?next-server?option in your DHCP server.

Modify the required variables:

U-Boot# print ethaddr                          <-- Check if MAC address is assigned and is unique
U-Boot# setenv ethaddr <unique-MAC-address>    <-- Set only if not present already,format uv:yy:zz:aa:bb:cc
U-Boot# setenv serverip <NFS and TFTP server-ip>
U-Boot# setenv rootpath /location/of/nfsroot/export
U-Boot# setenv bootcmd net_boot

Booting the kernel

In case everything went well,boot the kernel from U-Boot using the following command.

U-Boot# boot

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读