Skip to contentSkip to conversation

arm: socfpga: soc64: Move spl_board_prepare_for_boot()

PATCH New Jit Loon Lim 1 participant 5 messages Sep 18, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 arm: socfpga: soc64: Move spl_board_prepare_for_boot()

From: Ley Foon Tan <[email protected]>

Move spl_board_prepare_for_boot() to spl_soc64.c.

spl_board_prepare_for_boot() will use for all SoC64 platforms.

---
 arch/arm/mach-socfpga/spl_soc64.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-socfpga/spl_soc64.c +6 -0
index ba6efc1d86..f3fa1ae361 100644
@@ -23,3 +23,9 @@ u32 spl_boot_mode(const u32 boot_device)
 		return MMCSD_MODE_RAW;
 }
 #endif
+
+/* board specific function prior loading SSBL / U-Boot */
+void spl_board_prepare_for_boot(void)
+{
+	mbox_hps_stage_notify(HPS_EXECUTION_STATE_SSBL);
+}
Signature · 1 line
2.26.2
#2 lore raw

PATCH 3/5 arm: socfpga: soc64: Move socfpga_init_smmu() to before boot SSBL

From: Ley Foon Tan <[email protected]>

socfpga_init_smmu() change the L3 masters (eg: SDMMC, NAND and etc) to non-secure , this cause the failure when L3 masters loading SSBL image to secure region in DDR.

Move socfpga_init_smmu() to spl_perform_fixups(), so, it is called prior running SSBL.

---
 arch/arm/mach-socfpga/spl_agilex.c            |  1 +
 .../mach-socfpga/{spl_agilex.c => spl_dm.c}   | 38 +++++++------------
 arch/arm/mach-socfpga/spl_soc64.c             |  3 ++
 3 files changed, 18 insertions(+), 24 deletions(-)
 copy arch/arm/mach-socfpga/{spl_agilex.c => spl_dm.c} (82%)
arch/arm/mach-socfpga/spl_agilex.c +1 -0
index ee5a9dc1e2..f137b71e99 100644
@@ -65,6 +65,7 @@ void board_init_f(ulong dummy)
 	cm_print_clock_quick_summary();
 
 	firewall_setup();
