Before Uboot started the first stage, the pointer pointed to the START_ARMBOOT function, which is also
Is the start of the second phase of Uboot start and the second phase of Uboot start is mostly done in this function
Of
DECLARE_GLOBAL_DATA_PTR, this macro has this macro in most of the files, the macro
The actual definition is in include/asm-arm/global_data.h
#define DECLARE_GLOBAL_DATA_PTR Register volatile gd_t *gd asm ("R8")
This macro means: Define a global variable named GD, the global variable is a pointer type, accounting for 4 bytes, with volatile modification to represent the variable; The register is modified to indicate that the variable should be placed as far as possible in the Register; ASM ("R8") is a syntax supported by GCC, It means to put GD in the register R8.
Comprehensive analysis:declare_global_data_ptr is defined as a global variable to be placed in the register R8, called GD, whose type is a pointer to the gd_t type variable. gd_t defines a number of global variables, all of which are used by the entire uboot, with a bd_t type of pointer BD, pointing to the struct bd_info, which defines the global variables (such as IP address serial baud rate) that are first closed to the Development Board hardware .
Global variables GD is an important global variable in uboot (it is accurate to say that the global variable is a struct, there is a lot of content, the structure of the composition is the uboot commonly used in all global variables), because GD is often accessed, so put in registers to improve access efficiency.
Gd_base = Cfg_uboot_base + cfg_uboot_size-cfg_malloc_len-cfg_stack_size-sizeof (gd_t);
UBOOT District:cfg_uboot_base (33e00000) +cfg_uboot_size(the actual size of UBOOT, we gave here 2M)
Heap area: Length of Cfg_malloc_len, actual length is 912KB
Stack area: length
GD: sizeof (gd_t) length, actual 36 bytes
BD: sizeof (bd_t) length, actual length is about 44 bytes
So the approximate location of the gd_base is from the Uboot start address (33e00000) up the 624KB position.
gd = (gd_t*) gd_base;
//above has been gd_base is a memory address, which is then forced into a pointer by forcing the type conversion and assigned to GD so that GD points to the memory space
memset ((void*) GD, 0, sizeof (gd_t)); GD->BD = (bd_t*) ((char*) gd-sizeof (bd_t)); memset (gd->bd, 0, sizeof (bd_t));
typedef struct bd_info { int bi_baudrate; /* serial console baudrate */ unsigned long bi_ip_addr; / * IP ADDRESS */    UNSIGNED CHAR    BI_ENETADDR[6] ; /* ethernet adress */ struct environment_s *bi_env; ulong bi_arch_number; /* unique id for this board */ ulong bi_boot_params; /* where this board Expects params */ struct /* RAM configuration */ { ulong start; ulong size; } bi_dram[CONFIG_NR_DRAM_BANKS]; typedef struct global_data { bd_t *bd; unsigned long flags; unsigned long baudrate; unsigned long have_console; /* serial_init () was called */ unsigned long reloc_off; /*&nbsP relocation offset */ unsigned long env_addr; /* Address of Environment struct */ unsigned long env_valid; /* checksum of environment valid? */ unsigned long fb_base ; /* base address of frame buffer */
These are the contents of the structure that the two global variables of GD and BD refer to
Uboot Transplant (v) The second phase of--uboot initiation (GD and BD)