U-boot中有一个用来保存很多有用信息的全局结构体--gd_t(global 缩写),其中包括了bd变量,可以说gd_t结构体包括了u-boot中所有重要全局变量。
对于ARM平台这个结构体的定义大致如下:
include/asm-arm/global_data.h
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;
phys_size_t ram_size; /* RAM size */
unsigned long reset_status; /* reset status register at boot */
#endif
void **jt; /* jump table */
} gd_t;
bd_info 在include\asm-arm\u-boot.h 中定义
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;
在U-boot中使用gd结构之前要用先用宏DECLARE_GLOBAL_DATA_PTR来声明。这个宏的定义如下:
include/asm-arm/global_data.h
#define DECLARE_GLOBAL_DATA_PTR volatile gd_t *gd asm ("r8")
从这个宏的定义可以看出,gd是一个保存在ARM的r8寄存器中的gd_t结构体的指针。
对于 Kernel,在使用U-boot传递来的gd中的bd时用的是arm_bd,因为:
在arch/arm//setup.c文件中:
void __init setup_arch(char **cmdline_p)
{
……
struct *tags = (struct tag *)&init_tags;
struct machine_desc *mdesc;
char *from = default_command_line;
void *bd_offset = NULL;
……
save_bd(bd_offset);
……
}
save_bd():
void __init save_bd(void* addr)
{
memcpy((char *)__res,
(char *)addr,
sizeof(bd_t));
arm_bd = (bd_t *)__res;
}
阅读(1953) | 评论(0) | 转发(1) |