diff mbox

[U-Boot,08/27] spl: Add a way to declare an SPL image loader

Message ID 1474227917-9256-9-git-send-email-sjg@chromium.org
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass Sept. 18, 2016, 7:44 p.m. UTC
Add a linker list macro which can be used to declare an SPL image loader.
Update spl_load_image() to search available loaders for the correct one.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/spl/spl.c | 20 ++++++++++++++++++++
 include/spl.h    | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

Comments

Tom Rini Sept. 18, 2016, 10:15 p.m. UTC | #1
On Sun, Sep 18, 2016 at 01:44:57PM -0600, Simon Glass wrote:
> Add a linker list macro which can be used to declare an SPL image loader.
> Update spl_load_image() to search available loaders for the correct one.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  common/spl/spl.c | 20 ++++++++++++++++++++
>  include/spl.h    | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 52 insertions(+)
> 
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 3716e6a..719ae6e 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -344,12 +344,32 @@ static void announce_boot_device(u32 boot_device)
>  static inline void announce_boot_device(u32 boot_device) { }
>  #endif
>  
> +static struct spl_image_loader *spL_find_loader(uint boot_device)

I don't like spL here, I mis-read that as a typo the second time I saw
it.  Maybe a function comment and spl_ll_find_loader ?
Simon Glass Sept. 19, 2016, 3:22 a.m. UTC | #2
Hi Tom,

On 18 September 2016 at 16:15, Tom Rini <trini@konsulko.com> wrote:
> On Sun, Sep 18, 2016 at 01:44:57PM -0600, Simon Glass wrote:
>> Add a linker list macro which can be used to declare an SPL image loader.
>> Update spl_load_image() to search available loaders for the correct one.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>>  common/spl/spl.c | 20 ++++++++++++++++++++
>>  include/spl.h    | 32 ++++++++++++++++++++++++++++++++
>>  2 files changed, 52 insertions(+)
>>
>> diff --git a/common/spl/spl.c b/common/spl/spl.c
>> index 3716e6a..719ae6e 100644
>> --- a/common/spl/spl.c
>> +++ b/common/spl/spl.c
>> @@ -344,12 +344,32 @@ static void announce_boot_device(u32 boot_device)
>>  static inline void announce_boot_device(u32 boot_device) { }
>>  #endif
>>
>> +static struct spl_image_loader *spL_find_loader(uint boot_device)
>
> I don't like spL here, I mis-read that as a typo the second time I saw
> it.  Maybe a function comment and spl_ll_find_loader ?

Oops that was a typo. Fixed, thanks.

Regards,
Simon
diff mbox

Patch

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 3716e6a..719ae6e 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -344,12 +344,32 @@  static void announce_boot_device(u32 boot_device)
 static inline void announce_boot_device(u32 boot_device) { }
 #endif
 
+static struct spl_image_loader *spL_find_loader(uint boot_device)
+{
+	struct spl_image_loader *drv =
+		ll_entry_start(struct spl_image_loader, spl_image_loader);
+	const int n_ents =
+		ll_entry_count(struct spl_image_loader, spl_image_loader);
+	struct spl_image_loader *entry;
+
+	for (entry = drv; entry != drv + n_ents; entry++) {
+		if (boot_device == entry->boot_device)
+			return entry;
+	}
+
+	/* Not found */
+	return NULL;
+}
+
 static int spl_load_image(u32 boot_device)
 {
 	struct spl_boot_device bootdev;
+	struct spl_image_loader *loader = spL_find_loader(boot_device);
 
 	bootdev.boot_device = boot_device;
 	bootdev.boot_device_name = NULL;
+	if (loader)
+		return loader->load_image(&bootdev);
 
 	switch (boot_device) {
 #ifdef CONFIG_SPL_RAM_DEVICE
diff --git a/include/spl.h b/include/spl.h
index 63ca68c..8f19310 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -149,6 +149,38 @@  struct spl_boot_device {
 	const char *boot_device_name;
 };
 
+/**
+ * Holds information about a way of loading an SPL image
+ *
+ * @boot_device: Boot device that this loader supports
+ * @load_image: Function to call to load image
+ */
+struct spl_image_loader {
+	uint boot_device;
+	/**
+	 * load_image() - Load an SPL image
+	 *
+	 * @bootdev: describes the boot device to load from
+	 */
+	int (*load_image)(struct spl_boot_device *bootdev);
+};
+
+/* Declare an SPL image loader */
+#define SPL_LOAD_IMAGE(__name)					\
+	ll_entry_declare(struct spl_image_loader, __name, spl_image_loader)
+
+/*
+ * __priority is the priority of this method, 0 meaning it will be the top
+ * choice for this device, 9 meaning it is the bottom choice.
+ * __boot_device is the BOOT_DEVICE_... value
+ * __method is the load_image function to call
+ */
+#define SPL_LOAD_IMAGE_METHOD(__priority, __boot_device, __method) \
+	SPL_LOAD_IMAGE(__method ## __priority ## __boot_device) = { \
+		.boot_device = __boot_device, \
+		.load_image = __method, \
+	}
+
 /* NAND SPL functions */
 int spl_nand_load_image(struct spl_boot_device *bootdev);