Hi Simon,
Nice to see this being tackled after all the DM discussions I got
involved
in a long time ago (in a galaxy far far away...)
I think we can save a few bytes and simplify the code if we define only
the
base address and current pointer in global_data.h
#ifdef CONFIG_SYS_MALLOC_F_LEN
unsigned long malloc_base; /* limit address */
unsigned long malloc_ptr; /* current address */
#endif
On 2014-07-08 09:19, Simon Glass wrote:
+static int initf_malloc(void)
+{
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+ assert(gd->malloc_base); /* Set up by crt0.S */
+ gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
+ gd->malloc_ptr = 0;
+#endif
#ifdef CONFIG_SYS_MALLOC_F_LEN
assert(gd->malloc_base); /* Set up by crt0.S */
gd->malloc_ptr= gd->malloc_base;
#endif
+
+ return 0;
+}
+
diff --git a/common/board_r.c b/common/board_r.c
index 602a239..86424a0 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -259,6 +259,10 @@ static int initr_malloc(void)
{
ulong malloc_start;
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+ debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n",
gd->malloc_ptr,
+ gd->malloc_ptr / 1024);
+#endif
Use (gd->malloc_ptr - gd->malloc_base) to calculate the size
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+ if (!(gd->flags & GD_FLG_RELOC)) {
+ ulong new_ptr;
+ void *ptr;
+
+ new_ptr = gd->malloc_ptr + bytes;
+ if (new_ptr > gd->malloc_limit)
+ panic("Out of pre-reloc memory");
+ ptr = map_sysmem(gd->malloc_base + gd->malloc_ptr, bytes);
+ gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
+ return ptr;
+ }
+#endif
+
#ifdef CONFIG_SYS_MALLOC_F_LEN
if (!(gd->flags & GD_FLG_RELOC)) {
ulong curr_ptr;
curr_ptr = gd->malloc_ptr;
gd->malloc_ptr = ALIGN(gd->malloc_ptr + bytes,
sizeof(gd->malloc_ptr));
if (gd->malloc_ptr >= (gd->malloc_base +
CONFIG_SYS_MALLOC_F_LEN))
panic("Out of pre-reloc memory");
return map_sysmem(curr_ptr, bytes);
#endif
Regards,
Graeme
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot