uboot全局数据gd_t、bd_t和device_t

gd_t定义在include/asm-arm/global_data.h

 33  /* Keep it *SMALL* and remember to set CFG_GBL_DATA_SIZE > sizeof(gd_t)
 34  */

 36 typedef struct  global_data {
 37     bd_t        *bd;
 38     unsigned long   flags;
 39     unsigned long   baudrate;
 40     unsigned long   have_console;   /* serial_init() was called */
 41     unsigned long   reloc_off;  /* Relocation Offset */
 42     unsigned long   env_addr;   /* Address  of Environment struct */
 43     unsigned long   env_valid;  /* Checksum of Environment valid? */
 44     unsigned long   fb_base;    /* base address of frame buffer */
 45 #ifdef CONFIG_VFD
 46     unsigned char   vfd_type;   /* display type */
 47 #endif
 48 #if 0
 49     unsigned long   cpu_clk;    /* CPU clock in Hz!     */
 50     unsigned long   bus_clk;
 51     phys_size_t ram_size;   /* RAM size */
 52     unsigned long   reset_status;   /* reset status register at boot */
 53 #endif
 54     void        **jt;       /* jump table */
 55 } gd_t;


 67 #define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r8")
这个声明告诉编译器使用寄存器r8来存储gd_t类型的指针gd,即这个定义声明了一个指针,并且指明了它的存储位置。
register表示变量放在机器的寄存器
volatile用于指定变量的值可以由外部过程异步修改。

并且这个指针在start_armboot()(board.c)中被初始化:
    /* Pointer is writable since we allocated a register for it */
    gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
这样,gd就指向的一个可用的内存地址了。

-------------------------------------------------------------------------------------------------------------

bd_t定义于include/asm-arm/u-boot.h

 39 typedef struct bd_info {
 40     int         bi_baudrate;    /* serial console baudrate */
 41     unsigned long   bi_ip_addr; /* IP Address */
 42     unsigned char   bi_enetaddr[6]; /* Ethernet adress */
 43     struct environment_s           *bi_env;
 44     ulong           bi_arch_number; /* unique id for this board */
 45     ulong           bi_boot_params; /* where this board expects params */
 46     struct              /* RAM configuration */
 47     {
 48     ulong start;
 49     ulong size;
 50     }           bi_dram[CONFIG_NR_DRAM_BANKS];
 51 #ifdef CONFIG_HAS_ETH1
 52     /* second onboard ethernet port */
 53     unsigned char   bi_enet1addr[6];
 54 #endif
 55 } bd_t;
 56
 57 #define bi_env_data bi_env->data
 58 #define bi_env_crc  bi_env->crc

------------------------------------------------------------------------------------------------

device_t定义于include/devices.h,是对串口设备文件的描述。

 29 /*
 30  * CONSOLE DEVICES
 31  */
 32
 33 #define DEV_FLAGS_INPUT  0x00000001 /* Device can be used as input  console */
 34 #define DEV_FLAGS_OUTPUT 0x00000002 /* Device can be used as output console */
 35 #define DEV_FLAGS_SYSTEM 0x80000000 /* Device is a system device        */
 36 #define DEV_EXT_VIDEO    0x00000001 /* Video extensions supported       */
 37
 38 /* Device information */
 39 typedef struct {
 40     int flags;          /* Device flags: input/output/system    */
 41     int ext;            /* Supported extensions         */
 42     char    name[16];       /* Device name              */
 43
 44 /* GENERAL functions */
 45
 46     int (*start) (void);        /* To start the device          */
 47     int (*stop) (void);     /* To stop the device           */
 48
 49 /* OUTPUT functions */
 50
 51     void (*putc) (const char c);    /* To put a char            */
 52     void (*puts) (const char *s);   /* To put a string (accelerator)    */
 53
 54 /* INPUT functions */
 55
 56     int (*tstc) (void);     /* To test if a char is ready...    */
 57     int (*getc) (void);     /* To get that char         */
 58
 59 /* Other functions */
 60
 61     void *priv;         /* Private extensions           */
 62 } device_t;

posted @ 2015-09-27 21:12  yuxi_o  阅读(1340)  评论(0编辑  收藏  举报