All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support
@ 2022-04-04 16:33 Pali Rohár
  2022-04-22 12:32 ` Jaehoon Chung
  0 siblings, 1 reply; 4+ messages in thread
From: Pali Rohár @ 2022-04-04 16:33 UTC (permalink / raw)
  To: Priyanka Jain, Peng Fan, Jaehoon Chung; +Cc: u-boot

QorIQ pre-PBL BootROM scans first 24 SD card sectors (each with fixed 512
bytes length) for boot signature. Implement same redundancy behavior in
fsl_esdhc_spl driver to allow loading proper U-Boot when boot sector is not
the first one.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c
index 0146a231b221..ea8f4cd66964 100644
--- a/drivers/mmc/fsl_esdhc_spl.c
+++ b/drivers/mmc/fsl_esdhc_spl.c
@@ -20,7 +20,6 @@
 #define ESDHC_BOOT_IMAGE_ADDR	0x50
 #define MBRDBR_BOOT_SIG_55	0x1fe
 #define MBRDBR_BOOT_SIG_AA	0x1ff
-#define CONFIG_CFG_DATA_SECTOR	0
 
 
 void mmc_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
@@ -62,11 +61,13 @@ void __noreturn mmc_boot(void)
 #ifndef CONFIG_FSL_CORENET
 	uchar *tmp_buf;
 	u32 blklen;
+	u32 blk_off;
 	uchar val;
 #ifndef CONFIG_SPL_FSL_PBL
 	u32 val32;
 #endif
 	uint i, byte_num;
+	u32 sector;
 #endif
 	u32 offset, code_len;
 	struct mmc *mmc;
@@ -86,30 +87,37 @@ void __noreturn mmc_boot(void)
 	offset = CONFIG_SYS_MMC_U_BOOT_OFFS;
 #else
 	blklen = mmc->read_bl_len;
+	if (blklen < 512)
+		blklen = 512;
 	tmp_buf = malloc(blklen);
 	if (!tmp_buf) {
 		puts("spl: malloc memory failed!!\n");
 		hang();
 	}
+
+	sector = 0;
+again:
 	memset(tmp_buf, 0, blklen);
 
 	/*
 	* Read source addr from sd card
 	*/
-	err = mmc->block_dev.block_read(&mmc->block_dev,
-					CONFIG_CFG_DATA_SECTOR, 1, tmp_buf);
+	blk_start = (sector * 512) / mmc->read_bl_len;
+	blk_off = (sector * 512) % mmc->read_bl_len;
+	blk_cnt = DIV_ROUND_UP(512,  mmc->read_bl_len);
+	err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt, tmp_buf);
 	if (err != 1) {
 		puts("spl: mmc read failed!!\n");
 		hang();
 	}
 
 #ifdef CONFIG_SPL_FSL_PBL
-	val = *(tmp_buf + MBRDBR_BOOT_SIG_55);
+	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_55);
 	if (0x55 != val) {
 		puts("spl: mmc MBR/DBR signature is not valid!!\n");
 		hang();
 	}
-	val = *(tmp_buf + MBRDBR_BOOT_SIG_AA);
+	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_AA);
 	if (0xAA != val) {
 		puts("spl: mmc MBR/DBR signature is not valid!!\n");
 		hang();
@@ -123,10 +131,13 @@ void __noreturn mmc_boot(void)
 	byte_num = 4;
 	val32 = 0;
 	for (i = 0; i < byte_num; i++) {
-		val = *(tmp_buf + ESDHC_BOOT_SIGNATURE_OFF + i);
+		val = *(tmp_buf + blk_off + ESDHC_BOOT_SIGNATURE_OFF + i);
 		val32 = (val32 << 8) + val;
 	}
 	if (val32 != ESDHC_BOOT_SIGNATURE) {
+		/* BOOT signature may be on the first 24 sectors (each being 512 bytes) */
+		if (++sector < 24)
+			goto again;
 		puts("spl: mmc BOOT signature is not valid!!\n");
 		hang();
 	}
@@ -135,7 +146,7 @@ void __noreturn mmc_boot(void)
 	byte_num = 4;
 	offset = 0;
 	for (i = 0; i < byte_num; i++) {
-		val = *(tmp_buf + ESDHC_BOOT_IMAGE_ADDR + i);
+		val = *(tmp_buf + blk_off + ESDHC_BOOT_IMAGE_ADDR + i);
 		offset = (offset << 8) + val;
 	}
 	offset += CONFIG_SYS_MMC_U_BOOT_OFFS;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support
  2022-04-04 16:33 [PATCH] mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support Pali Rohár
@ 2022-04-22 12:32 ` Jaehoon Chung
  2022-04-22 12:39   ` Pali Rohár
  0 siblings, 1 reply; 4+ messages in thread
From: Jaehoon Chung @ 2022-04-22 12:32 UTC (permalink / raw)
  To: Pali Rohár, Priyanka Jain, Peng Fan, Jaehoon Chung; +Cc: u-boot



On 4/5/22 01:33, Pali Rohár wrote:
> QorIQ pre-PBL BootROM scans first 24 SD card sectors (each with fixed 512
> bytes length) for boot signature. Implement same redundancy behavior in
> fsl_esdhc_spl driver to allow loading proper U-Boot when boot sector is not
> the first one.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c
> index 0146a231b221..ea8f4cd66964 100644
> --- a/drivers/mmc/fsl_esdhc_spl.c
> +++ b/drivers/mmc/fsl_esdhc_spl.c
> @@ -20,7 +20,6 @@
>  #define ESDHC_BOOT_IMAGE_ADDR	0x50
>  #define MBRDBR_BOOT_SIG_55	0x1fe
>  #define MBRDBR_BOOT_SIG_AA	0x1ff
> -#define CONFIG_CFG_DATA_SECTOR	0
>  
>  
>  void mmc_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
> @@ -62,11 +61,13 @@ void __noreturn mmc_boot(void)
>  #ifndef CONFIG_FSL_CORENET
>  	uchar *tmp_buf;
>  	u32 blklen;
> +	u32 blk_off;
>  	uchar val;
>  #ifndef CONFIG_SPL_FSL_PBL
>  	u32 val32;
>  #endif
>  	uint i, byte_num;
> +	u32 sector;
>  #endif
>  	u32 offset, code_len;
>  	struct mmc *mmc;
> @@ -86,30 +87,37 @@ void __noreturn mmc_boot(void)
>  	offset = CONFIG_SYS_MMC_U_BOOT_OFFS;
>  #else
>  	blklen = mmc->read_bl_len;
> +	if (blklen < 512)
> +		blklen = 512;
>  	tmp_buf = malloc(blklen);
>  	if (!tmp_buf) {
>  		puts("spl: malloc memory failed!!\n");
>  		hang();
>  	}
> +
> +	sector = 0;

Why does it assign to 0 at here? Doesn't initialize this at above?
Does it need to check whether CONFIG_SPL_FSL_PBL enabled or not?

Best Regards,
Jaehoon Chung

> +again:
>  	memset(tmp_buf, 0, blklen);
>  
>  	/*
>  	* Read source addr from sd card
>  	*/
> -	err = mmc->block_dev.block_read(&mmc->block_dev,
> -					CONFIG_CFG_DATA_SECTOR, 1, tmp_buf);
> +	blk_start = (sector * 512) / mmc->read_bl_len;
> +	blk_off = (sector * 512) % mmc->read_bl_len;
> +	blk_cnt = DIV_ROUND_UP(512,  mmc->read_bl_len);
> +	err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt, tmp_buf);
>  	if (err != 1) {
>  		puts("spl: mmc read failed!!\n");
>  		hang();
>  	}
>  
>  #ifdef CONFIG_SPL_FSL_PBL
> -	val = *(tmp_buf + MBRDBR_BOOT_SIG_55);
> +	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_55);
>  	if (0x55 != val) {
>  		puts("spl: mmc MBR/DBR signature is not valid!!\n");
>  		hang();
>  	}
> -	val = *(tmp_buf + MBRDBR_BOOT_SIG_AA);
> +	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_AA);
>  	if (0xAA != val) {
>  		puts("spl: mmc MBR/DBR signature is not valid!!\n");
>  		hang();
> @@ -123,10 +131,13 @@ void __noreturn mmc_boot(void)
>  	byte_num = 4;
>  	val32 = 0;
>  	for (i = 0; i < byte_num; i++) {
> -		val = *(tmp_buf + ESDHC_BOOT_SIGNATURE_OFF + i);
> +		val = *(tmp_buf + blk_off + ESDHC_BOOT_SIGNATURE_OFF + i);
>  		val32 = (val32 << 8) + val;
>  	}
>  	if (val32 != ESDHC_BOOT_SIGNATURE) {
> +		/* BOOT signature may be on the first 24 sectors (each being 512 bytes) */
> +		if (++sector < 24)
> +			goto again;
>  		puts("spl: mmc BOOT signature is not valid!!\n");
>  		hang();
>  	}
> @@ -135,7 +146,7 @@ void __noreturn mmc_boot(void)
>  	byte_num = 4;
>  	offset = 0;
>  	for (i = 0; i < byte_num; i++) {
> -		val = *(tmp_buf + ESDHC_BOOT_IMAGE_ADDR + i);
> +		val = *(tmp_buf + blk_off + ESDHC_BOOT_IMAGE_ADDR + i);
>  		offset = (offset << 8) + val;
>  	}
>  	offset += CONFIG_SYS_MMC_U_BOOT_OFFS;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support
  2022-04-22 12:32 ` Jaehoon Chung
