public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Priyanka Jain <priyanka.jain@nxp.com>,
	Qiang Zhao <qiang.zhao@nxp.com>,
	Shengzhou Liu <Shengzhou.Liu@nxp.com>,
	Alexander Graf <agraf@csgraf.de>, Bin Meng <bmeng.cn@gmail.com>,
	Wolfgang Denk <wd@denx.de>, Sinan Akman <sinan@writeme.com>
Cc: u-boot@lists.denx.de
Subject: [PATCH 1/2] powerpc: mpc85xx: Add support for generating QorIQ pre-PBL eSDHC boot sector
Date: Tue,  5 Apr 2022 15:40:31 +0200	[thread overview]
Message-ID: <20220405134032.704-2-pali@kernel.org> (raw)
In-Reply-To: <20220405134032.704-1-pali@kernel.org>

QorIQ U-Boot binary for SD card booting compiled during build process
(either u-boot.bin or u-boot-with-spl.bin) cannot be directly loaded by
QorIQ pre-PBL BootROM. Compiled U-Boot binary first needs to be processed
by Freescale boot_format tool as described in doc/README.mpc85xx-sd-spi-boot

BootROM requires that image on SD card must contain special boot sector.
Implement support for generating this special boot sector directly in
U-Boot start code. Boot sector needs to be at the beginning of the image,
so when compiling only proper U-Boot without SPL then it needs to be in
proper U-Boot. When compiling SPL with proper U-Boot then it needs to be
only in SPL.

Support can be enabled by a new config option FSL_PREPBL_ESDHC_BOOT_SECTOR.
Via other two additional options FSL_PREPBL_ESDHC_BOOT_SECTOR_START and
FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA it is possible to tune how final U-Boot
image could be stored on the SD card.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 arch/powerpc/cpu/mpc85xx/Kconfig        | 53 +++++++++++++++
 arch/powerpc/cpu/mpc85xx/start.S        | 86 +++++++++++++++++++++++++
 arch/powerpc/cpu/mpc85xx/u-boot-spl.lds |  5 ++
 arch/powerpc/cpu/mpc85xx/u-boot.lds     |  5 ++
 4 files changed, 149 insertions(+)

diff --git a/arch/powerpc/cpu/mpc85xx/Kconfig b/arch/powerpc/cpu/mpc85xx/Kconfig
index c308447d493a..6f8b7593d250 100644
--- a/arch/powerpc/cpu/mpc85xx/Kconfig
+++ b/arch/powerpc/cpu/mpc85xx/Kconfig
@@ -12,6 +12,59 @@ config CMD_ERRATA
 	  This enables the 'errata' command which displays a list of errata
 	  work-arounds which are enabled for the current board.
 
+config FSL_PREPBL_ESDHC_BOOT_SECTOR
+	bool "Generate QorIQ pre-PBL eSDHC boot sector"
+	depends on MPC85xx
+	depends on SYS_EXTRA_OPTIONS = SDCARD
+	help
+	  With this option final image would have prepended QorIQ pre-PBL eSDHC
+	  boot sector suitable for SD card images. This boot sector instruct
+	  BootROM to configure L2 SRAM and eSDHC then load image from SD card
+	  into L2 SRAM and finally jump to image entry point.
+
+	  This is alternative to Freescale boot_format tool, but works only for
+	  SD card images and only for L2 SRAM booting. U-Boot images generated
+	  with this option should not passed to boot_format tool.
+
+	  For other configuration like booting from eSPI or configuring SDRAM
+	  please use Freescale boot_format tool without this option. See file
+	  doc/README.mpc85xx-sd-spi-boot
+
+config FSL_PREPBL_ESDHC_BOOT_SECTOR_START
+	int "QorIQ pre-PBL eSDHC boot sector start offset"
+	depends on FSL_PREPBL_ESDHC_BOOT_SECTOR
+	range 0 23
+	default 0
+	help
+	  QorIQ pre-PBL eSDHC boot sector may be located on one of the first
+	  24 SD card sectors. Select SD card sector on which final U-Boot
+	  image (with this boot sector) would be installed.
+
+	  By default first SD card sector (0) is used. But this may be changed
+	  to allow installing U-Boot image on some partition (with fixed start
+	  sector).
+
+	  Please note that any sector on SD card prior this boot sector must
+	  not contain ASCII "BOOT" bytes at sector offset 0x40.
+
+config FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA
+	int "Relative data sector for QorIQ pre-PBL eSDHC boot sector"
+	depends on FSL_PREPBL_ESDHC_BOOT_SECTOR
+	default 1
+	range 1 8388607
+	help
+	  Select data sector from the beginning of QorIQ pre-PBL eSDHC boot
+	  sector on which would be stored raw U-Boot image.
+
+	  By default is it second sector (1) which is the first available free
+	  sector (on the first sector is stored boot sector). It can be any
+	  sector number which offset in bytes can be expressed by 32-bit number.
+
+	  In case this final U-Boot image (with this boot sector) is put on
+	  the FAT32 partition into reserved boot area, this data sector needs
+	  to be at least 2 (third sector) because FAT32 use second sector for
+	  its data.
+
 choice
 	prompt "Target select"
 	optional
