diff mbox

[U-Boot,V2,10/13] spl: add support for alternative boot device

Message ID 1446024210-16517-11-git-send-email-nikita@compulab.co.il
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Nikita Kiryanov Oct. 28, 2015, 9:23 a.m. UTC
Introduce spl_boot_list array, which defines a list of boot devices
that SPL will try before hanging. By default this list will consist
of only spl_boot_device(), but board_boot_order() can be overridden
by board code to populate the array with custom values.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
---
Changes in V2:
	- No changes.

 common/spl/spl.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

Comments

Simon Glass Oct. 29, 2015, 5:19 p.m. UTC | #1
Hi Nikita,

On 28 October 2015 at 03:23, Nikita Kiryanov <nikita@compulab.co.il> wrote:
> Introduce spl_boot_list array, which defines a list of boot devices
> that SPL will try before hanging. By default this list will consist
> of only spl_boot_device(), but board_boot_order() can be overridden
> by board code to populate the array with custom values.
>
> Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
> Cc: Igor Grinberg <grinberg@compulab.co.il>
> Cc: Tom Rini <trini@konsulko.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
> Changes in V2:
>         - No changes.
>
>  common/spl/spl.c | 33 +++++++++++++++++++++++++++++----
>  1 file changed, 29 insertions(+), 4 deletions(-)

How will we convert this to driver model? I'm worried that this might
create a separate method which will live forever.