@ 2022-04-22 12:39   ` Pali Rohár
  2022-04-22 13:01     ` Jaehoon Chung
  0 siblings, 1 reply; 4+ messages in thread
From: Pali Rohár @ 2022-04-22 12:39 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Priyanka Jain, Peng Fan, Jaehoon Chung, u-boot

On Friday 22 April 2022 21:32:54 Jaehoon Chung wrote:
> On 4/5/22 01:33, Pali Rohár wrote:
> > QorIQ pre-PBL BootROM scans first 24 SD card sectors (each with fixed 512
> > bytes length) for boot signature. Implement same redundancy behavior in
> > fsl_esdhc_spl driver to allow loading proper U-Boot when boot sector is not
> > the first one.
> > 
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > ---
> >  drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++-------
> >  1 file changed, 18 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c
> > index 0146a231b221..ea8f4cd66964 100644
> > --- a/drivers/mmc/fsl_esdhc_spl.c
> > +++ b/drivers/mmc/fsl_esdhc_spl.c
> > @@ -20,7 +20,6 @@
> >  #define ESDHC_BOOT_IMAGE_ADDR	0x50
> >  #define MBRDBR_BOOT_SIG_55	0x1fe
> >  #define MBRDBR_BOOT_SIG_AA	0x1ff
> > -#define CONFIG_CFG_DATA_SECTOR	0
> >  
> >  
> >  void mmc_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
> > @@ -62,11 +61,13 @@ void __noreturn mmc_boot(void)
> >  #ifndef CONFIG_FSL_CORENET
> >  	uchar *tmp_buf;
> >  	u32 blklen;
> > +	u32 blk_off;
> >  	uchar val;
> >  #ifndef CONFIG_SPL_FSL_PBL
> >  	u32 val32;
> >  #endif
> >  	uint i, byte_num;
> > +	u32 sector;
> >  #endif
> >  	u32 offset, code_len;
> >  	struct mmc *mmc;
> > @@ -86,30 +87,37 @@ void __noreturn mmc_boot(void)
> >  	offset = CONFIG_SYS_MMC_U_BOOT_OFFS;
> >  #else
> >  	blklen = mmc->read_bl_len;
> > +	if (blklen < 512)
> > +		blklen = 512;
> >  	tmp_buf = malloc(blklen);
> >  	if (!tmp_buf) {
> >  		puts("spl: malloc memory failed!!\n");
> >  		hang();
> >  	}
> > +
> > +	sector = 0;
> 
> Why does it assign to 0 at here? Doesn't initialize this at above?

