diff mbox

[U-Boot,3/5] nand: sunxi: Add secondary U-Boot offset on second syndrome partition

Message ID 1430319781-15375-4-git-send-email-dkochmanski@turtle-solutions.eu
State Superseded
Delegated to: Hans de Goede
Headers show

Commit Message

Daniel Kochmański April 29, 2015, 3:02 p.m. UTC
Introduces CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS, pointing to backup
U-Boot instance in nand memory. In case if first header doesn't match,
tries to load bootloader from this offset. In case of both failing,
hang() is called.

Additionally define offset of backup U-boot for sunxi at start of
second syndrome partition.

Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
Cc: Ian Campbell <ijc@hellion.org.uk>
Cc: Hans De Goede <hdegoede@redhat.com>
---

 README                         |  4 ++++
 common/spl/spl_nand.c          | 28 +++++++++++++++++++++++++---
 include/configs/sunxi-common.h |  1 +
 3 files changed, 30 insertions(+), 3 deletions(-)

Comments

Ian Campbell May 2, 2015, 2:24 p.m. UTC | #1
On Wed, 2015-04-29 at 17:02 +0200, Daniel Kochmański wrote:
> Introduces CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS, pointing to backup
> U-Boot instance in nand memory. In case if first header doesn't match,
> tries to load bootloader from this offset. In case of both failing,
> hang() is called.
> 
> Additionally define offset of backup U-boot for sunxi at start of
> second syndrome partition.
> 
> Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
> Cc: Ian Campbell <ijc@hellion.org.uk>
> Cc: Hans De Goede <hdegoede@redhat.com>
> ---
> 
>  README                         |  4 ++++
>  common/spl/spl_nand.c          | 28 +++++++++++++++++++++++++---

This needs an ack from the maintainer of this file rather than Hans or
I.

Adding CC of Simon who is mentioned in the header plus some people who
touched the file recently in the hopes of finding out who that is.

Ian.
Tim Harvey May 5, 2015, 2:21 p.m. UTC | #2
On Wed, Apr 29, 2015 at 8:02 AM, Daniel Kochmański
<dkochmanski@turtle-solutions.eu> wrote:
> Introduces CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS, pointing to backup
> U-Boot instance in nand memory. In case if first header doesn't match,
> tries to load bootloader from this offset. In case of both failing,
> hang() is called.
>
> Additionally define offset of backup U-boot for sunxi at start of
> second syndrome partition.
>
> Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
> Cc: Ian Campbell <ijc@hellion.org.uk>
> Cc: Hans De Goede <hdegoede@redhat.com>
> ---
>
>  README                         |  4 ++++
>  common/spl/spl_nand.c          | 28 +++++++++++++++++++++++++---
>  include/configs/sunxi-common.h |  1 +
>  3 files changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/README b/README
> index ee65fdb..4ccf3cb 100644
> --- a/README
> +++ b/README
> @@ -3722,6 +3722,10 @@ FIT uImage format:
>                 CONFIG_SYS_NAND_U_BOOT_OFFS
>                 Location in NAND to read U-Boot from
>
> +               CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS
> +               Location in NAND to read backup U-Boot from, if first
> +               location doesn't contain valid image.
> +
>                 CONFIG_SYS_NAND_U_BOOT_DST
>                 Location in memory to load U-Boot to
>
> diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
> index 9d59fbb..7c44de1 100644
> --- a/common/spl/spl_nand.c
> +++ b/common/spl/spl_nand.c
> @@ -2,6 +2,9 @@
>   * Copyright (C) 2011
>   * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
>   *
> + * Copyright (C) 2015
> + * Turtle Solutions - Daniel Kochmański <dkochmanski@turtle-solutions.eu>
> + *
>   * SPDX-License-Identifier:    GPL-2.0+
>   */
>  #include <common.h>
> @@ -90,9 +93,28 @@ void spl_nand_load_image(void)
>         nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
>                             sizeof(*header), (void *)header);
>         spl_parse_image_header(header);
> -       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
> -                           spl_image.size,
> -                           (void *)(unsigned long)spl_image.load_addr);
> +       if (header->ih_os == IH_OS_U_BOOT) {
> +               nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
> +                                   spl_image.size,
> +                                   (void *)(unsigned long)spl_image.load_addr);
> +               nand_deselect();
> +               return;
> +       }
> +       puts("U-boot header didn't match.\n");
> +#ifdef CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS
> +       puts("Trying to start backup u-boot now...\n");
> +       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
> +                           sizeof(*header), (void *)header);
> +       spl_parse_image_header(header);
> +       if (header->ih_os == IH_OS_U_BOOT) {
> +               nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
> +                                   spl_image.size,
> +                                   (void *)(unsigned long)spl_image.load_addr);
> +               nand_deselect();
> +               return;
> +       }
> +#endif
> +       puts("No valid u-boot image found.\n");
>         nand_deselect();
>  }
>  #endif

Daniel,

Under what circumstances would header->ih_os not be IH_OS_U_BOOT? It
seems to me only if CONFIG_SYS_NAND_U_BOOT_OFFS pointed to the wrong
place but wouldn't this be a board configuration error?

Are you trying to put some redundancy in for detecting a corrupted
image? It seems to me that you would want to do more than check the
header type in that case.

Tim
Daniel Kochmański May 5, 2015, 2:34 p.m. UTC | #3
Hi,

Tim Harvey writes:

> On Wed, Apr 29, 2015 at 8:02 AM, Daniel Kochmański
> <dkochmanski@turtle-solutions.eu> wrote:
>> Introduces CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS, pointing to backup
>> U-Boot instance in nand memory. In case if first header doesn't match,
>> tries to load bootloader from this offset. In case of both failing,
>> hang() is called.
>>
>> Additionally define offset of backup U-boot for sunxi at start of
>> second syndrome partition.
>>
>> Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
>> Cc: Ian Campbell <ijc@hellion.org.uk>
>> Cc: Hans De Goede <hdegoede@redhat.com>
>> ---
>>
>>  README                         |  4 ++++
>>  common/spl/spl_nand.c          | 28 +++++++++++++++++++++++++---
>>  include/configs/sunxi-common.h |  1 +
>>  3 files changed, 30 insertions(+), 3 deletions(-)
>>
>> diff --git a/README b/README
>> index ee65fdb..4ccf3cb 100644
>> --- a/README
>> +++ b/README
>> @@ -3722,6 +3722,10 @@ FIT uImage format:
>>                 CONFIG_SYS_NAND_U_BOOT_OFFS
>>                 Location in NAND to read U-Boot from
>>
>> +               CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS
>> +               Location in NAND to read backup U-Boot from, if first
>> +               location doesn't contain valid image.
>> +
>>                 CONFIG_SYS_NAND_U_BOOT_DST
>>                 Location in memory to load U-Boot to
>>
>> diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
>> index 9d59fbb..7c44de1 100644
>> --- a/common/spl/spl_nand.c
>> +++ b/common/spl/spl_nand.c
>> @@ -2,6 +2,9 @@
>>   * Copyright (C) 2011
>>   * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
>>   *
>> + * Copyright (C) 2015
>> + * Turtle Solutions - Daniel Kochmański <dkochmanski@turtle-solutions.eu>
>> + *
>>   * SPDX-License-Identifier:    GPL-2.0+
>>   */
>>  #include <common.h>
>> @@ -90,9 +93,28 @@ void spl_nand_load_image(void)
>>         nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
>>                             sizeof(*header), (void *)header);
>>         spl_parse_image_header(header);
>> -       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
>> -                           spl_image.size,
>> -                           (void *)(unsigned long)spl_image.load_addr);
>> +       if (header->ih_os == IH_OS_U_BOOT) {
>> +               nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
>> +                                   spl_image.size,
>> +                                   (void *)(unsigned long)spl_image.load_addr);
>> +               nand_deselect();
>> +               return;
>> +       }
>> +       puts("U-boot header didn't match.\n");
>> +#ifdef CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS
>> +       puts("Trying to start backup u-boot now...\n");
>> +       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
>> +                           sizeof(*header), (void *)header);
>> +       spl_parse_image_header(header);
>> +       if (header->ih_os == IH_OS_U_BOOT) {
>> +               nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
>> +                                   spl_image.size,
>> +                                   (void *)(unsigned long)spl_image.load_addr);
>> +               nand_deselect();
>> +               return;
>> +       }
>> +#endif
>> +       puts("No valid u-boot image found.\n");
>>         nand_deselect();
>>  }
>>  #endif
>
> Daniel,
>
> Under what circumstances would header->ih_os not be IH_OS_U_BOOT? It
> seems to me only if CONFIG_SYS_NAND_U_BOOT_OFFS pointed to the wrong
> place but wouldn't this be a board configuration error?

In case of sunxi boards so-called BROM when it reads bootloader from
NAND it tries to load it from first block of NAND, and if
header/checksum doesn't match, then it tries to read it from second one.
>
> Are you trying to put some redundancy in for detecting a corrupted
> image? It seems to me that you would want to do more than check the
> header type in that case.