+
 	ret = uclass_get_device(UCLASS_CACHE, 0, &dev);
 	if (ret) {
 		debug("CCU init failed: %d\n", ret);
arch/arm/mach-socfpga/spl_dm.c renamed from arch/arm/mach-socfpga/spl_agilex.c +14 -24
similarity index 82%
copy from arch/arm/mach-socfpga/spl_agilex.c
copy to arch/arm/mach-socfpga/spl_dm.c
index ee5a9dc1e2..17b3cb28dc 100644
@@ -1,87 +1,77 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
  *
  */
-
-#include <init.h>
-#include <log.h>
-#include <asm/global_data.h>
 #include <asm/io.h>
 #include <asm/u-boot.h>
 #include <asm/utils.h>
 #include <common.h>
 #include <hang.h>
 #include <image.h>
+#include <init.h>
 #include <spl.h>
 #include <asm/arch/clock_manager.h>
 #include <asm/arch/firewall.h>
 #include <asm/arch/mailbox_s10.h>
 #include <asm/arch/misc.h>
 #include <asm/arch/reset_manager.h>
+#include <asm/arch/smmu_s10.h>
 #include <asm/arch/system_manager.h>
 #include <watchdog.h>
 #include <dm/uclass.h>
-
 DECLARE_GLOBAL_DATA_PTR;
-
 void board_init_f(ulong dummy)
 {
 	int ret;
 	struct udevice *dev;
-
 	ret = spl_early_init();
 	if (ret)
 		hang();
-
 	socfpga_get_managers_addr();
-
 	/* Ensure watchdog is paused when debugging is happening */
 	writel(SYSMGR_WDDBG_PAUSE_ALL_CPU,
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_WDDBG);
-
 #ifdef CONFIG_HW_WATCHDOG
 	/* Enable watchdog before initializing the HW */
 	socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
 	socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
 	hw_watchdog_init();
 #endif
-
 	/* ensure all processors are not released prior Linux boot */
 	writeq(0, CPU_RELEASE_ADDR);
-
 	timer_init();
-
 	sysmgr_pinmux_init();
-
+	preloader_console_init();
 	ret = uclass_get_device(UCLASS_CLK, 0, &dev);
 	if (ret) {
-		debug("Clock init failed: %d\n", ret);
+		printf("Clock init failed: %d\n", ret);
+		hang();
+	}
+	ret = uclass_get_device(UCLASS_CLK, 1, &dev);
+	if (ret) {
+		printf("Memory clock init failed: %d\n", ret);
 		hang();
 	}
-
-	preloader_console_init();
 	print_reset_info();
 	cm_print_clock_quick_summary();
 
 	firewall_setup();
+
 	ret = uclass_get_device(UCLASS_CACHE, 0, &dev);
 	if (ret) {
-		debug("CCU init failed: %d\n", ret);
+		printf("CCU init failed: %d\n", ret);
 		hang();
 	}
-
 #if CONFIG_IS_ENABLED(ALTERA_SDRAM)
 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
 	if (ret) {
-		debug("DRAM init failed: %d\n", ret);
+		printf("DRAM init failed: %d\n", ret);
 		hang();
 	}
 #endif
-
 	mbox_init();
-
 #ifdef CONFIG_CADENCE_QSPI
 	mbox_qspi_open();
 #endif
-}
+}
\ No newline at end of file
arch/arm/mach-socfpga/spl_soc64.c +3 -0
index 2204703853..2f0ad65c18 100644
@@ -27,5 +27,8 @@ u32 spl_boot_mode(const u32 boot_device)
 /* board specific function prior loading SSBL / U-Boot */
 void spl_perform_fixups(struct spl_image_info *spl_image)
 {
+	/* Setup and Initialize SMMU */
+	socfpga_init_smmu();
+
 	mbox_hps_stage_notify(HPS_EXECUTION_STATE_SSBL);
 }
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/5 arm: socfpga: soc64: Change to use spl_perform_fixups()

In reply to Jit Loon Lim

From: Ley Foon Tan <[email protected]>

spl_board_prepare_for_boot() function is only called in U-boot flow, not for ATF flow.

Change to use spl_perform_fixups() to support U-boot and ATF flow.

---
 arch/arm/mach-socfpga/spl_soc64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-socfpga/spl_soc64.c +1 -1
index f3fa1ae361..2204703853 100644
@@ -25,7 +25,7 @@ u32 spl_boot_mode(const u32 boot_device)
 #endif
 
 /* board specific function prior loading SSBL / U-Boot */
-void spl_board_prepare_for_boot(void)
+void spl_perform_fixups(struct spl_image_info *spl_image)
 {
 	mbox_hps_stage_notify(HPS_EXECUTION_STATE_SSBL);
 }
Signature · 1 line
2.26.2
#4 lore raw

PATCH 5/5 doc: socfpga: Add secure region change

In reply to Jit Loon Lim

From: Ley Foon Tan <[email protected]>

Add section 3.2 for SDRAM secure region update.

---
 doc/README.socfpga | 327 ++++++++++++++++++++++++---------------------
 1 file changed, 174 insertions(+), 153 deletions(-)
doc/README.socfpga +174 -153
index 4d73398eb9..0518974c1d 100644
@@ -1,178 +1,199 @@
-----------------------------------------
-SOCFPGA Documentation for U-Boot and SPL
-----------------------------------------
-
-This README is about U-Boot and SPL support for Altera's ARM Cortex-A9MPCore
-based SOCFPGA. To know more about the hardware itself, please refer to
-www.altera.com.
-
-
-socfpga_dw_mmc
---------------
-
-Here are macro and detailed configuration required to enable DesignWare SDMMC
-controller support within SOCFPGA
-
-#define CONFIG_SYS_MMC_MAX_BLK_COUNT	256
--> Using smaller max blk cnt to avoid flooding the limited stack in OCRAM
-
 ---------------------------------------------------------------------
-Cyclone 5 / Arria 5 generating the handoff header files for U-Boot SPL
+SOCFPGA Documentation for U-Boot and SPL
 ---------------------------------------------------------------------
 