All variables in this file are initialized after declaration. So I used
this same coding style also for newly introduced variables.

> Does it need to check whether CONFIG_SPL_FSL_PBL enabled or not?

This redundancy (retry) is implemented only for pre-PBL BootROMs (when
CONFIG_SPL_FSL_PBL is not enabled). I do not know how it works in PBL
BootROMs, so PBL code scans only sector 0, like before.

> Best Regards,
> Jaehoon Chung
> 
> > +again:
> >  	memset(tmp_buf, 0, blklen);
> >  
> >  	/*
> >  	* Read source addr from sd card
> >  	*/
> > -	err = mmc->block_dev.block_read(&mmc->block_dev,
> > -					CONFIG_CFG_DATA_SECTOR, 1, tmp_buf);
> > +	blk_start = (sector * 512) / mmc->read_bl_len;
> > +	blk_off = (sector * 512) % mmc->read_bl_len;
> > +	blk_cnt = DIV_ROUND_UP(512,  mmc->read_bl_len);
> > +	err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt, tmp_buf);
> >  	if (err != 1) {
> >  		puts("spl: mmc read failed!!\n");
> >  		hang();
> >  	}
> >  
> >  #ifdef CONFIG_SPL_FSL_PBL
> > -	val = *(tmp_buf + MBRDBR_BOOT_SIG_55);
> > +	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_55);
> >  	if (0x55 != val) {
> >  		puts("spl: mmc MBR/DBR signature is not valid!!\n");
> >  		hang();
> >  	}
> > -	val = *(tmp_buf + MBRDBR_BOOT_SIG_AA);
> > +	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_AA);
> >  	if (0xAA != val) {
> >  		puts("spl: mmc MBR/DBR signature is not valid!!\n");
> >  		hang();
> > @@ -123,10 +131,13 @@ void __noreturn mmc_boot(void)
> >  	byte_num = 4;
> >  	val32 = 0;
> >  	for (i = 0; i < byte_num; i++) {
> > -		val = *(tmp_buf + ESDHC_BOOT_SIGNATURE_OFF + i);
> > +		val = *(tmp_buf + blk_off + ESDHC_BOOT_SIGNATURE_OFF + i);
> >  		val32 = (val32 << 8) + val;
> >  	}
> >  	if (val32 != ESDHC_BOOT_SIGNATURE) {
> > +		/* BOOT signature may be on the first 24 sectors (each being 512 bytes) */
> > +		if (++sector < 24)
> > +			goto again;
> >  		puts("spl: mmc BOOT signature is not valid!!\n");
> >  		hang();
> >  	}
> > @@ -135,7 +146,7 @@ void __noreturn mmc_boot(void)
> >  	byte_num = 4;
> >  	offset = 0;
> >  	for (i = 0; i < byte_num; i++) {
> > -		val = *(tmp_buf + ESDHC_BOOT_IMAGE_ADDR + i);
> > +		val = *(tmp_buf + blk_off + ESDHC_BOOT_IMAGE_ADDR + i);
> >  		offset = (offset << 8) + val;
> >  	}
> >  	offset += CONFIG_SYS_MMC_U_BOOT_OFFS;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support
  2022-04-22 12:39   ` Pali Rohár
@ 2022-04-22 13:01     ` Jaehoon Chung
  0 siblings, 0 replies; 4+ messages in thread
From: Jaehoon Chung @ 2022-04-22 13:01 UTC (permalink / raw)
  To: Pali Rohár; +Cc: Priyanka Jain, Peng Fan, Jaehoon Chung, u-boot


On 4/22/22 21:39, Pali Rohár wrote:
> On Friday 22 April 2022 21:32:54 Jaehoon Chung wrote:
>> On 4/5/22 01:33, Pali Rohár wrote:
>>> QorIQ pre-PBL BootROM scans first 24 SD card sectors (each with fixed 512
>>> bytes length) for boot signature. Implement same redundancy behavior in
>>> fsl_esdhc_spl driver to allow loading proper U-Boot when boot sector is not
>>> the first one.
>>>
>>> Signed-off-by: Pali Rohár <pali@kernel.org>
>>> ---
>>>  drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++-------
>>>  1 file changed, 18 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c
>>> index 0146a231b221..ea8f4cd66964 100644
>>> --- a/drivers/mmc/fsl_esdhc_spl.c
>>> +++ b/drivers/mmc/fsl_esdhc_spl.c
>>> @@ -20,7 +20,6 @@
>>>  #define ESDHC_BOOT_IMAGE_ADDR	0x50
>>>  #define MBRDBR_BOOT_SIG_55	0x1fe
>>>  #define MBRDBR_BOOT_SIG_AA	0x1ff
>>> -#define CONFIG_CFG_DATA_SECTOR	0
>>>  
>>>  
>>>  void mmc_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
>>> @@ -62,11 +61,13 @@ void __noreturn mmc_boot(void)
>>>  #ifndef CONFIG_FSL_CORENET
>>>  	uchar *tmp_buf;
>>>  	u32 blklen;
>>> +	u32 blk_off;
>>>  	uchar val;
>>>  #ifndef CONFIG_SPL_FSL_PBL
>>>  	u32 val32;
>>>  #endif
>>>  	uint i, byte_num;
>>> +	u32 sector;
>>>  #endif
>>>  	u32 offset, code_len;
>>>  	struct mmc *mmc;
>>> @@ -86,30 +87,37 @@ void __noreturn mmc_boot(void)
>>>  	offset = CONFIG_SYS_MMC_U_BOOT_OFFS;
>>>  #else
>>>  	blklen = mmc->read_bl_len;
>>> +	if (blklen < 512)
>>> +		blklen = 512;
>>>  	tmp_buf = malloc(blklen);
>>>  	if (!tmp_buf) {
>>>  		puts("spl: malloc memory failed!!\n");
>>>  		hang();
>>>  	}
>>> +
>>> +	sector = 0;
>> Why does it assign to 0 at here? Doesn't initialize this at above?
> All variables in this file are initialized after declaration. So I used
> this same coding style also for newly introduced variables.
>
>> Does it need to check whether CONFIG_SPL_FSL_PBL enabled or not?
> This redundancy (retry) is implemented only for pre-PBL BootROMs (when
> CONFIG_SPL_FSL_PBL is not enabled). I do not know how it works in PBL
> BootROMs, so PBL code scans only sector 0, like before.


It's my mistake. I didn't see "#else"  for CONFIG_FSL_CORENET. Discard previous my comment.


Beet Regards,

Jaehoon Chung


>
>> Best Regards,
>> Jaehoon Chung
>>
>>> +again:
>>>  	memset(tmp_buf, 0, blklen);
>>>  
>>>  	/*
>>>  	* Read source addr from sd card
>>>  	*/
>>> -	err = mmc->block_dev.block_read(&mmc->block_dev,
>>> -					CONFIG_CFG_DATA_SECTOR, 1, tmp_buf);
>>> +	blk_start = (sector * 512) / mmc->read_bl_len;
>>> +	blk_off = (sector * 512) % mmc->read_bl_len;
>>> +	blk_cnt = DIV_ROUND_UP(512,  mmc->read_bl_len);
>>> +	err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt, tmp_buf);
>>>  	if (err != 1) {
>>>  		puts("spl: mmc read failed!!\n");
>>>  		hang();
>>>  	}
>>>  
>>>  #ifdef CONFIG_SPL_FSL_PBL
>>> -	val = *(tmp_buf + MBRDBR_BOOT_SIG_55);
>>> +	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_55);
>>>  	if (0x55 != val) {
>>>  		puts("spl: mmc MBR/DBR signature is not valid!!\n");
>>>  		hang();
>>>  	}
>>> -	val = *(tmp_buf + MBRDBR_BOOT_SIG_AA);
>>> +	val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_AA);
>>>  	if (0xAA != val) {
>>>  		puts("spl: mmc MBR/DBR signature is not valid!!\n");
>>>  		hang();
>>> @@ -123,10 +131,13 @@ void __noreturn mmc_boot(void)
>>>  	byte_num = 4;
>>>  	val32 = 0;
>>>  	for (i = 0; i < byte_num; i++) {
>>> -		val = *(tmp_buf + ESDHC_BOOT_SIGNATURE_OFF + i);
>>> +		val = *(tmp_buf + blk_off + ESDHC_BOOT_SIGNATURE_OFF + i);
>>>  		val32 = (val32 << 8) + val;
>>>  	}
>>>  	if (val32 != ESDHC_BOOT_SIGNATURE) {
>>> +		/* BOOT signature may be on the first 24 sectors (each being 512 bytes) */
>>> +		if (++sector < 24)
>>> +			goto again;
>>>  		puts("spl: mmc BOOT signature is not valid!!\n");
>>>  		hang();
>>>  	}
>>> @@ -135,7 +146,7 @@ void __noreturn mmc_boot(void)
>>>  	byte_num = 4;
>>>  	offset = 0;
>>>  	for (i = 0; i < byte_num; i++) {
>>> -		val = *(tmp_buf + ESDHC_BOOT_IMAGE_ADDR + i);
>>> +		val = *(tmp_buf + blk_off + ESDHC_BOOT_IMAGE_ADDR + i);
>>>  		offset = (offset << 8) + val;
>>>  	}
>>>  	offset += CONFIG_SYS_MMC_U_BOOT_OFFS;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-22 13:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 16:33 [PATCH] mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support Pali Rohár
2022-04-22 12:32 ` Jaehoon Chung
2022-04-22 12:39   ` Pali Rohár
2022-04-22 13:01     ` Jaehoon Chung

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.