SPL can't detect, from which offset it was loaded, therefore even if
image is correct and is placed on second block, it needs to check, if
something it reads is actual U-Boot. If not, then it is placed at second
one, and it should read U-Boot from second offset.
>
> Tim
Scott Wood May 18, 2015, 11:10 p.m. UTC | #4
On Wed, 2015-04-29 at 17:02 +0200, Daniel Kochmański wrote:
> diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
> index 9d59fbb..7c44de1 100644
> --- a/common/spl/spl_nand.c
> +++ b/common/spl/spl_nand.c
> @@ -2,6 +2,9 @@
>   * Copyright (C) 2011
>   * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
>   *
> + * Copyright (C) 2015
> + * Turtle Solutions - Daniel Kochmański <dkochmanski@turtle-solutions.eu>
> + *
>   * SPDX-License-Identifier:	GPL-2.0+
>   */
>  #include <common.h>
> @@ -90,9 +93,28 @@ void spl_nand_load_image(void)
>  	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
>  			    sizeof(*header), (void *)header);
>  	spl_parse_image_header(header);
> -	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
> -			    spl_image.size,
> -			    (void *)(unsigned long)spl_image.load_addr);
> +	if (header->ih_os == IH_OS_U_BOOT) {
> +		nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
> +				    spl_image.size,
> +				    (void *)(unsigned long)spl_image.load_addr);
> +		nand_deselect();
> +		return;
> +	}
> +	puts("U-boot header didn't match.\n");
> +#ifdef CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS
> +	puts("Trying to start backup u-boot now...\n");
> +	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
> +			    sizeof(*header), (void *)header);
> +	spl_parse_image_header(header);
> +	if (header->ih_os == IH_OS_U_BOOT) {
> +		nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
> +				    spl_image.size,
> +				    (void *)(unsigned long)spl_image.load_addr);
> +		nand_deselect();
> +		return;
> +	}
> +#endif

Factor this code into a function that is called twice rather than
repeating everything.

-Scott
diff mbox

Patch

diff --git a/README b/README
index ee65fdb..4ccf3cb 100644
--- a/README
+++ b/README
@@ -3722,6 +3722,10 @@  FIT uImage format:
 		CONFIG_SYS_NAND_U_BOOT_OFFS
 		Location in NAND to read U-Boot from
 
+		CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS
+		Location in NAND to read backup U-Boot from, if first
+		location doesn't contain valid image.
+
 		CONFIG_SYS_NAND_U_BOOT_DST
 		Location in memory to load U-Boot to
 
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 9d59fbb..7c44de1 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -2,6 +2,9 @@ 
  * Copyright (C) 2011
  * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
  *
+ * Copyright (C) 2015
+ * Turtle Solutions - Daniel Kochmański <dkochmanski@turtle-solutions.eu>
+ *
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
@@ -90,9 +93,28 @@  void spl_nand_load_image(void)
 	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
 			    sizeof(*header), (void *)header);
 	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
-			    spl_image.size,
-			    (void *)(unsigned long)spl_image.load_addr);
+	if (header->ih_os == IH_OS_U_BOOT) {
+		nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+				    spl_image.size,
+				    (void *)(unsigned long)spl_image.load_addr);
+		nand_deselect();
+		return;
+	}
+	puts("U-boot header didn't match.\n");
+#ifdef CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS
+	puts("Trying to start backup u-boot now...\n");
+	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
+			    sizeof(*header), (void *)header);
+	spl_parse_image_header(header);
+	if (header->ih_os == IH_OS_U_BOOT) {
+		nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS,
+				    spl_image.size,
+				    (void *)(unsigned long)spl_image.load_addr);
+		nand_deselect();
+		return;
+	}
+#endif
+	puts("No valid u-boot image found.\n");
 	nand_deselect();
 }
 #endif
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index b40cdd3..15fe512 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -330,6 +330,7 @@  extern int soft_i2c_gpio_scl;
 #define CONFIG_NAND_SUNXI
 #define CONFIG_CMD_SPL_WRITE_SIZE		0x000400
 #define CONFIG_SYS_NAND_U_BOOT_OFFS		0x008000
+#define CONFIG_SYS_NAND_U_BOOT_BACKUP_OFFS	0x208000
 #endif /* CONFIG_SPL_NAND_SUPPORT */
 
 #define CONFIG_MISC_INIT_R