-This text is assuming quartus 16.1, but newer versions will probably work just fine too;
-verified with DE1_SOC_Linux_FB demo project (https://github.com/VCTLabs/DE1_SOC_Linux_FB).
-Updated/working projects should build using either process below.
-
-Note: it *should* work from Quartus 14.0.200 onwards, however, the current vendor demo
-projects must have the IP cores updated as shown below.
-
-Rebuilding your Quartus project
--------------------------------
-
-Choose one of the follwing methods, either command line or GUI.
-
-Using the command line
-~~~~~~~~~~~~~~~~~~~~~~
-
-First run the embedded command shell, using your path to the Quartus install:
-
-  $ /path/to/intelFPGA/16.1/embedded/embedded_command_shell.sh
-
-Then (if necessary) update the IP cores in the project, generate HDL code, and
-build the project:
-
-  $ cd path/to/project/dir
-  $ qsys-generate soc_system.qsys --upgrade-ip-cores
-  $ qsys-generate soc_system.qsys --synthesis=[VERILOG|VHDL]
-  $ quartus_sh --flow compile <project name>
-
-Convert the resulting .sof file (SRAM object file) to .rbf file (Raw bit file):
+This README is about U-Boot and SPL support for Intel SOCFPGA.
+To know more about the hardware itself, please refer to
+https://www.intel.com/content/www/us/en/products/programmable/soc.html
 
-  $ quartus_cpf -c <project_name>.sof soc_system.rbf
 
-
-Generate BSP handoff files
-~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-You can run the bsp editor GUI below, or run the following command from the
-project directory:
-
-  $ /path/to/bsb/tools/bsp-create-settings --type spl --bsp-dir build \
-      --preloader-settings-dir hps_isw_handoff/soc_system_hps_0/ \
-      --settings build/settings.bsp
-
-You should use the bsp "build" directory above (ie, where the settings.bsp file is)
-in the following u-boot command to update the board headers.  Once these headers
-are updated for a given project build, u-boot should be configured for the
-project board (eg, de0-nano-sockit) and then build the normal spl build.
-
-Now you can skip the GUI section.
-
-
-Using the Qsys GUI
-~~~~~~~~~~~~~~~~~~
-
-1. Navigate to your project directory
-2. Run Quartus II
-3. Open Project (Ctrl+J), select <project_name>.qpf
-4. Run QSys [Tools->QSys]
-  4.1 In the Open dialog, select '<project_name>.qsys'
-  4.2 In the Open System dialog, wait until completion and press 'Close'
-  4.3 In the Qsys window, click on 'Generate HDL...' in bottom right corner
-     4.3.1 In the 'Generation' window, click 'Generate'
-     4.3.2 In the 'Generate' dialog, wait until completion and click 'Close'
-  4.4 In the QSys window, click 'Finish'
-     4.4.1 In the 'Quartus II' pop up window, click 'OK'
-5. Back in Quartus II main window, do the following
-  5.1 Use Processing -> Start -> Start Analysis & Synthesis (Ctrl+K)
-  5.2 Use Processing -> Start Compilation (Ctrl+L)
-
-    ... this may take some time, have patience ...
-
-6. Start the embedded command shell as shown in the previous section
-  6.1 Change directory to 'software/spl_bsp'
-  6.2 Prepare BSP by launching the BSP editor from ECS
-       => bsp-editor
-  6.3 In BSP editor
-      6.3.1 Use File -> Open
-      6.3.2 Select 'settings.bsp' file
-      6.3.3 Click Generate
-      6.3.4 Click Exit
+Table of Contents
+---------------------------------------------------------------------
+	1. Device Family Support vs Tested Intel Quartus
+	2. Feature Support
+	3. Major Changes and Known Issues
+	4. Cyclone V / Arria V generating the handoff header files for U-Boot SPL
+	5. Arria10 generating the handoff header files for U-Boot SPL
 
 
-Post handoff generation
-~~~~~~~~~~~~~~~~~~~~~~~
+1. Device Family Support vs Tested Intel Quartus
+---------------------------------------------------------------------
 
-Now that the handoff files are generated, U-Boot can be used to process
-the handoff files generated by the bsp-editor. For this, please use the
-following script from the u-boot source tree:
+	Processor			SOCFPGA Device Family		Intel Quartus Prime Pro Edition		Intel Quartus Prime Standard Edition
+	--------------------------------------------------------------------------------------------------------------------------------------------
+	Dual-core ARM Cortex-A9		Cyclone V			N/A					20.1
+					Arria V			N/A					20.1
+					Arria 10			20.1, 20.3					20.1
 
-  $ ./arch/arm/mach-socfpga/qts-filter.sh \
-        <soc_type> \
-        <input_qts_dir> \
-        <input_bsp_dir> \
-        <output_dir>
+	Quad-core ARM Cortex-A53	Stratix 10			20.1, 20.2, 20.3					N/A
+					Agilex				20.1, 20.2, 20.3					N/A
+					Diamond Mesa			Early access					N/A
 
-Process QTS-generated files into U-Boot compatible ones.
 
-    soc_type      - Type of SoC, either 'cyclone5' or 'arria5'.
-    input_qts_dir - Directory with compiled Quartus project
-                    and containing the Quartus project file (QPF).
-    input_bsp_dir - Directory with generated bsp containing
-                    the settings.bsp file.
-    output_dir    - Directory to store the U-Boot compatible
-                    headers.
+2. Feature Support
+---------------------------------------------------------------------
 
-This will generate (or update) the following 4 files:
+	Hardware Feature			Cyclone V	Arria 10	Stratix 10	Agilex		Diamond Mesa
+						Arria V
+	--------------------------------------------------------------------------------------------------------------------
+	SDRAM					Yes		Yes		Yes		Yes		Yes
+	HPS bridge (LWH2F, H2F, F2S)		Yes		Yes		Yes		Yes		Yes
+	HPS cold/warm reset			Yes		Yes		Yes		Yes		Yes
+	FPGA configuration			Yes		Yes		Yes		Yes		No
+	Partial reconfiguration			No		No		Yes		No		No
+	Ethernet (Synopsys EMAC controller)	Yes		Yes		Yes		Yes		Yes
+	Synopsys GPIO controller		Yes		Yes		Yes		Yes		Yes
+	Synopsys UART controller		Yes		Yes		Yes		Yes		Yes
+	Synopsys USB controller			Yes		Yes		Yes		Yes		Yes
+	Synopsys Watchdog timer			Yes		Yes		Yes		Yes		Yes
+	Synopsys I2C master controller		Yes		No		Yes		Yes		Yes
+	Synopsys SDMMC controller		Yes		Yes		Yes		Yes		Yes
+	Cadence QSPI controller			Yes		Yes		Yes		Yes		Yes
+	Denali NAND controller			No		Yes		Yes		Yes		Yes
+	---------------------------------------------------------------------------------------------------------------------
+
+	Software Feature			Cyclone V	Arria 10	Stratix 10	Agilex		Diamond Mesa
+						Arria V
+	---------------------------------------------------------------------------------------------------------------------
+	Remote System Update (RSU) [1]		No		No		Yes		Yes		No
+	ARM Trusted Firmware (ATF) [2]		No		No		Yes		Yes		Yes
+	Vendor Authorized Boot (VAB)		No		No		No		No		Yes
+	---------------------------------------------------------------------------------------------------------------------
+
+3. Major Changes and Known Issues
+---------------------------------------------------------------------
 
-  iocsr_config.h
-  pinmux_config.h
-  pll_config.h
-  sdram_config.h
+	3.1 Support 'vab' command to perform vendor authentication.
 
-These files should be copied into "qts" directory in the board directory
-(see output argument of qts-filter.sh command above).
+		Command format: vab addr len
+		Authorize 'len' bytes starting at 'addr' via vendor public key
 
-Here is an example for the DE-0 Nano SoC after the above rebuild process:
+	3.2 Support SDRAM secure region in U-boot-ATF flow
 
-  $ ll board/terasic/de0-nano-soc/qts/
-  total 36
-  -rw-r--r-- 1 sarnold sarnold 8826 Mar 21 18:11 iocsr_config.h
-  -rw-r--r-- 1 sarnold sarnold 4398 Mar 21 18:11 pinmux_config.h
-  -rw-r--r-- 1 sarnold sarnold 3190 Mar 21 18:11 pll_config.h
-  -rw-r--r-- 1 sarnold sarnold 9022 Mar 21 18:11 sdram_config.h
+		First 1 MiB of SDRAM is configured as secure region, other
+		address spaces are non-secure regions. Only software executing
+		at secure state EL3 (eg: U-boot SPL) and secure masters are
+		allowed access to secure region.
 
-Note: file sizes will differ slightly depending on the selected board.
 
-Now your board is ready for full mainline support including U-Boot SPL.
-The Preloader will not be needed any more.
+4. Cyclone5 / Arria 5 generating the handoff header files for U-Boot SPL
+---------------------------------------------------------------------
+	Rebuilding your Quartus project
+	-------------------------------
+	Choose one of the follwing methods, either command line or GUI.
+	Using the command line
+	~~~~~~~~~~~~~~~~~~~~~~
+	First run the embedded command shell, using your path to the Quartus install:
+	  $ /path/to/intelFPGA/16.1/embedded/embedded_command_shell.sh
+	Then (if necessary) update the IP cores in the project, generate HDL code, and
+	build the project:
+	  $ cd path/to/project/dir
+	  $ qsys-generate soc_system.qsys --upgrade-ip-cores
+	  $ qsys-generate soc_system.qsys --synthesis=[VERILOG|VHDL]
+	  $ quartus_sh --flow compile <project name>
+	Convert the resulting .sof file (SRAM object file) to .rbf file (Raw bit file):
+	  $ quartus_cpf -c <project_name>.sof soc_system.rbf
+	Generate BSP handoff files
+	~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	You can run the bsp editor GUI below, or run the following command from the
+	project directory:
+
+	  $ /path/to/bsb/tools/bsp-create-settings --type spl --bsp-dir build \
+	      --preloader-settings-dir hps_isw_handoff/soc_system_hps_0/ \
+	      --settings build/settings.bsp
+
+	You should use the bsp "build" directory above (ie, where the settings.bsp file is)
+	in the following u-boot command to update the board headers.  Once these headers
+	are updated for a given project build, u-boot should be configured for the
+	project board (eg, de0-nano-sockit) and then build the normal spl build.
+
+	Now you can skip the GUI section.
+
+	Using the Qsys GUI
+	~~~~~~~~~~~~~~~~~~
+	1. Navigate to your project directory
+	2. Run Quartus II
+	3. Open Project (Ctrl+J), select <project_name>.qpf
+	4. Run QSys [Tools->QSys]
+	  4.1 In the Open dialog, select '<project_name>.qsys'
+	  4.2 In the Open System dialog, wait until completion and press 'Close'
+	  4.3 In the Qsys window, click on 'Generate HDL...' in bottom right corner
+	     4.3.1 In the 'Generation' window, click 'Generate'
+	     4.3.2 In the 'Generate' dialog, wait until completion and click 'Close'
+	  4.4 In the QSys window, click 'Finish'
+	     4.4.1 In the 'Quartus II' pop up window, click 'OK'
+	5. Back in Quartus II main window, do the following
+	  5.1 Use Processing -> Start -> Start Analysis & Synthesis (Ctrl+K)
+	  5.2 Use Processing -> Start Compilation (Ctrl+L)
+	    ... this may take some time, have patience ...
+
+	6. Start the embedded command shell as shown in the previous section
+	  $ /path/to/bsb/tools/bsp-create-settings --type spl --bsp-dir build \
+	      --preloader-settings-dir hps_isw_handoff/soc_system_hps_0/ \
+	      --settings build/settings.bsp
+
+	Post handoff generation
+	~~~~~~~~~~~~~~~~~~~~~~~
+	Now that the handoff files are generated, U-Boot can be used to process
+	the handoff files generated by the bsp-editor. For this, please use the
+	following script from the u-boot source tree:
+	  $ ./arch/arm/mach-socfpga/qts-filter.sh \
+		<soc_type> \
+		<input_qts_dir> \
+		<input_bsp_dir> \
+		<output_dir>
+	Process QTS-generated files into U-Boot compatible ones.
+	    soc_type      - Type of SoC, either 'cyclone5' or 'arria5'.
+	    input_qts_dir - Directory with compiled Quartus project
+			    and containing the Quartus project file (QPF).
+	    input_bsp_dir - Directory with generated bsp containing
+			    the settings.bsp file.
+	    output_dir    - Directory to store the U-Boot compatible
+			    headers.
+	This will generate (or update) the following 4 files:
+	  iocsr_config.h
+	  pinmux_config.h
+	  pll_config.h
+	  sdram_config.h
+	These files should be copied into "qts" directory in the board directory
+	(see output argument of qts-filter.sh command above).
+	Here is an example for the DE-0 Nano SoC after the above rebuild process:
+	  $ ll board/terasic/de0-nano-soc/qts/
+	  total 36
+	  -rw-r--r-- 1 sarnold sarnold 8826 Mar 21 18:11 iocsr_config.h
+	  -rw-r--r-- 1 sarnold sarnold 4398 Mar 21 18:11 pinmux_config.h
+	  -rw-r--r-- 1 sarnold sarnold 3190 Mar 21 18:11 pll_config.h
+	  -rw-r--r-- 1 sarnold sarnold 9022 Mar 21 18:11 sdram_config.h
+	Note: file sizes will differ slightly depending on the selected board.
+	      For SoC devkit please refer to https://rocketboards.org/foswiki/Documentation/BuildingBootloader#Cyclone_V_SoC_45_Boot_from_SD_Card
+	Now your board is ready for full mainline support including U-Boot SPL.
+	The Preloader will not be needed any more.
+
+
+5. Arria10 generating the handoff header files for U-Boot SPL
+---------------------------------------------------------------------
 
-----------------------------------------------------------
-Arria 10 generating the handoff header files for U-Boot SPL
-----------------------------------------------------------
+	A header file for inclusion in a devicetree for Arria10 can be generated
+	by the qts-filter-a10.sh script directly from the hps_isw_handoff/hps.xml
+	file generated during the FPGA project compilation.  The header contains
+	all PLL, clock, pinmux, and bridge configurations required.
 
-A header file for inclusion in a devicetree for Arria10 can be generated
-by the qts-filter-a10.sh script directly from the hps_isw_handoff/hps.xml
-file generated during the FPGA project compilation.  The header contains
-all PLL, clock, pinmux, and bridge configurations required.
+	Please look at the socfpga_arria10_socdk_sdmmc-u-boot.dtsi for an example
+	that includes use of the generated handoff header.
 
-Please look at the socfpga_arria10_socdk_sdmmc-u-boot.dtsi for an example
-that includes use of the generated handoff header.
+	Devicetree header generation
+	~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Devicetree header generation
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+	The qts-filter-a10.sh script can process the compile time genetated hps.xml
+	to create the appropriate devicetree header.
 
-The qts-filter-a10.sh script can process the compile time genetated hps.xml
-to create the appropriate devicetree header.
+	  $ ./arch/arm/mach-socfpga/qts-filter-a10.sh \
+		<hps_xml> \
+		<output_file>
 
+	    hps_xml      - hps_isw_handoff/hps.xml from Quartus project
+	    output_file  - Output filename and location for header file
 
-  $ ./arch/arm/mach-socfpga/qts-filter-a10.sh \
-        <hps_xml> \
-        <output_file>
-
-    hps_xml      - hps_isw_handoff/hps.xml from Quartus project
-    output_file  - Output filename and location for header file
-
-The script generates a single header file names <output_file> that should
-be placed in arch/arm/dts.
+	The script generates a single header file names <output_file> that should
+	be placed in arch/arm/dts.
Signature · 1 line
2.26.2
#3 lore raw

PATCH 4/5 ddr: altera: soc64: Add secure region support for ATF flow

In reply to Jit Loon Lim

From: Ley Foon Tan <[email protected]>

Setting up firewall regions based on SDRAM memory banks configuration (up to CONFIG_NR_DRAM_BANKS banks) instead of using whole address space.

First 1 MiB (0 to 0xfffff) of SDRAM is configured as secure region, other address spaces are non-secure regions. The ARM Trusted Firmware (ATF) image is located in this first 1 MiB memory region. So, this can prevent software executing at non-secure state EL0-EL2 and non-secure masters access to secure region.

Add common function for firewall setup and reuse for all SoC64 devices.

---
 drivers/ddr/altera/sdram_agilex.c |  16 +-
 drivers/ddr/altera/sdram_dm.c     | 998 ++++++++++++++++++++++++++++++
 drivers/ddr/altera/sdram_s10.c    |  16 +-
 3 files changed, 1002 insertions(+), 28 deletions(-)
 create mode 100644 drivers/ddr/altera/sdram_dm.c
drivers/ddr/altera/sdram_agilex.c +2 -14
index 65ecdd022c..9f96b4619a 100644
@@ -115,20 +115,6 @@ int sdram_mmr_init_full(struct udevice *dev)
 
 	printf("DDR: %lld MiB\n", gd->ram_size >> 20);
 
-	/* This enables nonsecure access to DDR */
-	/* mpuregion0addr_limit */
-	FW_MPU_DDR_SCR_WRITEL(gd->ram_size - 1,
-			      FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMIT);
-	FW_MPU_DDR_SCR_WRITEL(0x1F, FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMITEXT);
-
-	/* nonmpuregion0addr_limit */
-	FW_MPU_DDR_SCR_WRITEL(gd->ram_size - 1,
-			      FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMIT);
-
-	/* Enable mpuregion0enable and nonmpuregion0enable */
-	FW_MPU_DDR_SCR_WRITEL(MPUREGION0_ENABLE | NONMPUREGION0_ENABLE,
-			      FW_MPU_DDR_SCR_EN_SET);
-
 	u32 ctrlcfg1 = hmc_readl(plat, CTRLCFG1);
 
 	/* Enable or disable the DDR ECC */
@@ -163,6 +149,8 @@ int sdram_mmr_init_full(struct udevice *dev)
 
 	sdram_size_check(&bd);
 
+	sdram_set_firewall(&bd);
+
 	priv->info.base = bd.bi_dram[0].start;
 	priv->info.size = gd->ram_size;
 
drivers/ddr/altera/sdram_dm.c new file +998 -0

999 lines not on this page · raw message

drivers/ddr/altera/sdram_s10.c +2 -14
index 4d36fb4533..6b663bbbb8 100644
@@ -123,20 +123,6 @@ int sdram_mmr_init_full(struct udevice *dev)
 	clrbits_le32(CCU_REG_ADDR(CCU_TCU_MPRT_ADBASE_MEMSPACE1E),
 		     CCU_ADBASE_DI_MASK);
 
-	/* this enables nonsecure access to DDR */
-	/* mpuregion0addr_limit */
-	FW_MPU_DDR_SCR_WRITEL(0xFFFF0000, FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMIT);
-	FW_MPU_DDR_SCR_WRITEL(0x1F, FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMITEXT);
-
-	/* nonmpuregion0addr_limit */
-	FW_MPU_DDR_SCR_WRITEL(0xFFFF0000,
-			      FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMIT);
-	FW_MPU_DDR_SCR_WRITEL(0x1F, FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT);
-
-	/* Enable mpuregion0enable and nonmpuregion0enable */
-	FW_MPU_DDR_SCR_WRITEL(MPUREGION0_ENABLE | NONMPUREGION0_ENABLE,
-			      FW_MPU_DDR_SCR_EN_SET);
-
 	/* Ensure HMC clock is running */
 	if (poll_hmc_clock_status()) {
 		puts("DDR: Error as HMC clock not running\n");
@@ -329,6 +315,8 @@ int sdram_mmr_init_full(struct udevice *dev)
 
 	sdram_size_check(&bd);
 
+	sdram_set_firewall(&bd);
+
 	priv->info.base = bd.bi_dram[0].start;
 	priv->info.size = gd->ram_size;
 
Signature · 1 line
2.26.2