Skip to content

Instantly share code, notes, and snippets.

@n1tehawk
Last active May 20, 2016 06:41
Show Gist options
  • Save n1tehawk/776bdd1e3f0fdeb04deefbec3b531bdd to your computer and use it in GitHub Desktop.
Save n1tehawk/776bdd1e3f0fdeb04deefbec3b531bdd to your computer and use it in GitHub Desktop.
change spl_header @ 0x0 -> spl_signature @ 0x4 to avoid dereferencing NULL
diff --git a/uart0-helloworld-sdboot.c b/uart0-helloworld-sdboot.c
index 2278b0b..0d62cf0 100644
--- a/uart0-helloworld-sdboot.c
+++ b/uart0-helloworld-sdboot.c
@@ -419,16 +419,18 @@ enum { BOOT_DEVICE_UNK, BOOT_DEVICE_FEL, BOOT_DEVICE_MMC0, BOOT_DEVICE_SPI };
int get_boot_device(void)
{
- u32 *spl_header = (void *)0x0;
+ u32 *spl_signature = (void *)0x4;
if (soc_is_a64() || soc_is_a80())
- spl_header = (void *)0x10000;
+ spl_signature = (void *)0x10004;
/* Check the eGON.BT0 magic in the SPL header */
- if (!(spl_header[1] == 0x4E4F4765 && spl_header[2] == 0x3054422E))
+ if (spl_signature[0] != 0x4E4F4765 || spl_signature[1] != 0x3054422E)
return BOOT_DEVICE_FEL;
- else if ((spl_header[10] & 0xFF) == 0)
+
+ u32 boot_dev = spl_signature[9] & 0xFF; /* offset into SPL = 0x28 */
+ if (boot_dev == 0)
return BOOT_DEVICE_MMC0;
- else if ((spl_header[10] & 0xFF) == 3)
+ if (boot_dev == 3)
return BOOT_DEVICE_SPI;
return BOOT_DEVICE_UNK;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment