Skip to contentSkip to conversation

Always load PowerPC kernel to KERNEL_LOAD_ADDR

PATCH In review Alexander Graf 3 participants 6 messages Jan 25, 2009 – Jan 26, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Always load PowerPC kernel to KERNEL_LOAD_ADDR

Linux changed its physical address location in the elf header from 0xc0000000 to 0 on 2.6.25, causing later kernels to fail booting with the -kernel option.

This patch assures that the lowest segment in the elf binary is loaded to KERNEL_LOAD_ADDR, which is where the firmware expects it.

With this patch applied, I was able to successfully boot a 2.6.18 and a 2.6.27 Linux kernel using the -kernel option.

---
 hw/ppc_oldworld.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/ppc_oldworld.c +3 -1
index 042a40f..f64884b 100644
@@ -207,9 +207,11 @@ static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size,
     }
 
     if (linux_boot) {
+        uint64_t lowaddr = 0;
         kernel_base = KERNEL_LOAD_ADDR;
         /* now we can load the kernel */
-        kernel_size = load_elf(kernel_filename, kernel_base - 0xc0000000ULL,
+        load_elf(kernel_filename, 0, NULL, &lowaddr, NULL);
+        kernel_size = load_elf(kernel_filename, kernel_base - lowaddr,
                                NULL, NULL, NULL);
         if (kernel_size < 0)
             kernel_size = load_aout(kernel_filename, kernel_base,
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 20 lines · Alexander Graf

Linux changed its physical address location in the elf header from 0xc0000000 to 0 on 2.6.25, causing later kernels to fail booting with the -kernel option.

This patch assures that the lowest segment in the elf binary is loaded to KERNEL_LOAD_ADDR, which is where the firmware expects it.

With this patch applied, I was able to successfully boot a 2.6.18 and a 2.6.27 Linux kernel using the -kernel option.

---
 hw/ppc_oldworld.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/ppc_oldworld.c +0 -0
index 042a40f..f64884b 100644

hw/ppc_oldworld.c static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size, · line 215

Quoted 10 lines
hw/ppc_oldworld.c +3 -1
@@ -207,9 +207,11 @@ static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size,
     }
 
     if (linux_boot) {
+        uint64_t lowaddr = 0;
         kernel_base = KERNEL_LOAD_ADDR;
         /* now we can load the kernel */
-        kernel_size = load_elf(kernel_filename, kernel_base - 0xc0000000ULL,
+        load_elf(kernel_filename, 0, NULL, &lowaddr, NULL);
+        kernel_size = load_elf(kernel_filename, kernel_base - lowaddr,
                                NULL, NULL, NULL);

Hello,

Can't you speculatively load at kernel_base assuming it's a new kernel, then only if lowaddr indicates it was an old kernel you do the second load to fix things up?

Maybe also a comment or two in the code explaining the hack.. :)

Cheers

#2 lore raw
Quoted 37 lines · Edgar E. Iglesias
Quoted 32 lines · Alexander Graf

Linux changed its physical address location in the elf header from 0xc0000000 to 0 on 2.6.25, causing later kernels to fail booting with the -kernel option.

This patch assures that the lowest segment in the elf binary is loaded to KERNEL_LOAD_ADDR, which is where the firmware expects it.

With this patch applied, I was able to successfully boot a 2.6.18 and a 2.6.27 Linux kernel using the -kernel option.

---
hw/ppc_oldworld.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
hw/ppc_oldworld.c +3 -1
index 042a40f..f64884b 100644
@@ -207,9 +207,11 @@ static void ppc_heathrow_init (ram_addr_t  
 ram_size, int vga_ram_size,
    }
 
    if (linux_boot) {
+        uint64_t lowaddr = 0;
        kernel_base = KERNEL_LOAD_ADDR;
        /* now we can load the kernel */
-        kernel_size = load_elf(kernel_filename, kernel_base -  
 0xc0000000ULL,
+        load_elf(kernel_filename, 0, NULL, &lowaddr, NULL);
+        kernel_size = load_elf(kernel_filename, kernel_base -  
 lowaddr,
Quoted 1 line
                               NULL, NULL, NULL);

Hello,

Quoted 3 lines

Can't you speculatively load at kernel_base assuming it's a new kernel, then only if lowaddr indicates it was an old kernel you do the second load to fix things up?

Hm - so we only call load_elf once for new kernels? Sounds like a good idea :-).

Quoted 1 line

Maybe also a comment or two in the code explaining the hack.. :)

Right, that might be nice.

Alex

Quoted 3 lines

Cheers

#3 lore raw
Quoted 39 lines · Alexander Graf
Quoted 36 lines · Edgar E. Iglesias
Quoted 22 lines · Alexander Graf

Linux changed its physical address location in the elf header from 0xc0000000 to 0 on 2.6.25, causing later kernels to fail booting with the -kernel option.

This patch assures that the lowest segment in the elf binary is loaded to KERNEL_LOAD_ADDR, which is where the firmware expects it.

With this patch applied, I was able to successfully boot a 2.6.18 and a 2.6.27 Linux kernel using the -kernel option.

---
hw/ppc_oldworld.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
hw/ppc_oldworld.c +0 -0
index 042a40f..f64884b 100644
@@ -207,9 +207,11 @@ static void ppc_heathrow_init (ram_addr_t ram_size, 
 int vga_ram_size,
    }

hw/ppc_oldworld.c static void ppc_heathrow_init (ram_addr_t ram_size, · line 217

Quoted 10 lines
hw/ppc_oldworld.c +3 -1
 
    if (linux_boot) {
+        uint64_t lowaddr = 0;
        kernel_base = KERNEL_LOAD_ADDR;
        /* now we can load the kernel */
-        kernel_size = load_elf(kernel_filename, kernel_base - 
 0xc0000000ULL,
+        load_elf(kernel_filename, 0, NULL, &lowaddr, NULL);
+        kernel_size = load_elf(kernel_filename, kernel_base - lowaddr,
                               NULL, NULL, NULL);

Hello,

Quoted 6 lines
Quoted 3 lines

Can't you speculatively load at kernel_base assuming it's a new kernel, then only if lowaddr indicates it was an old kernel you do the second load to fix things up?

Hm - so we only call load_elf once for new kernels? Sounds like a good idea :-).

Yes, if it works :)

Cheers

#4 lore raw
In reply to Alexander Graf
Quoted 46 lines · Alexander Graf
Quoted 38 lines · Edgar E. Iglesias
Quoted 33 lines · Alexander Graf

Linux changed its physical address location in the elf header from 0xc0000000 to 0 on 2.6.25, causing later kernels to fail booting with the -kernel option.

This patch assures that the lowest segment in the elf binary is loaded
to KERNEL_LOAD_ADDR, which is where the firmware expects it.

With this patch applied, I was able to successfully boot a 2.6.18 and a 2.6.27 Linux kernel using the -kernel option.

---
hw/ppc_oldworld.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
hw/ppc_oldworld.c +3 -1
index 042a40f..f64884b 100644
@@ -207,9 +207,11 @@ static void ppc_heathrow_init (ram_addr_t  
 ram_size, int vga_ram_size,
    }
 
    if (linux_boot) {
+        uint64_t lowaddr = 0;
        kernel_base = KERNEL_LOAD_ADDR;
        /* now we can load the kernel */
-        kernel_size = load_elf(kernel_filename, kernel_base -  
 0xc0000000ULL,
+        load_elf(kernel_filename, 0, NULL, &lowaddr, NULL);
+        kernel_size = load_elf(kernel_filename, kernel_base -  
 lowaddr,
Quoted 1 line
                               NULL, NULL, NULL);

Hello,

Quoted 4 lines

Can't you speculatively load at kernel_base assuming it's a new kernel,
then only if lowaddr indicates it was an old kernel you do the second load to fix things up?

Quoted 7 lines

Hm - so we only call load_elf once for new kernels? Sounds like a good idea :-).

Quoted 1 line

Maybe also a comment or two in the code explaining the hack.. :)

Right, that might be nice.

I have just committed a fix based on your patch and implementing that. I also added a comment explaining the hack.

Aurelien

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#5 lore raw
Quoted 50 lines · Aurelien Jarno
Quoted 49 lines · Alexander Graf
Quoted 38 lines · Edgar E. Iglesias
Quoted 33 lines · Alexander Graf

Linux changed its physical address location in the elf header from 0xc0000000 to 0 on 2.6.25, causing later kernels to fail booting with the -kernel option.

This patch assures that the lowest segment in the elf binary is loaded
to KERNEL_LOAD_ADDR, which is where the firmware expects it.

With this patch applied, I was able to successfully boot a 2.6.18 and a 2.6.27 Linux kernel using the -kernel option.

---
hw/ppc_oldworld.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
hw/ppc_oldworld.c +3 -1
index 042a40f..f64884b 100644
@@ -207,9 +207,11 @@ static void ppc_heathrow_init (ram_addr_t
 ram_size, int vga_ram_size,
   }
 
   if (linux_boot) {
+        uint64_t lowaddr = 0;
       kernel_base = KERNEL_LOAD_ADDR;
       /* now we can load the kernel */
-        kernel_size = load_elf(kernel_filename, kernel_base -
 0xc0000000ULL,
+        load_elf(kernel_filename, 0, NULL, &lowaddr, NULL);
+        kernel_size = load_elf(kernel_filename, kernel_base -
 lowaddr,
Quoted 1 line
                              NULL, NULL, NULL);

Hello,

Quoted 4 lines

Can't you speculatively load at kernel_base assuming it's a new kernel,
then only if lowaddr indicates it was an old kernel you do the second load to fix things up?

Hm - so we only call load_elf once for new kernels? Sounds like a good idea :-).

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Maybe also a comment or two in the code explaining the hack.. :)

Right, that might be nice.

I have just committed a fix based on your patch and implementing that. I also added a comment explaining the hack.

Heh - I literally started to look at the patch again about 2 seconds before your mail came in.

Thanks!

Alex