[OpenBIOS] [commit] r724 - trunk/openbios-devel/libopenbios

repository service svn at openbios.org
Fri Apr 2 12:28:49 CEST 2010


Author: mcayland
Date: Fri Apr  2 12:28:48 2010
New Revision: 724
URL: http://tracker.coreboot.org/trac/openbios/changeset/724

Log:
Finish the use of saved-program-state within the loaders. This involves 2 changes: firstly ensure that the saved-program-state 
is being set correctly in all of the loaders, and secondly we change the bootinfo loader so that the bootscript is executed as 
part of init-program and not go. This seems to reflect the idea of execute-buffer in OpenBOOT that any Forth code is executed 
directly during init-program, rather than being deferred to go.

Note: the latter change is fairly simple, but I have been unable to test it myself other than verifying it compiles.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>

Modified:
   trunk/openbios-devel/libopenbios/bootinfo_load.c
   trunk/openbios-devel/libopenbios/elf_load.c
   trunk/openbios-devel/libopenbios/fcode_load.c
   trunk/openbios-devel/libopenbios/xcoff_load.c

Modified: trunk/openbios-devel/libopenbios/bootinfo_load.c
==============================================================================
--- trunk/openbios-devel/libopenbios/bootinfo_load.c	Fri Apr  2 11:18:51 2010	(r723)
+++ trunk/openbios-devel/libopenbios/bootinfo_load.c	Fri Apr  2 12:28:48 2010	(r724)
@@ -126,7 +126,7 @@
 	char *base;
 	int proplen;
 	phandle_t chosen;
-	int tag, taglen, script, scriptlen, entity, chrp;
+	int tag, taglen, script, scriptlen, scriptvalid, entity, chrp;
 	char tagbuf[128], c;
 	char *device, *filename, *directory;
 	int partition;
@@ -135,7 +135,7 @@
         char *tmp;
 	char bootpath[1024];
 
-	feval("0 state-valid !");
+	/* Parse the boot script */
 
 	chosen = find_dev("/chosen");
 	tmp = get_property(chosen, "bootpath", &proplen);
@@ -169,6 +169,7 @@
 	tag = 0;
 	taglen = 0;
 	script = 0;
+	scriptvalid = 0;
 	scriptlen = 0;
 	entity = 0;
 	current = 0;
@@ -197,7 +198,7 @@
 					DPRINTF("got bootscript %s\n",
 						bootscript);
 
-					feval("-1 state-valid !");
+					scriptvalid = -1;
 
 					break;
 				} else if (strncasecmp(tagbuf, "/chrp-boot", 10) == 0)
@@ -246,7 +247,10 @@
 			bootscript[scriptlen++] = c;
 		}
 	}
-	/* FIXME: should initialize saved-program-state. */
-	push_str(bootscript);
-	feval("bootinfo-size ! bootinfo-entry !");
+
+	/* If the payload is bootinfo then we execute it immediately */
+	if (scriptvalid)
+		feval(bootscript);
+	else
+		DPRINTF("Unable to parse bootinfo bootscript\n");
 }

Modified: trunk/openbios-devel/libopenbios/elf_load.c
==============================================================================
--- trunk/openbios-devel/libopenbios/elf_load.c	Fri Apr  2 11:18:51 2010	(r723)
+++ trunk/openbios-devel/libopenbios/elf_load.c	Fri Apr  2 12:28:48 2010	(r724)
@@ -473,7 +473,7 @@
 	int i;
 	Elf_ehdr *ehdr;
 	Elf_phdr *phdr;
-	size_t size;
+	size_t size, total_size = 0;
 	char *addr;
 	cell tmp;
 
@@ -483,6 +483,12 @@
 	base = (char*)POP();
 
 	ehdr = (Elf_ehdr *)base;
+
+	if (!is_elf(ehdr)) {
+		debug("Not a valid ELF memory image\n");
+		return;
+	}
+
 	phdr = (Elf_phdr *)(base + ehdr->e_phoff);
 
 	for (i = 0; i < ehdr->e_phnum; i++) {
@@ -508,12 +514,20 @@
 		addr = (char *)tmp;
 
 		memcpy(addr, base + phdr[i].p_offset, size);
+
+		total_size += size;
+
 #ifdef CONFIG_PPC
 		flush_icache_range( addr, addr + size );
 #endif
 	}
-	/* FIXME: should initialize saved-program-state. */
+
+	// Initialise saved-program-state
 	PUSH(ehdr->e_entry);
-	feval("elf-entry !");
+	feval("saved-program-state >sps.entry !");
+	PUSH(total_size);
+	feval("saved-program-state >sps.file-size !");
+	feval("elf saved-program-state >sps.file-type !");
+
 	feval("-1 state-valid !");
 }

Modified: trunk/openbios-devel/libopenbios/fcode_load.c
==============================================================================
--- trunk/openbios-devel/libopenbios/fcode_load.c	Fri Apr  2 11:18:51 2010	(r723)
+++ trunk/openbios-devel/libopenbios/fcode_load.c	Fri Apr  2 12:28:48 2010	(r724)
@@ -95,6 +95,12 @@
 
 	fword("load-base");
 	address = POP();
+
+	if (!is_fcode((unsigned char *)address)) {
+		debug("Not a valid Fcode memory image\n");
+		return;
+	}
+
 	PUSH(address);
 	PUSH(1);
 	fword("byte-load");

Modified: trunk/openbios-devel/libopenbios/xcoff_load.c
==============================================================================
--- trunk/openbios-devel/libopenbios/xcoff_load.c	Fri Apr  2 11:18:51 2010	(r723)
+++ trunk/openbios-devel/libopenbios/xcoff_load.c	Fri Apr  2 12:28:48 2010	(r724)
@@ -58,6 +58,7 @@
 	COFF_aouthdr_t *ahdr;
 	COFF_scnhdr_t *shdr;
 	uint32_t offset;
+	size_t total_size = 0;
 	int i;
 
 	feval("0 state-valid !");
@@ -112,6 +113,7 @@
 
 			memcpy((char*)shdr->s_vaddr, base + shdr->s_scnptr,
 			       shdr->s_size);
+			total_size += shdr->s_size;
 #ifdef CONFIG_PPC
 			flush_icache_range((char*)shdr->s_vaddr,
 					 (char*)(shdr->s_vaddr + shdr->s_size));
@@ -120,22 +122,26 @@
 
 			memcpy((char*)shdr->s_vaddr, base + shdr->s_scnptr,
 			       shdr->s_size);
+			total_size += shdr->s_size;
 
 		} else if (strcmp(shdr->s_name, ".bss") == 0) {
 
 			memset((void *)shdr->s_vaddr, 0, shdr->s_size);
-
+			total_size += shdr->s_size;
 		} else {
 			DPRINTF("    Skip '%s' section\n", shdr->s_name);
 		}
 		offset += sizeof(COFF_scnhdr_t);
 	}
 
-	/* FIXME: should initialize saved-program-state. */
-
 	DPRINTF("XCOFF entry point: %x\n", *(uint32_t*)ahdr->entry);
+
+	// Initialise saved-program-state
 	PUSH(*(uint32_t*)ahdr->entry);
-	feval("xcoff-entry !");
+	feval("saved-program-state >sps.entry !");
+	PUSH(total_size);
+	feval("saved-program-state >sps.file-size !");
+	feval("xcoff saved-program-state >sps.file-type !");
 
 	feval("-1 state-valid !");
 }



More information about the OpenBIOS mailing list