歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> U-Boot中gd的定義和使用

U-Boot中gd的定義和使用

日期:2017/3/1 9:43:40   编辑:Linux編程

最近在做uboot中nand啟動相關的工作,遇到一個問題一直糾結著。現在終於明白了這個問題,想想還有好多兄弟在某個黑暗的角落裡或者某台電腦前糾結著呢,所以趕緊寫下來以供查閱。

U-Boot源代碼下載地址 http://www.linuxidc.com/Linux/2011-07/38897.htm

uboot version 2014.4

/* Architecture-specific global data */
struct arch_global_data {
#if defined(CONFIG_FSL_ESDHC)
u32 sdhc_clk;
#endif
#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;
#endif

#ifdef CONFIG_OMAP
struct omap_boot_parameters omap_boot_params;
#endif
};

#include <asm-generic/global_data.h>

#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

從這裡看到了gd的定義,並且可以知道氣質這個結構體的定義是在:#include <asm-generic/global_data.h>這個目錄下。

那麼就去這個目錄下添加一個私有變量使得在後續的使用過程中更加方便吧!!!!!!!!!!!

typedef struct global_data {
bd_t *bd;
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 */
#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 */
#ifdef CONFIG_PRE_CONSOLE_BUFFER
unsigned long precon_buf_idx;
/* Pre-Console buffer index */
#endif
#ifdef CONFIG_MODEM_SUPPORT
unsigned long do_mdm_init;
unsigned long be_quiet;
#endif
unsigned long env_addr;
/* Address of Environment struct */
unsigned long env_valid;
/* Checksum of Environment valid? */

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 device *dm_root; /* Root instance for Driver Model */
struct list_head uclass_root;
/* Head of core tree */
#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 */
void **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
unsigned long timebase_h;
unsigned long timebase_l;
struct arch_global_data arch;
/* architecture-specific data */

#ifdef CONFIG_xxxxx //此處隨便x
void *priv;
/* point to the private data */
#endif
} gd_t;

在使用的過程中包含頭文件,就可以使用了。

u-boot Makefile完全解讀 http://www.linuxidc.com/Linux/2013-04/83529.htm

U-Boot中的date命令 http://www.linuxidc.com/Linux/2013-07/87614.htm

U-Boot源代碼下載地址 http://www.linuxidc.com/Linux/2011-07/38897.htm

U-Boot下的兩個重要數據:bd_t和gd_t http://www.linuxidc.com/Linux/2013-05/83993.htm

U-Boot中的version命令 http://www.linuxidc.com/Linux/2013-05/83990.htm

U-Boot中的usb命令 http://www.linuxidc.com/Linux/2013-05/83991.htm

Copyright © Linux教程網 All Rights Reserved