您的位置:首页 > 理论基础 > 数据结构算法

U-Boot学习:[0]global_data 和 bd_info

2017-03-22 15:52 369 查看

U-Boot学习:[0]global_data 和 bd_info

基于U-Boot 2017.03-rc2-gc7a25b3-dirty 源码分析

global_data

global_data 数据结构

global_data 数据结构的定义位于源码目录:

include/asm-generic/global_data.h

typedef struct global_data {
bd_t *bd;       //struct board_info指针,保存板子信息
unsigned long flags;        //指示标志,如设备已经初始化标志等
unsigned int baudrate;       //串口波特率
unsigned long cpu_clk;      /* CPU clock in Hz!     */
unsigned long bus_clk;
/* We cannot bracket this with CONFIG_PCI due to mpc5xxx */
unsigned long pci_clk;
unsigned long mem_clk;
#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
unsigned long fb_base;      /* Base address of framebuffer mem frame buffer的基址 */
#endif
#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
unsigned long post_log_word;    /* Record POST activities */
unsigned long post_log_res; /* success of POST test */
unsigned long post_init_f_time; /* When post_init_f started */
#endif
#ifdef CONFIG_BOARD_TYPES
unsigned long board_type;
#endif
unsigned long have_console; /* serial_init() was called 串口初始化标志 */
#if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
unsigned long precon_buf_idx;   /* Pre-Console buffer index */
#endif
unsigned long env_addr;     /* Address  of Environment struct 环境参数地址 */
unsigned long env_valid;    /* Checksum of Environment valid? 环境参数CRC检验有效标志 */

unsigned long ram_top;      /* Top address of RAM used by U-Boot */
unsigned long relocaddr;    /* Start address of U-Boot in RAM */
phys_size_t ram_size;       /* RAM size */
unsigned long mon_len;      /* monitor len */
unsigned long irq_sp;       /* irq stack pointer */
unsigned long start_addr_sp;    /* start_addr_stackpointer */
unsigned long reloc_off;
struct global_data *new_gd; /* relocated global data */

#ifdef CONFIG_DM
struct udevice  *dm_root;   /* Root instance for Driver Model */
struct udevice  *dm_root_f; /* Pre-relocation root instance */
struct list_head uclass_root;   /* Head of core tree */
#endif
#ifdef CONFIG_TIMER
struct udevice  *timer;     /* Timer instance for Driver Model */
#endif

const void *fdt_blob;       /* Our device tree, NULL if none */
void *new_fdt;          /* Relocated FDT */
unsigned long fdt_size;     /* Space reserved for relocated FDT */
struct jt_funcs *jt;        /* jump table 跳转表,用来"函数调用地址登记" */
char env_buf[32];       /* buffer for getenv() before reloc. */
#ifdef CONFIG_TRACE
void        *trace_buff;    /* The trace buffer */
#endif
#if defined(CONFIG_SYS_I2C)
int     cur_i2c_bus;    /* current used i2c bus */
#endif
#ifdef CONFIG_SYS_I2C_MXC
void *srdata[10];
#endif
unsigned long timebase_h;
unsigned long timebase_l;
#ifdef CONFIG_SYS_MALLOC_F_LEN
unsigned long malloc_base;  /* base address of early malloc() */
unsigned long malloc_limit; /* limit address */
unsigned long malloc_ptr;   /* current address */
#endif
#ifdef CONFIG_PCI
struct pci_controller *hose;    /* PCI hose for early use */
phys_addr_t pci_ram_top;    /* top of region accessible to PCI */
#endif
#ifdef CONFIG_PCI_BOOTDELAY
int pcidelay_done;
#endif
struct udevice *cur_serial_dev; /* current serial device */
struct arch_global_data arch;   /* architecture-specific data */
#ifdef CONFIG_CONSOLE_RECORD
struct membuff console_out; /* console output */
struct membuff console_in;  /* console input */
#endif
#ifdef CONFIG_DM_VIDEO
ulong video_top;        /* Top of video frame buffer area */
ulong video_bottom;     /* Bottom of video frame buffer area */
#endif
} gd_t;


global_data 声明

对于ARM架构,其 struct arch_global_data 定义位于源码目录:

arch/arm/include/asm/global_data.h:

