aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHao Wu <wuhaotsh@google.com>2022-09-29 14:38:13 -0700
committerHao Wu <wuhaotsh@google.com>2022-09-29 14:38:13 -0700
commit4f54dfc47aed90a63c8b0facb91f3571b44d2ec6 (patch)
tree2ae89fe381269e6f3a3f6bfd44bbd8c78852fb65
parent1287b6e42e839ba2ab0f06268c5b53ae60df3537 (diff)
downloadvbootrom-4f54dfc47aed90a63c8b0facb91f3571b44d2ec6.zip
vbootrom-4f54dfc47aed90a63c8b0facb91f3571b44d2ec6.tar.gz
vbootrom-4f54dfc47aed90a63c8b0facb91f3571b44d2ec6.tar.bz2
Automatically search for UBOOT location for NPCM8xx images.
-rw-r--r--npcm8xx/image.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/npcm8xx/image.c b/npcm8xx/image.c
index f799774..3dade5c 100644
--- a/npcm8xx/image.c
+++ b/npcm8xx/image.c
@@ -1,7 +1,7 @@
/*
* Boot image parsing and loading.
*
- * Copyright 2022 Google LLC
+ * Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,10 +21,18 @@
#define SPI0CS0 0x80000000
#define CLK 0xf0801000
#define FIU0 0xfb000000
+
#define CLK_CLKSEL 0x04
#define CLK_CLKSEL_DEFAULT 0x1f18fc9
+
#define FIU_DRD_CFG 0x00
+#define UBOOT_TAG 0x4c42544f4f42550aULL /* .UBOOTBL */
+#define UBOOT_MAGIC 0x1400000a
+#define UBOOT_SIZE 0xae680
+#define UBOOT_INVALID 0xffffffff
+#define UBOOT_DEST 0x7e00
+
/*
* This structure must reside at offset 0x100 in SRAM.
*
@@ -70,17 +78,26 @@ void copy_boot_image(uintptr_t dest_addr, uintptr_t src_addr, int32_t len)
}
}
-uintptr_t load_boot_image(void)
+static void search_and_load_uboot(uintptr_t end)
{
- uintptr_t dest_addr = 0x8000;
+ uintptr_t addr;
+ uintptr_t src_addr, dest_addr = UBOOT_DEST;
+
+ for (addr = 0; addr < end; addr += 0x100) {
+ src_addr = SPI0CS0 + addr;
+ if ((*(uint64_t *)src_addr == UBOOT_TAG) &&
+ (*(uint32_t *)(src_addr + 0x200) == UBOOT_MAGIC)) {
+ copy_boot_image(dest_addr, src_addr, UBOOT_SIZE);
+ return;
+ }
+ }
+}
+uintptr_t load_boot_image(void)
+{
/* Set CLKSEL to similar values as NPCM7XX */
reg_write(CLK, CLK_CLKSEL, CLK_CLKSEL_DEFAULT);
+ search_and_load_uboot(0x200000);
- /* Load the U-BOOT image to DRAM */
- copy_boot_image(dest_addr, SPI0CS0 + 0x20200, 0xa6e80);
- /* Set FIU to use 4 byte mode, similar to what TIP does in reality. */
- reg_write(FIU0, FIU_DRD_CFG, 0x0301100b);
-
- return dest_addr;
+ return UBOOT_DEST + 0x200;
}