From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Chou Date: Sat, 14 Nov 2015 14:23:31 +0800 Subject: [U-Boot] [PATCH v3] Fix board init code to use a valid C runtime environment In-Reply-To: <1447425803-24281-1-git-send-email-albert.u.boot@aribaud.net> References: <1447425803-24281-1-git-send-email-albert.u.boot@aribaud.net> Message-ID: <5646D363.6000404@wytron.com.tw> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Albert, On 2015?11?13? 22:43, Albert ARIBAUD wrote: > +/* > + * Initialize reserved space (which has been safely allocated on the C > + * stack from the C runtime environment handling code). > + * > + * Do not use 'gd->' until arch_setup_gd() has been called! > + */ > + > +void board_init_f_init_reserve(ulong base) > { > struct global_data *gd_ptr; > #ifndef _USE_MEMCPY > int *ptr; > #endif > > - /* Leave space for the stack we are running with now */ > - top -= 0x40; > + /* > + * clear GD entirely > + */ > > - top -= sizeof(struct global_data); > - top = ALIGN(top, 16); > - gd_ptr = (struct global_data *)top; > + gd_ptr = (struct global_data *)base; > + /* go down one GD plus 16-byte alignment */ > + base += roundup(sizeof(struct global_data), 16); Maybe it can keep the original order, top--gd--malloc--base. #if defined(CONFIG_SYS_MALLOC_F) base += CONFIG_SYS_MALLOC_F_LEN; #endif gd_ptr = (struct global_data *)base; > + /* zero the area */ > #ifdef _USE_MEMCPY > memset(gd_ptr, '\0', sizeof(*gd)); > #else > for (ptr = (int *)gd_ptr; ptr < (int *)(gd_ptr + 1); ) > *ptr++ = 0; > #endif > + /* set GD unless architecture did it already */ > +#if !defined(CONFIG_X86) && !defined(CONFIG_SYS_THUMB_BUILD) > arch_setup_gd(gd_ptr); > +#endif > + > + /* > + * record malloc arena start > + */ > > #if defined(CONFIG_SYS_MALLOC_F) > - top -= CONFIG_SYS_MALLOC_F_LEN; > - gd->malloc_base = top; > + /* go down one malloc arena */ > + gd->malloc_base = base; #if defined(CONFIG_SYS_MALLOC_F) base -= CONFIG_SYS_MALLOC_F_LEN; gd->malloc_base = base; #endif > + base += CONFIG_SYS_MALLOC_F_LEN; Useless statement. Best regards, Thomas