diff --git a/arch/powerpc/cpu/mpc85xx/start.S b/arch/powerpc/cpu/mpc85xx/start.S
index 796a58b929ec..50b23a97662c 100644
--- a/arch/powerpc/cpu/mpc85xx/start.S
+++ b/arch/powerpc/cpu/mpc85xx/start.S
@@ -56,6 +56,92 @@
 	GOT_ENTRY(__bss_start)
 	END_GOT
 
+#ifdef CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR
+#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
+
+/* Maximal size of the image */
+#ifdef CONFIG_SPL_BUILD
+#define MAX_IMAGE_SIZE (CONFIG_SPL_MAX_SIZE - (CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA * 512))
+#else
+#define MAX_IMAGE_SIZE CONFIG_SYS_L2_SIZE
+#endif
+
+#if defined(CONFIG_SPL_BUILD) && CONFIG_SPL_MAX_SIZE < CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA * 512
+#error "CONFIG_SPL_MAX_SIZE is too small for CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA"
+#endif
+
+#if MAX_IMAGE_SIZE > CONFIG_SYS_L2_SIZE
+#error "Image is too big"
+#endif
+
+#define DIV_ROUND_UP(a, b) (((a) + (b) - 1) / (b))
+#define ALIGN(x, a) (DIV_ROUND_UP(x, a) * (a))
+
+/* Definitions from C header file asm/immap_85xx.h */
+#define MPC85xx_L2CTL_L2E			0x80000000
+#define MPC85xx_L2CTL_L2SRAM_ENTIRE		0x00010000
+#define MPC85xx_L2ERRDIS_MBECC			0x00000008
+#define MPC85xx_L2ERRDIS_SBECC			0x00000004
+
+/* Definitions from C header file fsl_esdhc.h */
+#define ESDHCCTL_SNOOP				0x00000040
+
+/*
+ * QorIQ pre-PBL eSDHC boot sector:
+ * Instruct BootROM to configure L2 SRAM and eSDHC then load image
+ * from SD card into L2 SRAM and finally jump to image entry point.
+ */
+	.section .bootsect, "a"
+	.globl bootsect
+
+bootsect:
+	b _start /* Make boot sector bootable, jump to entry point, but this is not needed at all */
+
+	.org 0x40 /* BOOT signature */
+	.ascii "BOOT"
+
+	.org 0x48 /* Number of bytes to be copied, must be multiple of block size (512) */
+	.long ALIGN(MAX_IMAGE_SIZE, 512)
+
+	.org 0x50 /* Source address from the beginning of boot sector in byte address format, must be multiple of block size (512) */
+	.long (CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_START + CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA) * 512
+
+	.org 0x58 /* Target address in the system's local memory address space */
+	.long CONFIG_SYS_MONITOR_BASE + CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA * 512
+
+	.org 0x60 /* Execution starting address */
+	.long _start
+
+	.org 0x68 /* Number of configuration data pairs */
+	.long DIV_ROUND_UP(.Lconf_pair_end - .Lconf_pair_start, 8)
+
+	.org 0x80 /* Start of configuration */
+	.Lconf_pair_start:
+
+	.long 0xff720100 /* Address: L2 memory-mapped SRAM base addr 0 */
+	.long CONFIG_SYS_INIT_L2_ADDR
+
+	.long 0xff720e44 /* Address: L2 cache error disable */
+	.long MPC85xx_L2ERRDIS_MBECC | MPC85xx_L2ERRDIS_SBECC
+
+	.long 0xff720000 /* Address: L2 configuration 0 */
+	.long MPC85xx_L2CTL_L2E | MPC85xx_L2CTL_L2SRAM_ENTIRE
+
+	.long 0xff72e40c /* Address: eSDHC DMA control */
+	.long ESDHCCTL_SNOOP
+
+	.long 0x40000001 /* Command: Delay in 8 CCB clocks */
+	.long 256
+
+	.long 0x80000001 /* End of configuration */
+	.Lconf_pair_end:
+
+	.org 0x1b8 /* Reserved for MBR/DBR */
+	.org 0x200 /* End of boot sector */
+
+#endif
+#endif
+
 /*
  * e500 Startup -- after reset only the last 4KB of the effective
  * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
diff --git a/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds b/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds
index 6fd0da9f39b1..272e94a1f169 100644
--- a/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds
+++ b/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds
@@ -14,6 +14,11 @@ SECTIONS
 {
 	. = IMAGE_TEXT_BASE;
 	.text : {
+/* Optional boot sector */
+#if defined(CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR)
+		KEEP(*(.bootsect))
+		. = CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA * 512;
+#endif
 /* For ifc, elbc, esdhc, espi, all need the SPL without section .resetvec */
 #ifdef CONFIG_SYS_MPC85XX_NO_RESETVEC
 		KEEP(*(.bootpg))
