Global data

Globally required fields are held in the global data structure. A pointer to the structure is available as symbol gd. The symbol is made available by the macro %DECLARE_GLOBAL_DATA_PTR.

Register pointing to global data

On most architectures the global data pointer is stored in a register.

ARC r25
ARM 32bit r9
ARM 64bit x18
M68000 d7
MicroBlaze r31
NDS32 r10
Nios II gp
PowerPC r2
RISC-V gp (x3)
SuperH r13

The sandbox, x86, and Xtensa are notable exceptions.

Clang for ARM does not support assigning a global register. When using Clang gd is defined as an inline function using assembly code. This adds a few bytes to the code size.

Binaries called by U-Boot are not aware of the register usage and will not conserve gd. UEFI binaries call the API provided by U-Boot and may return to U-Boot. The value of gd has to be saved every time U-Boot is left and restored whenever U-Boot is reentered. This is also relevant for the implementation of function tracing. For setting the value of gd function set_gd() can be used.

Global data structure

struct global_data

global data structure

Definition

struct global_data {
  struct bd_info *bd;
  unsigned long flags;
  unsigned int baudrate;
  unsigned long cpu_clk;
  unsigned long bus_clk;
  unsigned long pci_clk;
  unsigned long mem_clk;
#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) || defined(CONFIG_DM_VIDEO);
  unsigned long fb_base;
#endif;
#if defined(CONFIG_POST);
  unsigned long post_log_word;
  unsigned long post_log_res;
  unsigned long post_init_f_time;
#endif;
#ifdef CONFIG_BOARD_TYPES;
  unsigned long board_type;
#endif;
  unsigned long have_console;
#if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER);
  unsigned long precon_buf_idx;
#endif;
  unsigned long env_addr;
  unsigned long env_valid;
  unsigned long env_has_init;
  int env_load_prio;
  unsigned long ram_base;
  unsigned long ram_top;
  unsigned long relocaddr;
  phys_size_t ram_size;
  unsigned long mon_len;
  unsigned long irq_sp;
  unsigned long start_addr_sp;
  unsigned long reloc_off;
  struct global_data *new_gd;
#ifdef CONFIG_DM;
  struct udevice *dm_root;
  struct udevice *dm_root_f;
  struct list_head uclass_root;
#endif;
#ifdef CONFIG_TIMER;
  struct udevice *timer;
#endif;
  const void *fdt_blob;
  void *new_fdt;
  unsigned long fdt_size;
#ifdef CONFIG_OF_LIVE;
  struct device_node *of_root;
#endif;
#if CONFIG_IS_ENABLED(MULTI_DTB_FIT);
  const void *multi_dtb_fit;
#endif;
  struct jt_funcs *jt;
  char env_buf[32];
#ifdef CONFIG_TRACE;
  void *trace_buff;
#endif;
#if defined(CONFIG_SYS_I2C);
  int cur_i2c_bus;
#endif;
  unsigned int timebase_h;
  unsigned int timebase_l;
#if CONFIG_VAL(SYS_MALLOC_F_LEN);
  unsigned long malloc_base;
  unsigned long malloc_limit;
  unsigned long malloc_ptr;
#endif;
#ifdef CONFIG_PCI;
  struct pci_controller *hose;
  phys_addr_t pci_ram_top;
#endif;
#ifdef CONFIG_PCI_BOOTDELAY;
  int pcidelay_done;
#endif;
  struct udevice *cur_serial_dev;
  struct arch_global_data arch;
#ifdef CONFIG_CONSOLE_RECORD;
  struct membuff console_out;
  struct membuff console_in;
#endif;
#ifdef CONFIG_DM_VIDEO;
  ulong video_top;
  ulong video_bottom;
#endif;
#ifdef CONFIG_BOOTSTAGE;
  struct bootstage_data *bootstage;
  struct bootstage_data *new_bootstage;
#endif;
#ifdef CONFIG_LOG;
  int log_drop_count;
  int default_log_level;
  struct list_head log_head;
  int log_fmt;
#endif;
#if CONFIG_IS_ENABLED(BLOBLIST);
  struct bloblist_hdr *bloblist;
  struct bloblist_hdr *new_bloblist;
# ifdef CONFIG_SPL;
  struct spl_handoff *spl_handoff;
# endif;
#endif;
#if defined(CONFIG_TRANSLATION_OFFSET);
  fdt_addr_t translation_offset;
#endif;
#if CONFIG_IS_ENABLED(WDT);
  struct udevice *watchdog_dev;
#endif;
};

Members

bd
board information
flags

global data flags

See enum gd_flags

baudrate
baud rate of the serial interface
cpu_clk
CPU clock rate in Hz
bus_clk
platform clock rate in Hz
pci_clk
PCI clock rate in Hz
mem_clk
memory clock rate in Hz
fb_base
base address of frame buffer memory
post_log_word

active POST tests

post_log_word is a bit mask defining which POST tests are recorded (see constants POST_*).

post_log_res

POST results

post_log_res is a bit mask with the POST results. A bit with value 1 indicates successful execution.

post_init_f_time
time in ms when post_init_f() started
board_type

board type

If a U-Boot configuration supports multiple board types, the actual board type may be stored in this field.

have_console

console is available

A value of 1 indicates that serial_init() was called and a console is available. A value of 0 indicates that console input and output drivers shall not be called.

precon_buf_idx

pre-console buffer index

precon_buf_idx indicates the current position of the buffer used to collect output before the console becomes available

env_addr

address of environment structure

env_addr contains the address of the structure holding the environment variables.

env_valid

environment is valid

See enum env_valid

env_has_init

bit mask indicating environment locations

enum env_location defines which bit relates to which location

env_load_prio
priority of the loaded environment
ram_base
base address of RAM used by U-Boot
ram_top
top address of RAM used by U-Boot
relocaddr

start address of U-Boot in RAM

After relocation this field indicates the address to which U-Boot has been relocated. It can be displayed using the bdinfo command. Its value is needed to display the source code when debugging with GDB using the ‘add-symbol-file u-boot <relocaddr>’ command.

ram_size
RAM size in bytes
mon_len
monitor length in bytes
irq_sp
IRQ stack pointer
start_addr_sp
initial stack pointer address
reloc_off
relocation offset
new_gd
pointer to relocated global data
dm_root
root instance for Driver Model
dm_root_f
pre-relocation root instance
uclass_root
head of core tree
timer
timer instance for Driver Model
fdt_blob
U-Boot’s own device tree, NULL if none
new_fdt
relocated device tree
fdt_size
space reserved for relocated device space
of_root
root node of the live tree
multi_dtb_fit
pointer to uncompressed multi-dtb FIT image
jt

jump table

The jump table contains pointers to exported functions. A pointer to the jump table is passed to standalone applications.

env_buf
buffer for env_get() before reloc
trace_buff

trace buffer

When tracing function in U-Boot this field points to the buffer recording the function calls.

cur_i2c_bus
currently used I2C bus
timebase_h
high 32 bits of timer
timebase_l
low 32 bits of timer
malloc_base
base address of early malloc()
malloc_limit
limit address of early malloc()
malloc_ptr
current address of early malloc()
hose
PCI hose for early use
pci_ram_top
top of region accessible to PCI
pcidelay_done

delay time before scanning of PIC hose expired

If CONFIG_PCI_BOOTDELAY=y, pci_hose_scan() waits for the number of milliseconds defined by environment variable pcidelay before scanning. Once this delay has expired the flag pcidelay_done is set to 1.

cur_serial_dev
current serial device
arch
architecture-specific data
console_out

output buffer for console recording

This buffer is used to collect output during console recording.

console_in

input buffer for console recording

If console recording is activated, this buffer can be used to emulate input.

video_top
top of video frame buffer area
video_bottom
bottom of video frame buffer area
bootstage
boot stage information
new_bootstage
relocated boot stage information
log_drop_count

number of dropped log messages

This counter is incremented for each log message which can not be processed because logging is not yet available as signaled by flag GD_FLG_LOG_READY in flags.

default_log_level

default logging level

For logging devices without filters default_log_level defines the logging level, cf. enum log_level_t.

log_head
list of logging devices
log_fmt

bit mask for logging format

The log_fmt bit mask selects the fields to be shown in log messages. enum log_fmt defines the bits of the bit mask.

bloblist
blob list information
new_bloblist
relocated blob list information
spl_handoff
SPL hand-off information
translation_offset

optional translation offset

See CONFIG_TRANSLATION_OFFSET.

watchdog_dev
watchdog device
gd_board_type()

retrieve board type

Parameters

Return

global board type

enum gd_flags

global data flags

Constants

GD_FLG_RELOC
code was relocated to RAM
GD_FLG_DEVINIT
devices have been initialized
GD_FLG_SILENT
silent mode
GD_FLG_POSTFAIL
critical POST test failed
GD_FLG_POSTSTOP
POST sequence aborted
GD_FLG_LOGINIT
log Buffer has been initialized
GD_FLG_DISABLE_CONSOLE
disable console (in & out)
GD_FLG_ENV_READY
environment imported into hash table
GD_FLG_SERIAL_READY
pre-relocation serial console ready
GD_FLG_FULL_MALLOC_INIT
full malloc() is ready
GD_FLG_SPL_INIT
spl_init() has been called
GD_FLG_SKIP_RELOC
don’t relocate
GD_FLG_RECORD
record console
GD_FLG_ENV_DEFAULT
default variable flag
GD_FLG_SPL_EARLY_INIT
early SPL initialization is done
GD_FLG_LOG_READY
log system is ready for use
GD_FLG_WDT_READY
watchdog is ready for use
GD_FLG_SKIP_LL_INIT
don’t perform low-level initialization
GD_FLG_SMP_READY
SMP initialization is complete

Description

See field flags of struct global_data.