[PATCH 1/2] support loading kernels/initrds > 6MB

Scott Moser ssmoser at us.ibm.com
Sat Oct 6 01:07:44 EST 2007


  The patch below moves the "search-for-prom_claim'able" routine that
  was present in load_elf64 and load_elf32 to a function named
  prom_claim_chunk.  This reduces the code-snippit duplication and makes
  the function available for of_net_open.

diff --git a/include/prom.h b/include/prom.h
index b48e230..8083f2b 100644
--- a/include/prom.h
+++ b/include/prom.h
@@ -37,6 +37,7 @@ typedef void *phandle;
 #define PROM_INVALID_HANDLE	((prom_handle)-1UL)
 #define BOOTDEVSZ               (2048) /* iscsi args can be in excess of 1040 bytes */
 #define TOK_ISCSI               "iscsi"
+#define PROM_CLAIM_MAX_ADDR	0x8000000
 
 struct prom_args;
 typedef int (*prom_entry)(struct prom_args *);
@@ -85,6 +86,7 @@ int prom_set_color(prom_handle device, int color, int r, int g, int b);
 
 /* memory */
 
+void *prom_claim_chunk(void *virt, unsigned int size, unsigned int align);
 void *prom_claim (void *virt, unsigned int size, unsigned int align);
 void prom_release(void *virt, unsigned int size);
 void prom_map (void *phys, void *virt, int size);
diff --git a/second/prom.c b/second/prom.c
index bd2451e..a30f997 100644
--- a/second/prom.c
+++ b/second/prom.c
@@ -568,6 +568,25 @@ prom_sleep (int seconds)
      while (prom_getms() <= end);
 }
 
+/* if address given is claimed look for other addresses to get the needed
+ * space before giving up
+ */
+void *
+prom_claim_chunk(void *virt, unsigned int size, unsigned int align)
+{
+     void *found, *addr;
+     for(addr=virt; addr <= (void*)PROM_CLAIM_MAX_ADDR;
+         addr+=(0x100000/sizeof(addr))) {
+          found = prom_claim(addr, size, 0);
+          if (found != (void *)-1) {
+               DEBUG_F("claimed %i at 0x%x (0x%x)\n",size,(int)found,(int)virt);
+               return(found);
+          }
+     }
+     prom_printf("Claim error, can't allocate %x at 0x%x\n",size,(int)virt);
+     return((void*)-1);
+}
+
 void *
 prom_claim (void *virt, unsigned int size, unsigned int align)
 {
diff --git a/second/yaboot.c b/second/yaboot.c
index 4e92f29..94fce15 100644
--- a/second/yaboot.c
+++ b/second/yaboot.c
@@ -1235,7 +1235,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo)
      Elf32_Ehdr		*e = &(loadinfo->elf.elf32hdr);
      Elf32_Phdr		*p, *ph;
      int			size = sizeof(Elf32_Ehdr) - sizeof(Elf_Ident);
-     unsigned long	addr, loadaddr;
+     unsigned long	loadaddr;
 
      /* Read the rest of the Elf header... */
      if ((*(file->fs->read))(file, size, &e->e_version) < size) {
@@ -1323,13 +1323,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo)
           loadaddr = loadinfo->load_loc;
      }
 
-     /* On some systems, loadaddr may already be claimed, so try some
-      * other nearby addresses before giving up.
-      */
-     for(addr=loadaddr; addr <= loadaddr * 8 ;addr+=0x100000) {
-	  loadinfo->base = prom_claim((void *)addr, loadinfo->memsize, 0);
-	  if (loadinfo->base != (void *)-1) break;
-     }
+     loadinfo->base = prom_claim_chunk((void *)loadaddr, loadinfo->memsize, 0);
      if (loadinfo->base == (void *)-1) {
 	  prom_printf("Claim error, can't allocate kernel memory\n");
 	  goto bail;
@@ -1379,7 +1373,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo)
      Elf64_Ehdr		*e = &(loadinfo->elf.elf64hdr);
      Elf64_Phdr		*p, *ph;
      int			size = sizeof(Elf64_Ehdr) - sizeof(Elf_Ident);
-     unsigned long	addr, loadaddr;
+     unsigned long	loadaddr;
 
      /* Read the rest of the Elf header... */
      if ((*(file->fs->read))(file, size, &e->e_version) < size) {
@@ -1467,13 +1461,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo)
           loadaddr = e->e_entry;
      }
 
-     /* On some systems, loadaddr may already be claimed, so try some
-      * other nearby addresses before giving up.
-      */
-     for(addr=loadaddr; addr <= loadaddr * 8 ;addr+=0x100000) {
-	  loadinfo->base = prom_claim((void *)addr, loadinfo->memsize, 0);
-	  if (loadinfo->base != (void *)-1) break;
-     }
+     loadinfo->base = prom_claim_chunk((void *)loadaddr, loadinfo->memsize, 0);
      if (loadinfo->base == (void *)-1) {
 	  prom_printf("Claim error, can't allocate kernel memory\n");
 	  goto bail;




More information about the Yaboot-devel mailing list