【System transplantation】 uboot detailed analysis

Publisher:EtherealHeartLatest update time:2020-01-21 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Uboot usage

    uboot console, countdown
    command: debug, operate some hardware

setenv printenv saveenv 
 nand erase 
 nand write 
 tftp 20008000 zImage
 help: What commands can uboot provide?
 setenv == set == sete == seten

    Environment variables: provide parameters for the command
     serverip: the tftp command provides the address of the tftp server
     ipaddr: the tftp command provides the address of the tftp client (development board)

Two environment variables

    uboot: download the kernel and start the kernel
    bootcmd: what should uboot do automatically after the countdown ends

 set bootcmd tftp 20008000 zImage ; bootm 20008000
 set serverip 192.168.7.2
 set ipaddr 192.168.7.6
 set ethaddr 00:22:23:24:25:ee

   When the countdown ends, uboot will execute the content in bootcmd:
   tftp 20008000 zImage ; bootm 20008000

   Download the zImage file (/tftpboot/) from the tftp server (serverip) to 20008000 in the memory of the development board (ipaddr)

   set bootcmd tftp 20008000 zImage ; bootm 20008000

  bootargs: responsible for telling the kernel where the file system is (uboot passes it to the kernel, which is used by the kernel)

  set bootargs init=/linuxrc console=ttySAC0,115200 root=/dev/nfs nfsroot=192.168.7.2:/opt/filesystem ip=192.168.7.6
  root=xxxx: Where is the root file system directory?
  /dev/nfs: The root file system directory is at the remote end of the network
  
  nfsroot=xxxx: Which file path of which machine is the root file system directory?
  nfsroot=192.168.7.2:/opt/filesystem
  ip=192.168.7.6: When the system logs in, a static ip is assigned.

  If root=/dev/nfs
  root=/dev/nfs + nfsroot=xxxx +ip=xx
  
  If root=/dev/mtdblock2 (will be discussed when the file system is created)
   root=/dev/mtdblock2 + rootfstype=cramfs
  
  console=ttySAC0,115200: During kernel startup, where should the debugging information be output? printk
  init=/linuxrc : Specify the executable code file of the first init process
  /opt/filesystem==> host: /etc/exports
  sudo vim /etc/exports
  /opt/filesystem *(subtree_check,rw,no_root_squash,async)
  /opt/fs100/rootfs *(subtree_check,rw,no_root_squash,async)

 

Start the kernel: go/bootm

Official uboot

zImage
  : go
  set bootcmd tftp 20008000 zImage ; go 20008000
 
 uImage 
  : bootm(download address, cannot be 20008000)
  set bootcmd tftp 20800000 uImage ; bootm 20800000
 
 selection of download address:
  go==> can be any address
  bootm==> 20008000+zImage size or above==>20800000 
 Comprehensive usage:
  set bootcmd tftp 20800000 zImage ; go 20800000
  set bootcmd tftp 20800000 uImage ; bootm 20800000
uboot1.3.4:
 zImage/uImage ==>bootm
 set bootcmd tftp 20800000 uImage ; bootm 20800000

 

uboot connection script

    Path: cpu/arm_cortexa8/u-boot.lds

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start) // Entry function
SECTIONS
{
        . = 0x00000000; // Current starting position 0x0
        . = ALIGN(4);
        .text(target file) :
        { 
                cpu/arm_cortexa8/start.o (.text) // First file's .text
                *(.text)
        }
        . = ALIGN(4); // Current position four-byte alignment
        .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
        . = ALIGN(4);
        .data : { *(.data) }
        . = ALIGN(4);
        .got : { *(.got) }
        __u_boot_cmd_start = .; // Use __u_boot_cmd_start to record the current position. The code will use the global
        .u_boot_cmd: { *(.u_boot_cmd) } // Segment data
        __u_boot_cmd_end = .; // End position
        . = ALIGN(4);
        __bss_start = .;
        .bss: { *(.bss) }
        _end = .;
}

Connection base address:
     -Ttext 0x34800000==>board/samsung/smdkc100/config.mk
     TEXT_BASE = 0x34800000
     1, TEXT_BASE specifies the starting position of the uboot connection
     2, specifies the location of the uboot relocation (can be changed to 0x2ff00000)

 

Detailed description of uboot configuration

 

make smdkc100_config
vim Makefile
unconfig:
        @rm -f $(obj)include/config.h $(obj)include/config.mk
                $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp
                $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep
MKCONFIG := $(SRCTREE)/mkconfig == ./mkconfig Shell script (executable program)

smdkc100_config: unconfig
        @$(MKCONFIG) $(@:_config=) arm arm_cortexa8 smdkc100 samsung s5pc1xx
 ./mkconfig smdkc100 arm arm_cortexa8 smdkc100 samsung s5pc1xx
 Execute a script: 6 parameters are passed (control source code compilation)
 arm: architecture ==> lib_arm
 smdkc100: include/configs/smdkc100.h // Configuration of all macros of the development board
 arm_cortexa8: arm name ==> cpu/arm_cortexa8
 smdkc100 samsung: development board name ==> board/samsung/smdkc100
 s5pc1xx: cpu ==> cpu/arm_cortexa8/s5pc1xx

$(@:_config=): $@:_config= ==>smdkc100_config:_config= // _config is replaced with empty, remove
  $(@:_config=xxx) ===>smdkc100xxx

 

uboot first stage startup process

 

1, build exception vector table:
_start: b reset
 ldr pc, _undefined_instruction
 ldr pc, _software_interrupt
 ldr pc, _prefetch_abort
 ldr pc, _data_abort
 ldr pc, _not_used
 ldr pc, _irq
 ldr pc, _fiq

2,
reset:
 /*
  * set the cpu to SVC32 mode, disable F, I
  */
 mrs r0, cpsr
 bic r0, r0, #0x1f
 orr r0, r0, #0xd3
 msr cpsr,r0

 bl cpu_init_crit
   |
   /*
    * Invalidate L1 I/D
    */
   mov r0, #0 @ set up for MCR
   mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
   mcr p15, 0, r0, /     * Disable MMU stuff and caches     */    mrc p15, 0, r0, c1, c0, 0
   bic    r0, r0, #0x00002000 @ clear bits 13 (--V-)    bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)    orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align    orr r0, r0, #0x00000800 @ set bit 12 (Z---) BTB    mcr p15, 0, r0, c1, c0, 0    bl lowlevel_init //lowlevel_init.S (boardsamsungsmdkc100):lowlevel_init:      |      /* Disable Watchdog */      ldr r0, =S5PC100_WATCHDOG_BASE @0xEA200000      orr r0, r0, #0x0      str r5, [r0]      /* setting SRAM */      ldr r0, =S5PC100_SROMC_BASE      ldr r1, =0x9      str r1, [r0]      /* S5PC100 has 3 groups of interrupt sources */      ldr r0, =S5PC100_VIC0_BASE @0xE4000000      ldr r1, =S5PC100_VIC1_BASE @0xE4000000      ldr r2, =S5PC100_VIC2_BASE @0xE4000000      /* Disable all interrupts (VIC0, VIC1 and VIC2) */      mvn r3, #0x0      str r3, [r0, #0x14] @INTENCLEAR      str r3, [r1, #0x14] @INTENCLEAR      str r3, [r2, #0x14] @INTENCLEAR      /* Set all interrupts as IRQ */      str r5, [r0, #0xc] @INTSELECT      str r5, [r1, #0xc] @INTSELECT      str r5, [r2, #0xc] @INTSELECT      /* Pending Interrupt Clear */      str r5, [r0, #0xf00] @INTADDRESS      str r5, [r1, #0xf00] @INTADDRESS      str r5, [r2, #0xf00] @INTADDRESS      bl uart_asm_init // Just set the gpio function, the baud rate is set in the second stage      #if 1 // The changed part      /* init system clock */      bl system_clock_init // Basically no big problem      bl mem_ctrl_asm_init      //mem_setup.S boardsamsungSmdkc100       // Memory initialization is more complicated, the original manufacturer will provide (1.3.4)      // Ask FAE      // This part of the code has problems running      1, mem_ctrl_asm_init















































     2, mem_setup.S needs to be compiled <=== boardsamsungSmdkc100Makefile
     3, memory initialization code should be in the first 16k (disassembled)
      modify cpu/arm_cotexa8/u-boot.lds


 /* Set up the stack */
stack_setup: ldr
 r0, _TEXT_BASE @ upper 128 KiB: relocated uboot
 sub r0, r0, #CONFIG_SYS_MALLOC_LEN @ malloc area
 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE @ bdinfo
#ifdef CONFIG_USE_IRQ
 sub r0, r0, #(CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ)
#endif
 sub sp, r0, #12 @ leave 3 words for abort-stack
 and sp, sp, #~7 @ 8 byte alinged for (ldr/str)d

Self-copy of uboot code:
 /* nand src offset : 0x0*/
 mov r0, #0x0   
 /* ​​ddr dst addr : 0x2ff00000*/
 ldr r1,=0x2ff00000
 /*size*/
 ldr r2, =0x40000
 bl copy2ddr

ddr address (relocation target address): should be the same as the base address of the uboot link
board/samsung/smdkc100/config.mk
TEXT_BASE=xxxx

Clear bss end 

/* Clear BSS (if any). Is below tx (watch load addr - need space) */
clear_bss:
 ldr r0, _bss_start @ find start of bss segment
 ldr r1, _bss_end @ stop here
 mov r2, #0x00000000 @ clear value
clbss_l:
 str r2, [r0] @ clear BSS location
 cmp r0, r1 @ are we at the end yet
 add r0, r0, #4 @ increment clear index pointer
 bne clbss_l @ keep clearing till at end

Jump to C stage
 ldr pc, _start_armboot @ jump to C code

_start_armboot: .word start_armboot

_start_armboot: .word start_armboot
    //start_armboot's value is determined during compilation: 0x2ff00000+offset==> 0x2ff00980

arm: basically all instructions are position-independent (the instructions can be executed anywhere).
    Some codes are position-dependent: ldr pc, _start_armboot (pc jumps to the target address _start_armboot (0x2ff00980), which is related to a specific location)
    The ldr instruction itself is position-independent, and the entire ldr pc, _start_armboot ==> becomes a position-dependent instruction

Link address: The linker sorts all the instructions. There must be a base address: base address + offset of the instruction.
Run address: The address where the instruction is actually loaded. When running, the address where the instruction is stored.
Physical address: Related to the hardware. The addresses in the data sheet are all physical addresses. The values ​​set by the hardware engineer for the device.
Virtual address: Generally related to MMU.

Ideas:


    1. Support a boot mode nand boot
         a. Initialize the clock and memory
              1. mem_setup.S is compiled
         b. Complete the implementation of self-copy
              nand_ops.c (read operation)
              nand(0x0) --> ddr(TEXT_BASE)
             board/samsung/smdkc100/config.mk
         c. The first stage code must all be in the first 16k
              u-boot.lds
         d. Familiar with the first stage boot process code

[1] [2] [3]
Reference address:【System transplantation】 uboot detailed analysis

Previous article:arm series knowledge framework
Next article:[Embedded] arm-linux-gcc/ld/objcopy/objdump parameter overview

Recommended ReadingLatest update time:2024-11-15 05:08

S3C2440 transplantation uboot compile and burn uboot
Table of Contents Migration environment Get uboot Update cross-compilation tools Configuring environment variables Migration environment Host: VMWare – Ubuntu 16.04 Development board: S3C2440 Compiler: arm-linux-gcc-4.3.2.tgz u-boot: u-boot-2012.04.01.tar.bz2 Get uboot Go to https://www.denx.de/wiki/U-Boot to do
[Microcontroller]
S3C2440 transplantation uboot compile and burn uboot
How to configure NORFASH when using JLINK to download uboot to MINI2440?
Note: The following settings are applicable to downloading an empty board (i.e. no program in the chip) using JLINK, and are downloaded to NORFALSH. 1.Target Interface (as shown below): 2.CPU settings: CPU settings include 3 parts: 2.1 Select CPU (S3C2440A is ARM920T core)   2.2 Set RAM address and size (S3
[Microcontroller]
How to configure NORFASH when using JLINK to download uboot to MINI2440?
TX2440 ARM development board Uboot transplantation (Part 3, add Nand Flash related operation support)
In the previous section, we said that there are usually two ways to boot the kernel in an embedded bootloader: booting from Nor Flash and booting from Nand Flash. However, no matter whether it is booting from Nor or Nand, after entering the second stage, the execution process of the two is the same. When u-boot's star
[Microcontroller]
cortex-a8 uboot series: Chapter 14 uboot environment variables
1. Uboot environment variable basis 1. The role of environment variables Instead of modifying the uboot source code, we can modify the environment variables to affect some data and features of the uboot runtime. For example, modifying the bootdelay environment variable can change the countdown seconds when the system
[Microcontroller]
cortex-a8 uboot series: Chapter 14 uboot environment variables
ARM study notes 007 uboot configuration and steps for burning nandflash
1. Burn the transplanted uboot into norflash first (this step is omitted) 2. The program to be burned must be placed in the /tftpboot directory of the virtual machine (if there is no such directory, you can create it yourself) 3. Set IP, gateway, etc. setenv serverip202.38.214.161;setenv ipaddr 202.38.214.163;sete
[Microcontroller]
ARM study notes 007 uboot configuration and steps for burning nandflash
The difference between ldr and adr in ARM assembly and analysis of related source code in uboot
ARM assembly has ldr instruction and ldr, adr pseudo-instructions, they can all use label expressions as operands. The following will illustrate their differences by analyzing a piece of code and the corresponding disassembly results. ldr r0, _start   adr r0, _start   ldr r0, =_start   _start:   b _start  
[Microcontroller]
Understanding of bl instruction in uboot of TQ2440-7.start.S
When compiling u-boot, add $(obj)u-boot.dis to the end of the ALL variable in Makefile, and u-boot.dis will be compiled. u-boot.dis is the disassembly of each instruction of u-boot generated by arm-linux-objdum –d. 33d80080:    e59f13f4     ldr    r1,      33d80084:    e59f03f4     ldr    r0,      33d80088:    e580100
[Microcontroller]
Understanding of bl instruction in uboot of TQ2440-7.start.S
s3c2440 bare metal-memory controller (3-3, operating norflash in uboot of norflash programming)
Prerequisite: norflash is initialized normally and can be executed normally from nor. The CPU always reads instructions from address 0 to execute the program. When the CPU is set to nor to start, address 0 corresponds to nor. When the cpu starts from nand, address 0 corresponds to sram. 1. Read norFlash We set the b
[Microcontroller]
s3c2440 bare metal-memory controller (3-3, operating norflash in uboot of norflash programming)
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号