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 |
Nios II |
gp |
PowerPC |
r2 |
RISC-V |
gp (x3) |
SuperH |
r13 |
x86 32bit |
fs |
The sandbox, x86_64, and Xtensa are notable exceptions.
Current implementation uses a register for the GD pointer because this results in smaller code. However, using plain global data for the GD pointer would be possible too (and simpler, as it does not require the reservation of a specific register for it), but the resulting code is bigger.
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.
Guidelines
The global_data structure is placed in some memory which is available very early
after boot to allow for a minimum set of global variables during system
initialisation (until the memory controller is set up and RAM can be used). It
is the primary data structure passed from pre-relocation U-Boot to
post-relocation, i.e. from board_init_f() to board_init_r().
The global_data struct exists for the lifetime of U-Boot. Since the struct is
used by all architectures, fields added should be useful for most architectures.
Fields which are only needed on one or two architectures can be placed in the
architecture-specific struct arch_global_data.
In any case the struct should be kept small, since it uses precious SRAM on many boards.
SPL also uses global data, as well as U-Boot proper, so take care to avoid adding fields to SPL which are not actually used by SPL. You can create access functions or macros in the header file to avoid filling the C code with #ifdefs.
A flags word is available, which provides a convenient means to track the state of various initialisation phases within U-Boot.
Global data structure
-
struct global_data
global data structure
Definition
struct global_data {
struct bd_info *bd;
struct global_data *new_gd;
const void *fdt_blob;
struct udevice *cur_serial_dev;
#ifndef CONFIG_XPL_BUILD;
struct jt_funcs *jt;
struct board_f *boardf;
#endif;
phys_size_t ram_size;
phys_addr_t ram_top;
unsigned long flags;
unsigned long cpu_clk;
#if CONFIG_IS_ENABLED(ENV_SUPPORT);
unsigned long env_addr;
#endif ;
unsigned long ram_base;
unsigned long relocaddr;
unsigned long irq_sp;
unsigned long start_addr_sp;
unsigned long reloc_off;
unsigned int bus_clk;
unsigned int mem_clk;
unsigned int mon_len;
unsigned int baudrate;
#if CONFIG_IS_ENABLED(ENV_SUPPORT);
unsigned short env_has_init;
unsigned char env_valid;
char env_load_prio;
char env_buf[32];
#endif ;
enum fdt_source_t fdt_src;
struct arch_global_data arch;
struct list_head dmtag_list;
unsigned int timebase_h;
unsigned int timebase_l;
#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;
#if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER);
long precon_buf_idx;
#endif;
#ifdef CONFIG_DM;
struct udevice *dm_root;
struct list_head uclass_root_s;
struct list_head *uclass_root;
# if CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT);
struct driver_rt *dm_driver_rt;
# endif;
#if CONFIG_IS_ENABLED(OF_PLATDATA_RT);
struct udevice_rt *dm_udevice_rt;
void *dm_priv_base;
# endif;
#endif;
#ifdef CONFIG_TIMER;
struct udevice *timer;
#endif;
#if CONFIG_IS_ENABLED(OF_LIVE);
struct device_node *of_root;
#endif;
#if CONFIG_IS_ENABLED(MULTI_DTB_FIT);
const void *multi_dtb_fit;
#endif;
#ifdef CONFIG_TRACE;
void *trace_buff;
#endif;
#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY);
int cur_i2c_bus;
#endif;
#if CONFIG_IS_ENABLED(CMD_BDINFO_EXTRA);
unsigned long malloc_start;
#endif;
#if CONFIG_IS_ENABLED(SYS_MALLOC_F);
unsigned long malloc_base;
unsigned int malloc_limit;
unsigned int malloc_ptr;
#endif;
#ifdef CONFIG_CONSOLE_RECORD;
struct membuf console_out;
struct membuf console_in;
#endif;
#if CONFIG_IS_ENABLED(VIDEO);
ulong video_top;
ulong video_bottom;
#endif;
#ifdef CONFIG_BOOTSTAGE;
struct bootstage_data *bootstage;
#endif;
#ifdef CONFIG_LOG;
struct list_head log_head;
int log_drop_count;
char default_log_level;
char log_fmt;
unsigned char logc_prev;
unsigned char logl_prev;
bool log_cont;
bool processing_msg;
#endif;
#if CONFIG_IS_ENABLED(BLOBLIST);
struct bloblist_hdr *bloblist;
#endif;
#if CONFIG_IS_ENABLED(HANDOFF);
struct spl_handoff *spl_handoff;
#endif;
#if defined(CONFIG_TRANSLATION_OFFSET);
fdt_addr_t translation_offset;
#endif;
#ifdef CONFIG_ACPI;
struct acpi_ctx *acpi_ctx;
ulong acpi_start;
#endif;
#if CONFIG_IS_ENABLED(GENERATE_SMBIOS_TABLE);
char *smbios_version;
#endif;
#if CONFIG_IS_ENABLED(EVENT);
struct event_state event_state;
#endif;
#if CONFIG_IS_ENABLED(CYCLIC);
struct hlist_head cyclic_list;
#endif;
#if CONFIG_IS_ENABLED(UPL);
struct upl *upl;
#endif;
};
Members
bdboard information
new_gdpointer to relocated global data
fdt_blobU-Boot’s own device tree, NULL if none
cur_serial_devcurrent serial device
jtjump table
The jump table contains pointers to exported functions. A pointer to the jump table is passed to standalone applications.
boardfinformation only used before relocation
ram_sizeRAM size in bytes
ram_toptop address of RAM used by U-Boot
flagsglobal data flags
See
enum gd_flagscpu_clkCPU clock rate in Hz
env_addraddress of environment structure
env_addr contains the address of the structure holding the environment variables.
ram_basebase address of RAM used by U-Boot
relocaddrstart 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.
irq_spIRQ stack pointer
start_addr_spinitial stack pointer address
reloc_offrelocation offset
bus_clkplatform clock rate in Hz
mem_clkmemory clock rate in Hz
mon_lenmonitor length in bytes
baudratebaud rate of the serial interface
env_has_initbit mask indicating environment locations
enum env_locationdefines which bit relates to which locationenv_validenvironment is valid
See
enum env_validenv_load_priopriority of the loaded environment
env_bufbuffer for env_get() before reloc
fdt_srcSource of FDT
archarchitecture-specific data
dmtag_listList of DM tags
timebase_hhigh 32 bits of timer
timebase_llow 32 bits of timer
post_log_wordactive POST tests
post_log_word is a bit mask defining which POST tests are recorded (see constants POST_*).
post_log_resPOST results
post_log_res is a bit mask with the POST results. A bit with value 1 indicates successful execution.
post_init_f_timetime in ms when post_init_f() started
board_typeboard type
If a U-Boot configuration supports multiple board types, the actual board type may be stored in this field.
precon_buf_idxpre-console buffer index
precon_buf_idx indicates the current position of the buffer used to collect output before the console becomes available. When negative, the pre-console buffer is temporarily disabled (used when the pre-console buffer is being written out, to prevent adding its contents to itself).
dm_rootroot instance for Driver Model
uclass_root_shead of core tree when uclasses are not in read-only memory.
When uclasses are in read-only memory, uclass_root_s is not used and uclass_root points to the root node generated by dtoc.
uclass_rootpointer to head of core tree, if uclasses are in read-only memory and cannot be adjusted to use uclass_root as a list head.
When not in read-only memory, uclass_root_s is used to hold the uclass root, and uclass_root points to the address of uclass_root_s.
dm_driver_rtDynamic info about the driver
dm_udevice_rtDynamic info about the udevice
dm_priv_baseBase address of the priv/plat region used when udevices and uclasses are in read-only memory. This is NULL if not used
timertimer instance for Driver Model
of_rootroot node of the live tree
multi_dtb_fitpointer to uncompressed multi-dtb FIT image
trace_bufftrace buffer
When tracing function in U-Boot this field points to the buffer recording the function calls.
cur_i2c_buscurrently used I2C bus
malloc_startstart of malloc() region
malloc_basebase address of early malloc()
malloc_limitmaximum size of early malloc()
malloc_ptrcurrently used bytes of early malloc()
console_outoutput buffer for console recording
This buffer is used to collect output during console recording.
console_ininput buffer for console recording
If console recording is activated, this buffer can be used to emulate input.
video_toptop of video frame buffer area
video_bottombottom of video frame buffer area
bootstageboot stage information
log_headlist of logging devices
log_drop_countnumber 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_READYin flags.default_log_leveldefault logging level
For logging devices without filters default_log_level defines the logging level, cf.
enum log_level_t.log_fmtbit mask for logging format
The log_fmt bit mask selects the fields to be shown in log messages.
enum log_fmtdefines the bits of the bit mask.logc_prevlogging category of previous message
This value is used as logging category for continuation messages.
logl_prevlogging level of the previous message
This value is used as logging level for continuation messages.
log_contPrevious log line did not finished wtih n
This allows for chained log messages on the same line
processing_msga log message is being processed
This flag is used to suppress the creation of additional messages while another message is being processed.
bloblistblob list information
spl_handoffSPL hand-off information
translation_offsetoptional translation offset
See CONFIG_TRANSLATION_OFFSET.
acpi_ctxACPI context pointer
acpi_startStart address of ACPI tables
smbios_versionPoints to SMBIOS type 0 version
event_statePoints to the current state of events
cyclic_listlist of registered cyclic functions
uplUniversal Payload-handoff information
-
gd_board_type
gd_board_type ()
retrieve board type
Parameters
Return
global board type
-
enum gd_flags
global data flags
Constants
GD_FLG_RELOCcode was relocated to RAM
GD_FLG_DEVINITdevices have been initialized
GD_FLG_SILENTsilent mode
GD_FLG_POSTFAILcritical POST test failed
GD_FLG_POSTSTOPPOST sequence aborted
GD_FLG_LOGINITlog Buffer has been initialized
GD_FLG_DISABLE_CONSOLEdisable console (in & out)
GD_FLG_ENV_READYenvironment imported into hash table
GD_FLG_SERIAL_READYpre-relocation serial console ready
GD_FLG_FULL_MALLOC_INITfull malloc() is ready
GD_FLG_SPL_INITspl_init() has been called
GD_FLG_SKIP_RELOCdon’t relocate
GD_FLG_RECORDrecord console
GD_FLG_RECORD_OVFrecord console overflow
GD_FLG_ENV_DEFAULTdefault variable flag
GD_FLG_SPL_EARLY_INITearly SPL initialization is done
GD_FLG_LOG_READYlog system is ready for use
GD_FLG_CYCLIC_RUNNINGcyclic_run is in progress
GD_FLG_SKIP_LL_INITdon’t perform low-level initialization
GD_FLG_SMP_READYSMP initialization is complete
GD_FLG_FDT_CHANGEDDevice tree change has been detected by tests
GD_FLG_DM_DEADDriver model is not accessible. This can be set when the memory used to holds its tables has been mapped out.
GD_FLG_BLOBLIST_READYbloblist is ready for use
GD_FLG_HUSH_OLD_PARSERUse hush old parser.
GD_FLG_HUSH_MODERN_PARSERUse hush 2021 parser.
GD_FLG_UPLRead/write a Universal Payload (UPL) handoff
GD_FLG_HAVE_CONSOLEserial_init() was called and a console is available. When not set, indicates that console input and output drivers shall not be called.
Description
See field flags of struct global_data.