diff mbox series

[v2] core/init: Assert when kernel not found

Message ID 20180228230716.15924-1-mikey@neuling.org
State Accepted
Headers show
Series [v2] core/init: Assert when kernel not found | expand

Commit Message

Michael Neuling Feb. 28, 2018, 11:07 p.m. UTC
If the kernel doesn't load out of flash or there is nothing at
KERNEL_LOAD_BASE, we end up with an esoteric message as we try to
branch to out of skiboot into nothing

  [    0.007197688,3] INIT: ELF header not found. Assuming raw binary.
  [    0.014035267,5] INIT: Starting kernel at 0x0, fdt at 0x3044ad90 13029
  [    0.014042254,3] ***********************************************
  [    0.014069947,3] Fatal Exception 0xe40 at 0000000000000000
  [    0.014085574,3] CFAR : 00000000300051c4
  [    0.014090118,3] SRR0 : 0000000000000000 SRR1 : 0000000000000000
  [    0.014096243,3] HSRR0: 0000000000000000 HSRR1: 9000000000001000
  [    0.014102546,3] DSISR: 00000000         DAR  : 0000000000000000
  [    0.014108538,3] LR   : 00000000300144c8 CTR  : 0000000000000000
  [    0.014114756,3] CR   : 40002202         XER  : 00000000
  [    0.014120301,3] GPR00: 000000003001447c GPR16: 0000000000000000

This improves the message and asserts in this case:

[    0.014042685,5] INIT: Starting kernel at 0x0, fdt at 0x3044ad90 13049 bytes)
[    0.014049556,0] FATAL: Kernel is zeros, can't execute!
[    0.014054237,0] Assert fail: core/init.c:566:0
[    0.014060472,0] Aborting!

Signed-off-by: Michael Neuling <mikey@neuling.org>
Reviewed-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
---
v2:
  Move location of assert as suggest by Vaidy
---
 core/init.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Joel Stanley March 1, 2018, 1:45 a.m. UTC | #1
On Thu, Mar 1, 2018 at 9:37 AM, Michael Neuling <mikey@neuling.org> wrote:
> If the kernel doesn't load out of flash or there is nothing at
> KERNEL_LOAD_BASE, we end up with an esoteric message as we try to
> branch to out of skiboot into nothing
>
>   [    0.007197688,3] INIT: ELF header not found. Assuming raw binary.
>   [    0.014035267,5] INIT: Starting kernel at 0x0, fdt at 0x3044ad90 13029
>   [    0.014042254,3] ***********************************************
>   [    0.014069947,3] Fatal Exception 0xe40 at 0000000000000000
>   [    0.014085574,3] CFAR : 00000000300051c4
>   [    0.014090118,3] SRR0 : 0000000000000000 SRR1 : 0000000000000000
>   [    0.014096243,3] HSRR0: 0000000000000000 HSRR1: 9000000000001000
>   [    0.014102546,3] DSISR: 00000000         DAR  : 0000000000000000
>   [    0.014108538,3] LR   : 00000000300144c8 CTR  : 0000000000000000
>   [    0.014114756,3] CR   : 40002202         XER  : 00000000
>   [    0.014120301,3] GPR00: 000000003001447c GPR16: 0000000000000000
>
> This improves the message and asserts in this case:
>
> [    0.014042685,5] INIT: Starting kernel at 0x0, fdt at 0x3044ad90 13049 bytes)
> [    0.014049556,0] FATAL: Kernel is zeros, can't execute!
> [    0.014054237,0] Assert fail: core/init.c:566:0
> [    0.014060472,0] Aborting!
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> Reviewed-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>

Tested-by: Joel Stanley <joel@jms.id.au>

Thanks Mikey!

Cheers,

Joel
Stewart Smith March 1, 2018, 4:12 a.m. UTC | #2
Michael Neuling <mikey@neuling.org> writes:

> If the kernel doesn't load out of flash or there is nothing at
> KERNEL_LOAD_BASE, we end up with an esoteric message as we try to
> branch to out of skiboot into nothing
>
>   [    0.007197688,3] INIT: ELF header not found. Assuming raw binary.
>   [    0.014035267,5] INIT: Starting kernel at 0x0, fdt at 0x3044ad90 13029
>   [    0.014042254,3] ***********************************************
>   [    0.014069947,3] Fatal Exception 0xe40 at 0000000000000000
>   [    0.014085574,3] CFAR : 00000000300051c4
>   [    0.014090118,3] SRR0 : 0000000000000000 SRR1 : 0000000000000000
>   [    0.014096243,3] HSRR0: 0000000000000000 HSRR1: 9000000000001000
>   [    0.014102546,3] DSISR: 00000000         DAR  : 0000000000000000
>   [    0.014108538,3] LR   : 00000000300144c8 CTR  : 0000000000000000
>   [    0.014114756,3] CR   : 40002202         XER  : 00000000
>   [    0.014120301,3] GPR00: 000000003001447c GPR16: 0000000000000000
>
> This improves the message and asserts in this case:
>
> [    0.014042685,5] INIT: Starting kernel at 0x0, fdt at 0x3044ad90 13049 bytes)
> [    0.014049556,0] FATAL: Kernel is zeros, can't execute!
> [    0.014054237,0] Assert fail: core/init.c:566:0
> [    0.014060472,0] Aborting!
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> Reviewed-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
> ---
> v2:
>   Move location of assert as suggest by Vaidy
> ---
>  core/init.c | 7 +++++++
>  1 file changed, 7 insertions(+)

Oh yeah, merged to master as of 18d7ee718bef3c95787473e3537be5f0653470c4
diff mbox series

Patch

diff --git a/core/init.c b/core/init.c
index 5633a9d38f..a8edc3b862 100644
--- a/core/init.c
+++ b/core/init.c
@@ -559,6 +559,13 @@  void __noreturn load_and_boot_kernel(bool is_reboot)
 	debug_descriptor.state_flags |= OPAL_BOOT_COMPLETE;
 
 	fdt_set_boot_cpuid_phys(fdt, this_cpu()->pir);
+
+	/* Check there is something there before we branch to it */
+	if (*(uint32_t *)kernel_entry == 0) {
+		prlog(PR_EMERG, "FATAL: Kernel is zeros, can't execute!\n");
+		assert(0);
+	}
+
 	if (kernel_32bit)
 		start_kernel32(kernel_entry, fdt, mem_top);
 	start_kernel(kernel_entry, fdt, mem_top);