diff --git a/arch/powerpc/cpu/mpc85xx/u-boot.lds b/arch/powerpc/cpu/mpc85xx/u-boot.lds
index 9f422810bb5d..4754aa1cf8e8 100644
--- a/arch/powerpc/cpu/mpc85xx/u-boot.lds
+++ b/arch/powerpc/cpu/mpc85xx/u-boot.lds
@@ -19,6 +19,11 @@ SECTIONS
   /* Read-only sections, merged into text segment: */
   .text      :
   {
+#if defined(CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR) && !defined(CONFIG_SPL)
+    /* Optional boot sector */
+    KEEP(arch/powerpc/cpu/mpc85xx/start.o (.bootsect))
+    . = CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA * 512;
+#endif
 #ifdef CONFIG_SYS_MPC85XX_NO_RESETVEC
     KEEP(arch/powerpc/cpu/mpc85xx/start.o (.bootpg))
 #endif
-- 
2.20.1


  reply	other threads:[~2022-04-05 13:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05 13:40 [PATCH 0/2] powerpc: mpc85xx: Add support for generating QorIQ pre-PBL eSDHC boot sector Pali Rohár
2022-04-05 13:40 ` Pali Rohár [this message]
2022-04-25  5:25   ` [PATCH 1/2] " Priyanka Jain (OSS)
2022-04-25 12:36     ` Pali Rohár
2022-05-11 20:59       ` Pali Rohár
2022-05-18 10:53         ` Pali Rohár
2022-06-04 13:02           ` Pali Rohár
2022-06-23 17:17             ` Pali Rohár
2022-06-28 18:07               ` Pali Rohár
2022-06-28 18:14                 ` Tom Rini
2022-07-13 23:49                 ` Pali Rohár
2022-07-21 22:49                   ` Pali Rohár
2022-05-11 18:57   ` [PATCH v2] " Pali Rohár
2022-04-05 13:40 ` [PATCH 2/2] board: freescale: p1_p2_rdb_pc: Calculate offsets for " Pali Rohár
2022-08-01 12:50   ` [PATCH v2] " Pali Rohár
2022-08-17 21:03     ` Pali Rohár
2022-09-07  3:02       ` Peng Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220405134032.704-2-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=Shengzhou.Liu@nxp.com \
    --cc=agraf@csgraf.de \
    --cc=bmeng.cn@gmail.com \
    --cc=priyanka.jain@nxp.com \
    --cc=qiang.zhao@nxp.com \
    --cc=sinan@writeme.com \
    --cc=u-boot@lists.denx.de \
    --cc=wd@denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox