public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] strings: use puts() rather than printf()
@ 2008-11-04 21:03 Mike Frysinger
  2008-11-04 21:03 ` [U-Boot] [PATCH v2] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs Mike Frysinger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mike Frysinger @ 2008-11-04 21:03 UTC (permalink / raw)
  To: u-boot

When running `strings` on really long strings, the stack tends to get
smashed due to printf().  Switch to puts() instead since we're only passing
the data through.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 common/cmd_strings.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/common/cmd_strings.c b/common/cmd_strings.c
index db54f29..7d05cf8 100644
--- a/common/cmd_strings.c
+++ b/common/cmd_strings.c
@@ -29,7 +29,8 @@ int do_strings(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 	char *addr = start_addr;
 	do {
-		printf("%s\n", addr);
+		puts(addr);
+		puts("\n");
 		addr += strlen(addr) + 1;
 	} while (addr[0] && addr < last_addr);
 
-- 
1.6.0.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v2] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs
  2008-11-04 21:03 [U-Boot] [PATCH] strings: use puts() rather than printf() Mike Frysinger
@ 2008-11-04 21:03 ` Mike Frysinger
  2008-11-05 17:14 ` [U-Boot] [PATCH] strings: use puts() rather than printf() Scott Wood
  2008-12-07  0:17 ` Wolfgang Denk
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2008-11-04 21:03 UTC (permalink / raw)
  To: u-boot

The current ELF loading function does a lot of work above and beyond a
simple "loading".  It ignores the real load addresses and loads things into
their virtual (runtime) address.  This is undesirable when we just want it
to load an ELF and let the ELF do the actual C runtime init.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
	- add a call to flush_cache() to make sure icache/dcache are in sync

 common/cmd_elf.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/common/cmd_elf.c b/common/cmd_elf.c
index 3ebb6d9..d0515b9 100644
--- a/common/cmd_elf.c
+++ b/common/cmd_elf.c
@@ -276,6 +276,33 @@ int valid_elf_image (unsigned long addr)
  * A very simple elf loader, assumes the image is valid, returns the
  * entry point address.
  * ====================================================================== */
+#ifdef CONFIG_ELF_SIMPLE_LOAD
+unsigned long load_elf_image (unsigned long addr)
+{
+	Elf32_Ehdr *ehdr;
+	Elf32_Phdr *phdr;
+	unsigned long entry;
+	size_t i;
+
+	ehdr = (Elf32_Ehdr *) addr;
+	phdr = (Elf32_Phdr *) (addr + ehdr->e_phoff);
+
+	entry = ehdr->e_entry;
+
+	/* Load each program header */
+	for (i = 0; i < ehdr->e_phnum; ++i) {
+		void *dst = (void *) phdr->p_paddr;
+		void *src = (void *) addr + phdr->p_offset;
+		printf ("Loading phdr %i to 0x%p (%i bytes)\n",
+		        i, dst, phdr->p_filesz);
+		memcpy (dst, src, phdr->p_filesz);
+		flush_cache ((unsigned long)dst, phdr->p_filesz);
+		++phdr;
+	}
+
+	return entry;
+}
+#else
 unsigned long load_elf_image (unsigned long addr)
 {
 	Elf32_Ehdr *ehdr;		/* Elf header structure pointer     */
@@ -327,6 +354,7 @@ unsigned long load_elf_image (unsigned long addr)
 
 	return ehdr->e_entry;
 }
+#endif
 
 /* ====================================================================== */
 U_BOOT_CMD(
-- 
1.6.0.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] strings: use puts() rather than printf()
  2008-11-04 21:03 [U-Boot] [PATCH] strings: use puts() rather than printf() Mike Frysinger
  2008-11-04 21:03 ` [U-Boot] [PATCH v2] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs Mike Frysinger
@ 2008-11-05 17:14 ` Scott Wood
  2008-12-07  0:17 ` Wolfgang Denk
  2 siblings, 0 replies; 4+ messages in thread
From: Scott Wood @ 2008-11-05 17:14 UTC (permalink / raw)
  To: u-boot

Mike Frysinger wrote:
> When running `strings` on really long strings, the stack tends to get
> smashed due to printf().  Switch to puts() instead since we're only passing
> the data through.

...which raises the question of why we don't have vsnprintf().

-Scott

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] strings: use puts() rather than printf()
  2008-11-04 21:03 [U-Boot] [PATCH] strings: use puts() rather than printf() Mike Frysinger
  2008-11-04 21:03 ` [U-Boot] [PATCH v2] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs Mike Frysinger
  2008-11-05 17:14 ` [U-Boot] [PATCH] strings: use puts() rather than printf() Scott Wood
@ 2008-12-07  0:17 ` Wolfgang Denk
  2 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Denk @ 2008-12-07  0:17 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1225832627-10248-1-git-send-email-vapier@gentoo.org> you wrote:
> When running `strings` on really long strings, the stack tends to get
> smashed due to printf().  Switch to puts() instead since we're only passing
> the data through.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
>  common/cmd_strings.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Never call a man a fool.  Borrow from him.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-07  0:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-04 21:03 [U-Boot] [PATCH] strings: use puts() rather than printf() Mike Frysinger
2008-11-04 21:03 ` [U-Boot] [PATCH v2] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs Mike Frysinger
2008-11-05 17:14 ` [U-Boot] [PATCH] strings: use puts() rather than printf() Scott Wood
2008-12-07  0:17 ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox