Commit a0a8029058e11b8eda1a3d61fdf497bc687b30f8

Authored by Simon Glass
Committed by Tom Rini
1 parent ecdfd69a4b

spl: Add a way to declare an SPL image loader

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>
Reviewed-by: Tom Rini <trini@konsulko.com>

Showing 2 changed files with 52 additions and 0 deletions Side-by-side Diff

... ... @@ -347,12 +347,32 @@
347 347 static inline void announce_boot_device(u32 boot_device) { }
348 348 #endif
349 349  
  350 +static struct spl_image_loader *spl_ll_find_loader(uint boot_device)
  351 +{
  352 + struct spl_image_loader *drv =
  353 + ll_entry_start(struct spl_image_loader, spl_image_loader);
  354 + const int n_ents =
  355 + ll_entry_count(struct spl_image_loader, spl_image_loader);
  356 + struct spl_image_loader *entry;
  357 +
  358 + for (entry = drv; entry != drv + n_ents; entry++) {
  359 + if (boot_device == entry->boot_device)
  360 + return entry;
  361 + }
  362 +
  363 + /* Not found */
  364 + return NULL;
  365 +}
  366 +
350 367 static int spl_load_image(u32 boot_device)
351 368 {
352 369 struct spl_boot_device bootdev;
  370 + struct spl_image_loader *loader = spl_ll_find_loader(boot_device);
353 371  
354 372 bootdev.boot_device = boot_device;
355 373 bootdev.boot_device_name = NULL;
  374 + if (loader)
  375 + return loader->load_image(&bootdev);
356 376  
357 377 switch (boot_device) {
358 378 #ifdef CONFIG_SPL_RAM_DEVICE
... ... @@ -149,6 +149,38 @@
149 149 const char *boot_device_name;
150 150 };
151 151  
  152 +/**
  153 + * Holds information about a way of loading an SPL image
  154 + *
  155 + * @boot_device: Boot device that this loader supports
  156 + * @load_image: Function to call to load image
  157 + */
  158 +struct spl_image_loader {
  159 + uint boot_device;
  160 + /**
  161 + * load_image() - Load an SPL image
  162 + *
  163 + * @bootdev: describes the boot device to load from
  164 + */
  165 + int (*load_image)(struct spl_boot_device *bootdev);
  166 +};
  167 +
  168 +/* Declare an SPL image loader */
  169 +#define SPL_LOAD_IMAGE(__name) \
  170 + ll_entry_declare(struct spl_image_loader, __name, spl_image_loader)
  171 +
  172 +/*
  173 + * __priority is the priority of this method, 0 meaning it will be the top
  174 + * choice for this device, 9 meaning it is the bottom choice.
  175 + * __boot_device is the BOOT_DEVICE_... value
  176 + * __method is the load_image function to call
  177 + */
  178 +#define SPL_LOAD_IMAGE_METHOD(__priority, __boot_device, __method) \
  179 + SPL_LOAD_IMAGE(__method ## __priority ## __boot_device) = { \
  180 + .boot_device = __boot_device, \
  181 + .load_image = __method, \
  182 + }
  183 +
152 184 /* NAND SPL functions */
153 185 int spl_nand_load_image(struct spl_boot_device *bootdev);
154 186