/* Architecture-specific global data */
struct arch_global_data {
#if defined(CONFIG_FSL_ESDHC)
u32 sdhc_clk;
#endif

#if defined(CONFIG_U_QE)
u32 qe_clk;
u32 brg_clk;
uint mp_alloc_base;
uint mp_alloc_top;
#endif /* CONFIG_U_QE */

#ifdef CONFIG_AT91FAMILY
/* "static data" needed by at91's clock.c */
unsigned long   cpu_clk_rate_hz;
unsigned long   main_clk_rate_hz;
unsigned long   mck_rate_hz;
unsigned long   plla_rate_hz;
unsigned long   pllb_rate_hz;
unsigned long   at91_pllb_usb_init;
#endif
/* "static data" needed by most of timer.c on ARM platforms */
unsigned long timer_rate_hz;
unsigned long tbu;
unsigned long tbl;
unsigned long lastinc;
unsigned long long timer_reset_value;
#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
unsigned long tlb_addr;
unsigned long tlb_size;
#if defined(CONFIG_ARM64)
unsigned long tlb_fillptr;
unsigned long tlb_emerg;
#endif
#endif
#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
#define MEM_RESERVE_SECURE_SECURED  0x1
#define MEM_RESERVE_SECURE_MAINTAINED   0x2
#define MEM_RESERVE_SECURE_ADDR_MASK    (~0x3)
/*
* Secure memory addr
* This variable needs maintenance if the RAM base is not zero,
* or if RAM splits into non-consecutive banks. It also has a
* flag indicating the secure memory is marked as secure by MMU.
* Flags used: 0x1 secured
*             0x2 maintained
*/
phys_addr_t secure_ram;
unsigned long tlb_allocated;
#endif

#ifdef CONFIG_ARCH_OMAP2
u32 omap_boot_device;
u32 omap_boot_mode;
u8 omap_ch_flags;
#endif
#if defined(CONFIG_FSL_LSCH3) && defined(CONFIG_SYS_FSL_HAS_DP_DDR)
unsigned long mem2_clk;
#endif
};


#ifdef CONFIG_ARM64
#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("x18")
#else
#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r9")
#endif
#endif


当使用gd_t时需用宏定义进行声明:DECLARE_GLOBAL_DATA_PTR。

对于ARM架构指定占用寄存器r9;对于ARM64架构制定占用寄存器x18。

bd_info

bd_info 数据结构

bd_info 数据结构的定义位于源码目录:

include/asm-generic/u-boot.h

typedef struct bd_info {
unsigned long   bi_memstart;    /* start of DRAM memory */
phys_size_t bi_memsize; /* size  of DRAM memory in bytes */
unsigned long   bi_flashstart;  /* start of FLASH memory */
unsigned long   bi_flashsize;   /* size  of FLASH memory */
unsigned long   bi_flashoffset; /* reserved area for startup monitor */
unsigned long   bi_sramstart;   /* start of SRAM memory */
unsigned long   bi_sramsize;    /* size  of SRAM memory */
#ifdef CONFIG_AVR32
unsigned char   bi_phy_id[4];   /* PHY address for ATAG_ETHERNET */
unsigned long   bi_board_number;/* ATAG_BOARDINFO */
#endif
#ifdef CONFIG_ARM
unsigned long   bi_arm_freq; /* arm frequency */
unsigned long   bi_dsp_freq; /* dsp core frequency */
unsigned long   bi_ddr_freq; /* ddr frequency */
#endif
#if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_MPC8260) \
|| defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
unsigned long   bi_immr_base;   /* base of IMMR register */
#endif
#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
unsigned long   bi_mbar_base;   /* base of internal registers */
#endif
#if defined(CONFIG_MPC83xx)
unsigned long   bi_immrbar;
#endif
unsigned long   bi_bootflags;   /* boot / reboot flag (Unused) */
unsigned long   bi_ip_addr; /* IP Address */
unsigned char   bi_enetaddr[6]; /* OLD: see README.enetaddr */
unsigned short  bi_ethspeed;    /* Ethernet speed in Mbps */
unsigned long   bi_intfreq; /* Internal Freq, in MHz */
unsigned long   bi_busfreq; /* Bus Freq, in MHz */
#if defined(CONFIG_CPM2)
unsigned long   bi_cpmfreq; /* CPM_CLK Freq, in MHz */
unsigned long   bi_brgfreq; /* BRG_CLK Freq, in MHz */
unsigned long   bi_sccfreq; /* SCC_CLK Freq, in MHz */
unsigned long   bi_vco;     /* VCO Out from PLL, in MHz */
#endif
#if defined(CONFIG_MPC512X)
unsigned long   bi_ipsfreq; /* IPS Bus Freq, in MHz */
#endif /* CONFIG_MPC512X */
#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
unsigned long   bi_ipbfreq; /* IPB Bus Freq, in MHz */
unsigned long   bi_pcifreq; /* PCI Bus Freq, in MHz */
#endif
#if defined(CONFIG_EXTRA_CLOCK)
unsigned long bi_inpfreq;   /* input Freq in MHz */
unsigned long bi_vcofreq;   /* vco Freq in MHz */
unsigned long bi_flbfreq;   /* Flexbus Freq in MHz */
#endif
#if defined(CONFIG_405)   || \
defined(CONFIG_405GP) || \
defined(CONFIG_405EP) || \
defined(CONFIG_405EZ) || \
defined(CONFIG_405EX) || \
defined(CONFIG_440)
unsigned char   bi_s_version[4];    /* Version of this structure */
unsigned char   bi_r_version[32];   /* Version of the ROM (AMCC) */
unsigned int    bi_procfreq;    /* CPU (Internal) Freq, in Hz */
unsigned int    bi_plb_busfreq; /* PLB Bus speed, in Hz */
unsigned int    bi_pci_busfreq; /* PCI Bus speed, in Hz */
unsigned char   bi_pci_enetaddr[6]; /* PCI Ethernet MAC address */
#endif

#ifdef CONFIG_HAS_ETH1
unsigned char   bi_enet1addr[6];    /* OLD: see README.enetaddr */
#endif
#ifdef CONFIG_HAS_ETH2
unsigned char   bi_enet2addr[6];    /* OLD: see README.enetaddr */
#endif
#ifdef CONFIG_HAS_ETH3
unsigned char   bi_enet3addr[6];    /* OLD: see README.enetaddr */
#endif
#ifdef CONFIG_HAS_ETH4
unsigned char   bi_enet4addr[6];    /* OLD: see README.enetaddr */
#endif
#ifdef CONFIG_HAS_ETH5
unsigned char   bi_enet5addr[6];    /* OLD: see README.enetaddr */
#endif

#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
defined(CONFIG_405EZ) || defined(CONFIG_440GX) || \
defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
defined(CONFIG_460EX) || defined(CONFIG_460GT)
unsigned int    bi_opbfreq;     /* OPB clock in Hz */
int     bi_iic_fast[2];     /* Use fast i2c mode */
#endif
#if defined(CONFIG_4xx)
#if defined(CONFIG_440GX) || \
defined(CONFIG_460EX) || defined(CONFIG_460GT)
int     bi_phynum[4];           /* Determines phy mapping */
int     bi_phymode[4];          /* Determines phy mode */
#elif defined(CONFIG_405EP) || defined(CONFIG_405EX) || defined(CONFIG_440)
int     bi_phynum[2];           /* Determines phy mapping */
int     bi_phymode[2];          /* Determines phy mode */
#else
int     bi_phynum[1];           /* Determines phy mapping */
int     bi_phymode[1];          /* Determines phy mode */
#endif
#endif /* defined(CONFIG_4xx) */
ulong           bi_arch_number; /* unique id for this board */
ulong           bi_boot_params; /* where this board expects params */
#ifdef CONFIG_NR_DRAM_BANKS
struct {            /* RAM configuration */
phys_addr_t start;
phys_size_t size;
} bi_dram[CONFIG_NR_DRAM_BANKS];
#endif /* CONFIG_NR_DRAM_BANKS */
} bd_t;


我的个人主页:http://www.techping.cn/

我的个人站点博客:http://www.techping.cn/blog/wordpress/

我的CSDN博客:http://blog.csdn.net/techping

我的简书:http://www.jianshu.com/users/b2a36e431d5e/timeline

我的GitHub:https://github.com/techping

欢迎相互follow~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  u-boot 数据结构 源码