>
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 56fccca..7913c52 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -178,6 +178,23 @@ int spl_init(void)
>         return 0;
>  }
>
> +#ifndef BOOT_DEVICE_NONE
> +#define BOOT_DEVICE_NONE 0xdeadbeef
> +#endif
> +
> +static u32 spl_boot_list[] = {
> +       BOOT_DEVICE_NONE,
> +       BOOT_DEVICE_NONE,
> +       BOOT_DEVICE_NONE,
> +       BOOT_DEVICE_NONE,
> +       BOOT_DEVICE_NONE,
> +};
> +
> +__weak void board_boot_order(u32 *spl_boot_list)
> +{
> +       spl_boot_list[0] = spl_boot_device();
> +}
> +
>  static int spl_load_image(u32 boot_device)
>  {
>         switch (boot_device) {
> @@ -247,7 +264,7 @@ static int spl_load_image(u32 boot_device)
>
>  void board_init_r(gd_t *dummy1, ulong dummy2)
>  {
> -       u32 boot_device;
> +       int i;
>
>         debug(">>spl:board_init_r()\n");
>
> @@ -272,10 +289,18 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
>         spl_board_init();
>  #endif
>
> -       boot_device = spl_boot_device();
> -       debug("boot device - %d\n", boot_device);
> -       if (spl_load_image(boot_device))
> +       board_boot_order(spl_boot_list);
> +       for (i = 0; i < ARRAY_SIZE(spl_boot_list) &&
> +                       spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
> +               if (!spl_load_image(spl_boot_list[i]))
> +                       break;
> +       }
> +
> +       if (i == ARRAY_SIZE(spl_boot_list) ||
> +           spl_boot_list[i] == BOOT_DEVICE_NONE) {
> +               puts("SPL: failed to boot from all boot devices\n");
>                 hang();
> +       }
>
>         switch (spl_image.os) {
>         case IH_OS_U_BOOT:
> --
> 1.9.1
>

Regards,
Simon
Nikita Kiryanov Oct. 31, 2015, 3:39 p.m. UTC | #2
On Thu, Oct 29, 2015 at 11:19:51AM -0600, Simon Glass wrote:
> Hi Nikita,
> 
> On 28 October 2015 at 03:23, Nikita Kiryanov <nikita@compulab.co.il> wrote:
> > Introduce spl_boot_list array, which defines a list of boot devices
> > that SPL will try before hanging. By default this list will consist
> > of only spl_boot_device(), but board_boot_order() can be overridden
> > by board code to populate the array with custom values.
> >
> > Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
> > Cc: Igor Grinberg <grinberg@compulab.co.il>
> > Cc: Tom Rini <trini@konsulko.com>
> > Cc: Simon Glass <sjg@chromium.org>
> > ---
> > Changes in V2:
> >         - No changes.
> >
> >  common/spl/spl.c | 33 +++++++++++++++++++++++++++++----
> >  1 file changed, 29 insertions(+), 4 deletions(-)
> 
> How will we convert this to driver model? I'm worried that this might
> create a separate method which will live forever.

I don't see how this is related to driver model. This code just fills in
an array and iterates over it. Can you elaborate?

> 
> >
> > diff --git a/common/spl/spl.c b/common/spl/spl.c
> > index 56fccca..7913c52 100644
> > --- a/common/spl/spl.c
> > +++ b/common/spl/spl.c
> > @@ -178,6 +178,23 @@ int spl_init(void)
> >         return 0;
> >  }
> >
> > +#ifndef BOOT_DEVICE_NONE
> > +#define BOOT_DEVICE_NONE 0xdeadbeef
> > +#endif
> > +
> > +static u32 spl_boot_list[] = {
> > +       BOOT_DEVICE_NONE,
> > +       BOOT_DEVICE_NONE,
> > +       BOOT_DEVICE_NONE,
> > +       BOOT_DEVICE_NONE,
> > +       BOOT_DEVICE_NONE,
> > +};
> > +
> > +__weak void board_boot_order(u32 *spl_boot_list)
> > +{
> > +       spl_boot_list[0] = spl_boot_device();
> > +}
> > +
> >  static int spl_load_image(u32 boot_device)
> >  {
> >         switch (boot_device) {
> > @@ -247,7 +264,7 @@ static int spl_load_image(u32 boot_device)
> >
> >  void board_init_r(gd_t *dummy1, ulong dummy2)
> >  {
> > -       u32 boot_device;
> > +       int i;
> >
> >         debug(">>spl:board_init_r()\n");
> >
> > @@ -272,10 +289,18 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
> >         spl_board_init();
> >  #endif
> >
> > -       boot_device = spl_boot_device();
> > -       debug("boot device - %d\n", boot_device);
> > -       if (spl_load_image(boot_device))
> > +       board_boot_order(spl_boot_list);
> > +       for (i = 0; i < ARRAY_SIZE(spl_boot_list) &&
> > +                       spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
> > +               if (!spl_load_image(spl_boot_list[i]))
> > +                       break;
> > +       }
> > +
> > +       if (i == ARRAY_SIZE(spl_boot_list) ||
> > +           spl_boot_list[i] == BOOT_DEVICE_NONE) {
> > +               puts("SPL: failed to boot from all boot devices\n");
> >                 hang();
> > +       }
> >
> >         switch (spl_image.os) {
> >         case IH_OS_U_BOOT:
> > --
> > 1.9.1
> >
> 
> Regards,
> Simon
>
Tom Rini Nov. 3, 2015, 3:56 p.m. UTC | #3
On Sat, Oct 31, 2015 at 05:39:56PM +0200, Nikita Kiryanov wrote:
> On Thu, Oct 29, 2015 at 11:19:51AM -0600, Simon Glass wrote:
> > Hi Nikita,
> > 
> > On 28 October 2015 at 03:23, Nikita Kiryanov <nikita@compulab.co.il> wrote:
> > > Introduce spl_boot_list array, which defines a list of boot devices
> > > that SPL will try before hanging. By default this list will consist
> > > of only spl_boot_device(), but board_boot_order() can be overridden
> > > by board code to populate the array with custom values.
> > >
> > > Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
> > > Cc: Igor Grinberg <grinberg@compulab.co.il>
> > > Cc: Tom Rini <trini@konsulko.com>
> > > Cc: Simon Glass <sjg@chromium.org>
> > > ---
> > > Changes in V2:
> > >         - No changes.
> > >
> > >  common/spl/spl.c | 33 +++++++++++++++++++++++++++++----
> > >  1 file changed, 29 insertions(+), 4 deletions(-)
> > 
> > How will we convert this to driver model? I'm worried that this might
> > create a separate method which will live forever.
> 
> I don't see how this is related to driver model. This code just fills in
> an array and iterates over it. Can you elaborate?

Indeed.  With DM we'd just want to make sure that we probe for the
device before trying to use it, yes?
Tom Rini Nov. 3, 2015, 3:57 p.m. UTC | #4
On Wed, Oct 28, 2015 at 11:23:27AM +0200, Nikita Kiryanov wrote:

> Introduce spl_boot_list array, which defines a list of boot devices
> that SPL will try before hanging. By default this list will consist
> of only spl_boot_device(), but board_boot_order() can be overridden
> by board code to populate the array with custom values.
> 
> Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
> Cc: Igor Grinberg <grinberg@compulab.co.il>
> Cc: Tom Rini <trini@konsulko.com>
> Cc: Simon Glass <sjg@chromium.org>

Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass Nov. 6, 2015, 3:15 a.m. UTC | #5
Hi,

On 3 November 2015 at 08:56, Tom Rini <trini@konsulko.com> wrote:
> On Sat, Oct 31, 2015 at 05:39:56PM +0200, Nikita Kiryanov wrote:
>> On Thu, Oct 29, 2015 at 11:19:51AM -0600, Simon Glass wrote:
>> > Hi Nikita,
>> >
>> > On 28 October 2015 at 03:23, Nikita Kiryanov <nikita@compulab.co.il> wrote:
>> > > Introduce spl_boot_list array, which defines a list of boot devices
>> > > that SPL will try before hanging. By default this list will consist
>> > > of only spl_boot_device(), but board_boot_order() can be overridden
>> > > by board code to populate the array with custom values.
>> > >
>> > > Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
>> > > Cc: Igor Grinberg <grinberg@compulab.co.il>
>> > > Cc: Tom Rini <trini@konsulko.com>
>> > > Cc: Simon Glass <sjg@chromium.org>
>> > > ---
>> > > Changes in V2:
>> > >         - No changes.
>> > >
>> > >  common/spl/spl.c | 33 +++++++++++++++++++++++++++++----
>> > >  1 file changed, 29 insertions(+), 4 deletions(-)
>> >
>> > How will we convert this to driver model? I'm worried that this might
>> > create a separate method which will live forever.
>>
>> I don't see how this is related to driver model. This code just fills in
>> an array and iterates over it. Can you elaborate?
>
> Indeed.  With DM we'd just want to make sure that we probe for the
> device before trying to use it, yes?

I'm not sure, hence my question.

I imagine that we might have a 'boot device' as a child of each of
these, but I'm really not sure. Let's worry about it later.

Regards,
Simon
diff mbox

Patch

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 56fccca..7913c52 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -178,6 +178,23 @@  int spl_init(void)
 	return 0;
 }
 
+#ifndef BOOT_DEVICE_NONE
+#define BOOT_DEVICE_NONE 0xdeadbeef
+#endif
+
+static u32 spl_boot_list[] = {
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+};
+
+__weak void board_boot_order(u32 *spl_boot_list)
+{
+	spl_boot_list[0] = spl_boot_device();
+}
+
 static int spl_load_image(u32 boot_device)
 {
 	switch (boot_device) {
@@ -247,7 +264,7 @@  static int spl_load_image(u32 boot_device)
 
 void board_init_r(gd_t *dummy1, ulong dummy2)
 {
-	u32 boot_device;
+	int i;
 
 	debug(">>spl:board_init_r()\n");
 
@@ -272,10 +289,18 @@  void board_init_r(gd_t *dummy1, ulong dummy2)
 	spl_board_init();
 #endif
 
-	boot_device = spl_boot_device();
-	debug("boot device - %d\n", boot_device);
-	if (spl_load_image(boot_device))
+	board_boot_order(spl_boot_list);
+	for (i = 0; i < ARRAY_SIZE(spl_boot_list) &&
+			spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
+		if (!spl_load_image(spl_boot_list[i]))
+			break;
+	}
+
+	if (i == ARRAY_SIZE(spl_boot_list) ||
+	    spl_boot_list[i] == BOOT_DEVICE_NONE) {
+		puts("SPL: failed to boot from all boot devices\n");
 		hang();
+	}
 
 	switch (spl_image.os) {
 	case IH_OS_U_BOOT: