u-boot-1.1.6\lib_arm\board.c
----------------------------------
.globl _start
_start: b reset
.globl _armboot_start
_armboot_start:
.word _start
-------------------------------
_armboot_start是u-boot的起始地址
gd_t結(jié)構(gòu)體和bd_t結(jié)構(gòu)體
typedef struct global_data {
bd_t *bd;
unsigned long flags;
unsigned long baudrate;
unsigned long have_console; /* serial_init() was called */
unsigned long reloc_off; /* Relocation Offset */
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid? */
unsigned long fb_base; /* base address of frame buffer */
#ifdef CONFIG_VFD
unsigned char vfd_type; /* display type */
#endif
#if 0
unsigned long cpu_clk; /* CPU clock in Hz! */
unsigned long bus_clk;
unsigned long ram_size; /* RAM size */
unsigned long reset_status; /* reset status register at boot */
#endif
void **jt; /* jump table */
} gd_t;
typedef struct bd_info {
int bi_baudrate; /* serial console baudrate */
unsigned long bi_ip_addr; /* IP Address */
unsigned char bi_enetaddr[6]; /* Ethernet adress */
struct environment_s *bi_env;
ulong bi_arch_number; /* unique id for this board */
ulong bi_boot_params; /* where this board expects params */
struct /* RAM configuration */
{
ulong start;
ulong size;
} bi_dram[CONFIG_NR_DRAM_BANKS];
#ifdef CONFIG_HAS_ETH1
/* second onboard ethernet port */
unsigned char bi_enet1addr[6];
#endif
} bd_t;
CFG_MALLOC_LEN 長度是128K,u-boot是512K,
gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
//執(zhí)行初始化列表函數(shù)
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
if ((*init_fnc_ptr)() != 0) {
hang ();
}
}
100ask24x0.c (board\100ask24x0)
gd->bd->bi_arch_number = MACH_TYPE_S3C2440;
gd->bd->bi_boot_params = 0x30000100;
bootcmd=nand read.jffs2 0x30007FC0 kernel;
void main_loop (void)
{
s = getenv ("bootcmd");
bootm 0x30007FC0
printf("Booting Linux ...\n");
run_command (s, 0);
}
查找命令的時候,
__u_boot_cmd_start和__u_boot_cmd_end中間的cmd段是怎么初始化的
--------------------------------------------------
鏈接腳本里面
__u_boot_cmd_start = .;
.u_boot_cmd : { *(.u_boot_cmd) }
__u_boot_cmd_end = .;
----------------------------------------------
cmd_tbl_t *find_cmd (const char *cmd)
{
for (cmdtp = &__u_boot_cmd_start;
cmdtp != &__u_boot_cmd_end;
cmdtp++) {
if (strncmp (cmd, cmdtp->name, len) == 0) {
if (len == strlen (cmdtp->name))
return cmdtp; /* full match */
cmdtp_temp = cmdtp; /* abbreviated command ? */
n_found++;
}
}
}
.u_boot_cmd這個段是哪來的
#define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))
bootm命令的定義
U_BOOT_CMD(
bootm, CFG_MAXARGS, 1, do_bootm,
"bootm - boot application image from memory\n",
"[addr [arg ...]]\n - boot application image stored in memory\n"
"\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
"\t'arg' can be the address of an initrd image\n"
#ifdef CONFIG_OF_FLAT_TREE
"\tWhen booting a Linux kernel which requires a flat device-tree\n"
"\ta third argument is required which is the address of the of the\n"
"\tdevice-tree blob. To boot that kernel without an initrd image,\n"
"\tuse a '-' for the second argument. If you do not pass a third\n"
"\ta bd_info struct will be passed instead\n"
#endif
);
U_BOOT_CMD的定義
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
進(jìn)行宏替換展開
- 字符串化(Stringification)
在宏體中似芝,如果宏參數(shù)前加個#那婉,那么在宏體擴(kuò)展的時候,宏參數(shù)會被擴(kuò)展成字符串的形式党瓮。如:
#define WARN_IF(EXP) \
do { if (EXP) \
fprintf (stderr, "Warning: " #EXP "\n"); } \
while (0)
WARN_IF (x == 0);會被擴(kuò)展成:
do { if (x == 0)
fprintf (stderr, "Warning: " "x == 0" "\n"); }
while (0);
bootm命令把kernel拷到加載地址運(yùn)行,并告訴內(nèi)核一些參數(shù),然后在跳到kernel運(yùn)行地址
1.設(shè)置啟動參數(shù)
setup_start_tag (bd);
char *commandline = getenv ("bootargs");
setup_commandline_tag (bd, commandline);
2.跳到入口地址
void (*theKernel)(int zero, int arch, uint params);
theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);
theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
nand read.jffs2 0x30007FC0 kernel; 使用.jffs2是因?yàn)椴恍枰?塊對齊
nand read[.jffs2] - addr off|partition size
nand write[.jffs2] - addr off|partiton size - read/write `size' bytes starting
at offset `off' to/from memory address `addr'
flash上沒有分區(qū)表
u-boot中如何添加自己的命令###
1.頭文件參考別的cmd_xxx.c
2.定義自己的U_BOOT_CMD宏
3.實(shí)現(xiàn)U_BOOT_CMD宏中cmd函數(shù)
#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <image.h>
#include <malloc.h>
#include <zlib.h>
#include <bzlib.h>
#include <environment.h>
#include <asm/byteorder.h>
int do_hello (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i = 0;
for (i = 0; i < argc; i++) {
printf("%s\n", argv[i]);
}
}
U_BOOT_CMD(
hello, CFG_MAXARGS, 1, do_hello,
"hello\n",
"fsdfdsfs example!\n"
);
---0x34000000 sdram最大地址---
??存放的是u-boot
---_armboot_start u-boot起始地址---
---CFG_MALLOC_LEN---大小192K