diff mbox

[U-Boot,v1,5/8] rockchip: mkimage: clarify header0 initialisation

Message ID 1492444088-52864-6-git-send-email-philipp.tomsich@theobroma-systems.com
State Accepted
Commit a1a2dfb87038faffdaa6e15b757a47e3a2f70ee5
Delegated to: Simon Glass
Headers show

Commit Message

Philipp Tomsich April 17, 2017, 3:48 p.m. UTC
This change set adds documentation to the header0 initialisation and
improves readability for the calculations of various offsets/lengths.

As the U-Boot SPL stage doesn't use any payload beyond what is covered
by init_size, we no longer add RK_MAX_BOOT_SIZE to init_boot_size.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
---

 tools/rkcommon.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Comments

Simon Glass April 18, 2017, 4 a.m. UTC | #1
On 17 April 2017 at 09:48, Philipp Tomsich <
philipp.tomsich@theobroma-systems.com> wrote:
> This change set adds documentation to the header0 initialisation and
> improves readability for the calculations of various offsets/lengths.
>
> As the U-Boot SPL stage doesn't use any payload beyond what is covered
> by init_size, we no longer add RK_MAX_BOOT_SIZE to init_boot_size.
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> ---
>
> tools/rkcommon.c | 20 +++++++++++++++++---
> 1 file changed, 17 insertions(+), 3 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass April 20, 2017, 9:06 p.m. UTC | #2
On 17 April 2017 at 22:00, Simon Glass <sjg@chromium.org> wrote:
> On 17 April 2017 at 09:48, Philipp Tomsich
> <philipp.tomsich@theobroma-systems.com> wrote:
>> This change set adds documentation to the header0 initialisation and
>> improves readability for the calculations of various offsets/lengths.
>>
>> As the U-Boot SPL stage doesn't use any payload beyond what is covered
>> by init_size, we no longer add RK_MAX_BOOT_SIZE to init_boot_size.
>>
>> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
>> ---
>>
>> tools/rkcommon.c | 20 +++++++++++++++++---
>> 1 file changed, 17 insertions(+), 3 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-rockchip/next, thanks!
Andyshrk May 27, 2017, 6:58 a.m. UTC | #3
Philipp, Simon:

2017-04-17 23:48 GMT+08:00 Philipp Tomsich <
philipp.tomsich@theobroma-systems.com>:

> This change set adds documentation to the header0 initialisation and
> improves readability for the calculations of various offsets/lengths.
>
> As the U-Boot SPL stage doesn't use any payload beyond what is covered
> by init_size, we no longer add RK_MAX_BOOT_SIZE to init_boot_size.
>


    I thinks this is one case that break BACK_TO_BROM  function. The
bootrom code will reads init_boot_size to get the size of the second level
loader(such as uboot) to load from storage to sdram when the BACK_TO_BROM
function enabled. This patch set init_boot_size to init_size, so the
bootrom will think that there is no second level bootloader, so it won't
load it and jump to it.

>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> ---
>
>  tools/rkcommon.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/tools/rkcommon.c b/tools/rkcommon.c
> index cfd40ac..ed29ef9 100644
> --- a/tools/rkcommon.c
> +++ b/tools/rkcommon.c
> @@ -13,6 +13,8 @@
>  #include "mkimage.h"
>  #include "rkcommon.h"
>
> +#define DIV_ROUND_UP(n, d)     (((n) + (d) - 1) / (d))
> +
>  enum {
>         RK_SIGNATURE            = 0x0ff0aa55,
>  };
> @@ -159,9 +161,21 @@ static void rkcommon_set_header0(void *buf, uint
> file_size,
>         hdr->disable_rc4 = !rkcommon_need_rc4_spl(params);
>         hdr->init_offset = RK_INIT_OFFSET;
>
> -       hdr->init_size = (file_size + RK_BLK_SIZE - 1) / RK_BLK_SIZE;
> -       hdr->init_size = (hdr->init_size + 3) & ~3;
> -       hdr->init_boot_size = hdr->init_size + RK_MAX_BOOT_SIZE /
> RK_BLK_SIZE;
> +       hdr->init_size = DIV_ROUND_UP(file_size, RK_BLK_SIZE);
> +       /*
> +        * The init_size has to be a multiple of 4 blocks (i.e. of 2K)
> +        * or the BootROM will not boot the image.
> +        *
> +        * Note: To verify that this is not a legacy constraint, we
> +        *       rechecked this against the RK3399 BootROM.
> +        */
> +       hdr->init_size = ROUND(hdr->init_size, 4);
> +       /*
> +        * The images we create do not contain the stage following the SPL
> as
> +        * part of the SPL image, so the init_boot_size (which might have
> been
> +        * read by Rockchip's miniloder) should be the same as the
> init_size.
> +        */
> +       hdr->init_boot_size = hdr->init_size;
>
>         rc4_encode(buf, RK_BLK_SIZE, rc4_key);
>  }
> --
> 1.9.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
>
diff mbox

Patch

diff --git a/tools/rkcommon.c b/tools/rkcommon.c
index cfd40ac..ed29ef9 100644
--- a/tools/rkcommon.c
+++ b/tools/rkcommon.c
@@ -13,6 +13,8 @@ 
 #include "mkimage.h"
 #include "rkcommon.h"
 
+#define DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
+
 enum {
 	RK_SIGNATURE		= 0x0ff0aa55,
 };
@@ -159,9 +161,21 @@  static void rkcommon_set_header0(void *buf, uint file_size,
 	hdr->disable_rc4 = !rkcommon_need_rc4_spl(params);
 	hdr->init_offset = RK_INIT_OFFSET;
 
-	hdr->init_size = (file_size + RK_BLK_SIZE - 1) / RK_BLK_SIZE;
-	hdr->init_size = (hdr->init_size + 3) & ~3;
-	hdr->init_boot_size = hdr->init_size + RK_MAX_BOOT_SIZE / RK_BLK_SIZE;
+	hdr->init_size = DIV_ROUND_UP(file_size, RK_BLK_SIZE);
+	/*
+	 * The init_size has to be a multiple of 4 blocks (i.e. of 2K)
+	 * or the BootROM will not boot the image.
+	 *
+	 * Note: To verify that this is not a legacy constraint, we
+	 *       rechecked this against the RK3399 BootROM.
+	 */
+	hdr->init_size = ROUND(hdr->init_size, 4);
+	/*
+	 * The images we create do not contain the stage following the SPL as
+	 * part of the SPL image, so the init_boot_size (which might have been
+	 * read by Rockchip's miniloder) should be the same as the init_size.
+	 */
+	hdr->init_boot_size = hdr->init_size;
 
 	rc4_encode(buf, RK_BLK_SIZE, rc4_key);
 }