AT91SAM9G25 Processor Uboot porting personal note one

Source: Internet
Author: User



1 Patch and patch generation


Generate Patches Diff-upnr old/new/> patch-x.y.z
DIFF-UPNR u-boot-2014.07/u-boot-2014.07_moveto9g25/> Moveto9g25-2015.08.25-ok.patch
Patch CD Old
Patch-p1 <. /patch-x.y.z
----------------------------------------------------------------------------------------------
2 Modifying Boards.cfg and Makefile
Status, Arch, Cpu:splcpu, SoC, Vendor, Board name, Target, Options, maintainers
Active arm Arm926ejs at91 Atmel AT91SAM9G25JZQ At91sam9g25jzq_nandflash
At91sam9g25jzq:at91sam9g25,sys_use_nandflash ZHAIGCH <[email protected]>


Modify Makefile, specify Cross_compile = arm-linux-
Copy Board/atmel/at91sam9x5ek to board name in AT91SAM9G25JZQ corresponding configuration file
Copy Include/configs/at91sam9x5ek.h to At91sam9g25jzq.h
Generate configuration header file make <target>_config
Make At91sam9g20ek_nandflash_config
Make At91sam9g25jzq_nandflash_config
Make
Make U-boot.dis//Generate Disassembly files
----------------------------------------------------------------------------------------------
3 Search String command
Grep-nr "XX".
Error compiling with the 4.3.2 Cross compiler armv5te instruction set is incompatible and is successfully passed using arm-none-gnueabi-4.7.3 compilation.

Modify the macro defined in Configs/at91sam9g25jzq.h as "config_sys_text_base0x22000000 "
After the program compiles the run address to 22000000, the NAND copy of the program is placed in the address, the direct jump execution.
Find the source code to do too good, straight run up!
----------------------------------------------------------------------------------------------
4 Start Analysis One
Arch/arm/lib/vectors. S//Interrupt vector table, jump to reset, i.e.:
Arch/arm/cpu/arm926ejs/start. S//Here if there is no two-level boot, there is a need to perform some necessary initialization operations.
such as shutting down the internal watchdog, initializing the system clock, initializing the DDR2 memory, copying the program from the NAND to the medium operation of the memory.
Since we are level two boot uboot, these have been completed by the 1-level boot program, so through the macro Config_skip_lowlevel_init
Skip directly through these procedures and call _main directly
Arch/arm/lib/crt0. S//_main defined in this file
Initialize SP to config_sys_init_sp_addr = 0x20000000 + 4096-generated_gbl_data_size
Sub SP, SP, #GD_SIZE, and then allocate gd_size-sized memory above the SP
mov R9, SP, at this time R9 save is gd_size the size of the memory of the start address, can also be considered as a pointer to a global variable structure body
Called Board_init_f, which is compiled according to the macro CONFIG_SYS_GENERIC_BOARD,COMMON/BOARD_F.C in the configuration header file
#define Declare_global_data_ptr Register volatile gd_t *GD asm ("R9")
COMMON/BOARD_F.C//If there is no macro, ARM/LIB/BOARD.C will be compiled, the file will be kicked out of the source, try not to link it
BL Board_init_f//board initialization, what do you do?
----------------------------------------------------------------------------------------------
5 Start Analysis Two
Board_init_f
GD = &data; The GD global data pointer points to the struct defined in the stack, which does not use the memory allocated outside the stack in the previous step
Why? later analysis
Initcall_run_list (Init_sequence_f)//Call all functions in the Init_sequence_f array
Setup_mon_len,//fill Gd->mon_len program length
SETUP_FDT,//Fill Gd->fdt_blob = 0
Trace_early_init,//Empty
Arch_cpu_init,//Call At91_clock_init, fill gd->arch clock-related data
Mark_bootstage,//"Board_init_f" string placed in record[] array record table
Timer_init,//Initialize pit, fill gd->arch.timer_rate_hz gd->arch.tbu = gd->arch.tbl = 0
Env_init,//The ENV_NAND.C is compiled and connected according to the macro Config_env_is_in_nand in the configuration file
Env_init is called to populate the GD-&GT;ENV_ADDR environment variable storage address
Fill gd->env_valid environment variable valid identity
Init_baud_rate,Fill Gd->baudrate
Serial_init, /* Serial Communications Setup * *
Console_init_f,//Fill gd->have_console = 1, initialize print buffer, from which you can use the printf printing function
Display_options,//console print Uboot version information and compile date
Display_text_info,/* Show Debugging Info if required */
Print_cpuinfo,//print processor model, master clock, system clock, peripheral clock
Announce_dram_init,//puts ("DRAM:");
Dram_init,//Fill gd->ram_size = 0x4000000
SETUP_DEST_ADDR,//Fill gd->relocaddr = Gd->ram_top = 0x24000000
reserve_round_4k,//4k alignment gd->relocaddr &= ~ (4096-1);
Reserve_trace,//null
Reserve_uboot,//gd->relocaddr-= gd->mon_len; leave out Uboot code space
Gd->relocaddr &= ~ (4096-1); 4K alignment
gd->start_addr_sp = gd->relocaddr; Stack space
Setup_machine,//gd->bd->bi_arch_number = Config_mach_type Set plate number
RESERVE_GLOBAL_DATA,//GD-&GT;START_ADDR_SP-= sizeof (gd_t), stack move down, allocate space gd_t
GD-&GT;NEW_GD = gd->start_addr_sp points to the newly allocated memory address
RESERVE_FDT,//gd->start_addr_sp-= gd->fdt_size; Allocating memory space for FDT
GD-&GT;NEW_FDT = gd->start_addr_sp points to the newly allocated FDT memory space
Reserve_stacks,//2 byte alignment, allocating memory for IRQ interrupts
Setup_dram_config,//null
Show_dram_config,//print out the size of the DRAM
DISPLAY_NEW_SP,//print gd->start_addr_sp at debug time
RELOC_FDT,//reposition FDT for data copying
Setup_reloc,//gd->reloc_off = gd->relocaddr-0x22000000;
memcpy (GD-&GT;NEW_GD, (char *) GD, sizeof (gd_t)); Copy the data in GD to the new address

