From 5541673db88f7a0182738e514665eb908738387a Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Tue, 12 Jun 2018 11:13:59 +0100 Subject: [PATCH] fel: Parse SPL DT name A while ago the SPL header was extended to hold the name of the DTB file that shall be used for the board a firmware image is made for. Add some code to extract that name from the SPL header. This will be used in later patches to load the proper DTB file. Signed-off-by: Andre Przywara --- fel.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/fel.c b/fel.c index 0fdeec4..def0292 100644 --- a/fel.c +++ b/fel.c @@ -865,7 +865,8 @@ uint32_t aw_fel_write_and_execute_spl(feldev_handle *dev, uint8_t *buf, size_t l * address stored within the image header; and the function preserves the * U-Boot entry point (offset) and size values. */ -void aw_fel_write_uboot_image(feldev_handle *dev, uint8_t *buf, size_t len) +static void aw_fel_write_uboot_image(feldev_handle *dev, uint8_t *buf, + size_t len, const char *dt_name) { if (len <= HEADER_SIZE) return; /* Insufficient size (no actual data), just bail out */ @@ -924,6 +925,28 @@ void aw_fel_write_uboot_image(feldev_handle *dev, uint8_t *buf, size_t len) uboot_size = data_size; } +static const char *spl_get_dtb_name(uint8_t *spl_buf) +{ + uint32_t dt_offset; + + if (memcmp(spl_buf + 4, "eGON.BT0", 8)) + return NULL; + + if (memcmp(spl_buf + 0x14, "SPL", 3)) + return NULL; + + if (spl_buf[0x17] < 0x2) /* only since v0.2 */ + return NULL; + + memcpy(&dt_offset, spl_buf + 0x20, 4); + dt_offset = le32toh(dt_offset); + + if (verbose) + printf("found DT name in SPL header: %s\n", spl_buf + dt_offset); + + return (char *)spl_buf + dt_offset; +} + /* * This function handles the common part of both "spl" and "uboot" commands. */ @@ -933,6 +956,7 @@ void aw_fel_process_spl_and_uboot(feldev_handle *dev, const char *filename) uint32_t offset; /* load file into memory buffer */ uint8_t *buf = load_file(filename, &size); + const char *dt_name = spl_get_dtb_name(buf); /* write and execute the SPL from the buffer */ offset = aw_fel_write_and_execute_spl(dev, buf, size); @@ -941,7 +965,8 @@ void aw_fel_process_spl_and_uboot(feldev_handle *dev, const char *filename) /* U-Boot pads to at least 32KB */ if (offset < SPL_MIN_OFFSET) offset = SPL_MIN_OFFSET; - aw_fel_write_uboot_image(dev, buf + offset, size - offset); + aw_fel_write_uboot_image(dev, buf + offset, size - offset, + dt_name); } free(buf); }