+static unsigned long load_elf_image_phdr(unsigned long addr);
+static unsigned long load_elf_image_shdr(unsigned long addr);
+
+/* Allow ports to override the default behavior */
+__attribute__((weak))
+unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
+ int argc, char * const argv[])
+{
+ unsigned long ret;
+
+ /*
+ * QNX images require the data cache is disabled.
+ * Data cache is already flushed, so just turn it off.
+ */
+ int dcache = dcache_status();
+ if (dcache)
+ dcache_disable();
+
+ /*
+ * pass address parameter as argv[0] (aka command name),
+ * and all remaining args
+ */
+ ret = entry(argc, argv);
+
+ if (dcache)
+ dcache_enable();
+
+ return ret;
+}
+
+/* ======================================================================
+ * Determine if a valid ELF image exists at the given memory location.
+ * First looks at the ELF header magic field, the makes sure that it is
+ * executable and makes sure that it is for a PowerPC.
+ * ====================================================================== */
+int valid_elf_image(unsigned long addr)
+{
+ Elf32_Ehdr *ehdr; /* Elf header structure pointer */
+
+ /* -------------------------------------------------- */
+
+ ehdr = (Elf32_Ehdr *) addr;
+
+ if (!IS_ELF(*ehdr)) {
+ printf("## No elf image at address 0x%08lx\n", addr);
+ return 0;
+ }
+
+ if (ehdr->e_type != ET_EXEC) {
+ printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
+ return 0;
+ }
+
+#if 0
+ if (ehdr->e_machine != EM_PPC) {
+ printf("## Not a PowerPC elf image at address 0x%08lx\n", addr);
+ return 0;
+ }