----------------------------------------------------------------------------------------------
6 Start Analysis Three
After calling Board_init_f () to complete the initialization of the board and the global struct variable gd, copy it to the global structure that is reassigned under the code snippet
In the body. Next, reset the SP, point R9 to the global variable GD, and then relocate the code.
Ldr SP, [R9, #GD_START_ADDR_SP]/* SP = GD-&GT;START_ADDR_SP */
Bic SP, SP, #7/* 8-byte Alignment for ABI compliance */
Ldr R9, [R9, #GD_BD]/* R9 = GD-&GT;BD */
Sub R9, R9, #GD_SIZE

Modify the code return value so that its value is relocated to the address
Adr LR, here
Ldr R0, [R9, #GD_RELOC_OFF]/* R0 = Gd->reloc_off */
Add LR, LR, r0
Ldr R0, [R9, #GD_RELOCADDR]/* R0 = gd->relocaddr */
Copy the code to the relocated address space
B Relocate_code
Arch/arm/lib/relocate. S
Code snippets, data segments, and command line segments from __image_copy_start to __image_copy_end in a link script
Copy to relocation address gd->relocaddr
Once the copy is complete, the. Rel.dyn segment from __rel_dyn_start to __rel_dyn_end is also required (used when the code is relocated, and the default should
is a compiler-generated related addressing related to the data)
After you have finished redefining the code, return to the relocated code
Bl C_runtime_cpu_setup//arch/arm/cpu/arm926ejs/start. S no other operations to initialize, return directly
Next Initialize the BSS segment
Next Call the Board_init_r function
mov r0, R9//Will relocate after new GD pointer as parameter 0 incoming function
LDR R1, [R9, #GD_RELOCADDR]//relocation of code snippet starting address as parameter 1 incoming function
LDR pc, =board_init_r//absolute address jump, since the code is repositioned, and also based on the offset value of the previous program according to the relocation
The running address of the program is corrected to ensure the correct operation when the relocation is done by the absolute address.
----------------------------------------------------------------------------------------------
7 Start Analysis Four
Board_init_r
Initcall_run_list (Init_sequence_r)//Loop call all functions in struct INIT_SEQUENCE_R
Initr_caches//Open processor data and instructions cache, you need to add your own
Board_init//initialization of specific board-related peripherals, and GD-&GT;BD related elements for initial setup, need to be ported for modification
Initr_serial//Initialize the serial port again
Initr_malloc//Initialize allocated heap space memory,
Bootstage_relocate//Start-up phase relocation, why the Unknown
Power_init_board//NULL if custom related actions are required
Initr_flash/NOR flash initialization, if no nor flash on board need to configure macros Config_sys_no_flash
Initr_nand//nand Flash initialization, you need to configure macros Config_cmd_nand
INITR_ENV//Initialize environment variables
Set_default_env ()//If the environment variable is not read from Flash, the default environment variable is used Default_environment
"Bootargs=" Config_bootargs "\"
"Bootcmd=" Config_bootcommand "\"
"Nfsboot=" Config_nfsbootcommand"The"
"Bootdelay=" __stringify (Config_bootdelay)"The"
"Baudrate=" __stringify (Config_baudrate)"The"
"Ethaddr=" __stringify (CONFIG_ETHADDR)"The"
"Ipaddr=" __stringify (CONFIG_IPADDR)"The"
"Serverip=" __stringify (Config_serverip)"The"
"Gatewayip=" __stringify (CONFIG_GATEWAYIP)"The"
"Netmask=" __stringify (Config_netmask)"The"

INITR_SECONDARY_CPU//null, the weak function of the __weak flag, if a function with the same function name in the compiled program uses it instead of itself
Stdio_init//Standard input/output initialization
Initr_jumptable//Initialize the Jump table, why the Unknown
Console_init_r//control command line related initialization operation, do not need to transplant, do not care about it.
Interrupt_init//interrupt initialization, do not care about interrupts, can boot the Linux kernel on the line,
INITR_ETHADDR//Initialize the NIC address, you need to configure the macro config_cmd_net
Initr_net//Initialize the NIC, you need to configure the macro config_cmd_net
Run_main_loop//main loop, running Main_loop in a dead loop, parsing user input command line, or system autorun command
Main_loop
----------------------------------------------------------------------------------------------
8 Start Analysis Five
Since there is an initial bootloader prior to uboot in the boot process of the 9G25 processor, the program completes the initialization of the interrupt vector table
Fiq IRQ Interrupt Scenario Recording and SP settings, DDR memory initialization, system clock working at 399MHZ, peripheral clock working at 133MHZ, debug
The serial port bps is 115200, then copy the 0x80000 (512k) Long data from the NAND 0x40000 to the DDR memory 0x23000000, then
Jump to 23000000 address by Ldr pc,=0x23000000 Absolute address to run a copy of the Uboot program to a few places.

Since some operations in Uboot (MMU, Icache, dcache) instruction MRC (read coprocessor), MCR (write coprocessor),
These two instructions must be executed in privileged mode, so let the processor work in SVC management mode before jumping to uboot, otherwise
Command will trigger an undefined instruction interrupt.
Patching test
Tar xjf u-boot-2014.07.tar.bz2
CD u-boot-2014.07/
Patch-p1 <. /moveto9g25-2015.08.25-ok.patch
Make At91sam9g25jzq_nandflash_config
Make
Make U-boot.dis

NFS 22000000 192.168.0.1:/home/terminal/workspace/nfs/image/uimage_1













Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

At91sam9g25 Processor Uboot porting personal note one

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.