arm: mvebu: Add gdsys ControlCenter-Compact board
Subsystems (10)
v2 cover arm: mvebu: Add gdsys ControlCenter-Compact board
This patch series adds support for the Guntermann & Drunck ControlCenter-Compact board.
To this extent, some bugs in the mvebu PCI driver are fixed, a GPIO driver is added, support for the Marvell 88E1680 is added, the TPM library is extended, the kwbimage generation is streamlined, a board function for manipulating the device tree is added, and secure boot for the mvebu architecture is implemented.
Dirk Eibach (3):
pci: mvebu: Fix Armada 38x support
net: phy: Support Marvell 88E1680
arm: mvebu: Add gdsys ControlCenter-Compact board
Mario Six (14):
mvebu: Add board_pex_config()
dm: Add callback to modify the device tree
lib: tpm: Add command to flush resources
core: device: Add dev_get_by_ofname function
gpio: Add gpio_request_simple function
tools: kwbimage: Fix dest addr
tools: kwbimage: Fix style violations
tools: kwbimage: Fix arithmetic with void pointers
tools: kwbimage: Reduce scope of variables
tools: kwbimage: Remove unused parameter
tools: kwbimage: Factor out add_binary_header_v1
tools: kwbimage: Refactor line parsing and fix error
arm: mvebu: Implement secure boot
controlcenterdc: Make secure boot available
Reinhard Pfau (1):
arm: mvebu: spl.c: Remove useless gd declaration
Makefile | 3 +- arch/arm/Kconfig | 1 + arch/arm/dts/Makefile | 3 +- arch/arm/dts/armada-38x-controlcenterdc.dts | 643 ++++++++++++++++ arch/arm/mach-mvebu/Kconfig | 39 + arch/arm/mach-mvebu/Makefile | 1 + arch/arm/mach-mvebu/efuse.c | 264 +++++++ arch/arm/mach-mvebu/include/mach/cpu.h | 2 + arch/arm/mach-mvebu/include/mach/efuse.h | 69 ++ arch/arm/mach-mvebu/include/mach/soc.h | 1 + arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.c | 8 + arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.h | 2 + arch/arm/mach-mvebu/spl.c | 2 - board/gdsys/a38x/.gitignore | 1 + board/gdsys/a38x/Kconfig | 36 + board/gdsys/a38x/MAINTAINERS | 7 + board/gdsys/a38x/Makefile | 44 ++ board/gdsys/a38x/controlcenterdc.c | 273 +++++++ board/gdsys/a38x/dt_helpers.c | 25 + board/gdsys/a38x/dt_helpers.h | 14 + board/gdsys/a38x/hre.c | 516 +++++++++++++ board/gdsys/a38x/hre.h | 38 + board/gdsys/a38x/hydra.c | 138 ++++ board/gdsys/a38x/hydra.h | 14 + board/gdsys/a38x/ihs_phys.c | 349 +++++++++ board/gdsys/a38x/ihs_phys.h | 2 + board/gdsys/a38x/keyprogram.c | 158 ++++ board/gdsys/a38x/keyprogram.h | 14 + board/gdsys/a38x/kwbimage.cfg.in | 40 + board/gdsys/a38x/spl.c | 21 + board/gdsys/p1022/controlcenterd-id.c | 9 - cmd/tpm.c | 70 ++ common/board_f.c | 10 + configs/controlcenterdc_defconfig | 57 ++ doc/README.armada-secureboot | 373 +++++++++ doc/driver-model/fdt-fixup.txt | 132 ++++ drivers/core/device.c | 7 + drivers/gpio/gpio-uclass.c | 17 + drivers/net/phy/marvell.c | 54 ++ drivers/pci/pci_mvebu.c | 25 +- drivers/tpm/Kconfig | 6 + dts/Kconfig | 10 + include/asm-generic/gpio.h | 22 + include/common.h | 1 + include/configs/controlcenterdc.h | 235 ++++++ include/dm/device.h | 8 + include/tpm.h | 45 ++ lib/tpm.c | 29 + tools/Makefile | 6 +- tools/kwbimage.c | 1111 +++++++++++++++++++++++---- tools/kwbimage.h | 37 + 51 files changed, 4806 insertions(+), 186 deletions(-) create mode 100644 arch/arm/dts/armada-38x-controlcenterdc.dts create mode 100644 arch/arm/mach-mvebu/efuse.c create mode 100644 arch/arm/mach-mvebu/include/mach/efuse.h create mode 100644 board/gdsys/a38x/.gitignore create mode 100644 board/gdsys/a38x/Kconfig create mode 100644 board/gdsys/a38x/MAINTAINERS create mode 100644 board/gdsys/a38x/Makefile create mode 100644 board/gdsys/a38x/controlcenterdc.c create mode 100644 board/gdsys/a38x/dt_helpers.c create mode 100644 board/gdsys/a38x/dt_helpers.h create mode 100644 board/gdsys/a38x/hre.c create mode 100644 board/gdsys/a38x/hre.h create mode 100644 board/gdsys/a38x/hydra.c create mode 100644 board/gdsys/a38x/hydra.h create mode 100644 board/gdsys/a38x/ihs_phys.c create mode 100644 board/gdsys/a38x/ihs_phys.h create mode 100644 board/gdsys/a38x/keyprogram.c create mode 100644 board/gdsys/a38x/keyprogram.h create mode 100644 board/gdsys/a38x/kwbimage.cfg.in create mode 100644 board/gdsys/a38x/spl.c create mode 100644 configs/controlcenterdc_defconfig create mode 100644 doc/README.armada-secureboot create mode 100644 doc/driver-model/fdt-fixup.txt create mode 100644 include/configs/controlcenterdc.h
--
2.9.0
PATCH v2 1/18 pci: mvebu: Fix Armada 38x support
From: Dirk Eibach <[email protected]>
Armada 38x has four PCI ports, not three.
The optimization in pci_init_board() seems to assume that every port has three lanes. This is obviously wrong, and breaks support for Armada 38x.
---
Changes in v2:
None
--- arch/arm/mach-mvebu/include/mach/soc.h | 1 + drivers/pci/pci_mvebu.c | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-)
arch/arm/mach-mvebu/include/mach/soc.h +1 -0
@@ -67,6 +67,7 @@#define MVEBU_REG_PCIE_BASE (MVEBU_REGISTER(0x40000))#define MVEBU_AXP_USB_BASE (MVEBU_REGISTER(0x50000))#define MVEBU_USB20_BASE (MVEBU_REGISTER(0x58000)) +#define MVEBU_REG_PCIE0_BASE (MVEBU_REGISTER(0x80000))#define MVEBU_AXP_SATA_BASE (MVEBU_REGISTER(0xa0000))#define MVEBU_SATA0_BASE (MVEBU_REGISTER(0xa8000))#define MVEBU_NAND_BASE (MVEBU_REGISTER(0xd0000))
drivers/pci/pci_mvebu.c +13 -12
@@ -91,25 +91,26 @@ static void __iomem *mvebu_pcie_membase = (void __iomem *)MBUS_PCI_MEM_BASE;#if defined(CONFIG_ARMADA_38X )#define PCIE_BASE (if) \ ((if) == 0 ? \ - MVEBU_REG_PCIE_BASE + 0x40000 : \ - MVEBU_REG_PCIE_BASE + 0x4000 * (if)) + MVEBU_REG_PCIE0_BASE : \ + (MVEBU_REG_PCIE_BASE + 0x4000 * (if - 1)))/* * On A38x MV6820 these PEX ports are supported: * 0 - Port 0.0 -* 1 - Port 0.1 -* 2 - Port 0.2 +* 1 - Port 1.0 +* 2 - Port 2.0 +* 3 - Port 3.0 */ -#define MAX_PEX 3 +#define MAX_PEX 4static struct mvebu_pcie pcie_bus[MAX_PEX ];static void mvebu_get_port_lane (struct mvebu_pcie *pcie,int pex_idx,int *mem_target,int *mem_attr) { -u8 port[] = {0 ,1 ,2 }; -u8 lane[] = {0 ,0 ,0 }; -u8 target[] = {8 ,4 ,4 }; -u8 attr[] = {0xe8 ,0xe8 ,0xd8 }; +u8 port[] = {0 ,1 ,2 ,3 }; +u8 lane[] = {0 ,0 ,0 ,0 }; +u8 target[] = {8 ,4 ,4 ,4 }; +u8 attr[] = {0xe8 ,0xe8 ,0xd8 ,0xb8 }; pcie->port = port[pex_idx]; pcie->lane = lane[pex_idx];
@@ -351,9 +352,9 @@ void pci_init_board(void)mvebu_get_port_lane (pcie, i, &mem_target, &mem_attr);/* Don't read at all from pci registers if port power is down */ -if (pcie->lane ==0 &&SELECT (soc_ctrl, pcie->port) ==0 ) { - i +=3 ; -debug ("%s: skipping port %d\n" , __func__, pcie->port); +if (SELECT (soc_ctrl, pcie->port) ==0 ) { +if (pcie->lane ==0 ) +debug ("%s: skipping port %d\n" , __func__, pcie->port);continue ; }
--
2.9.0
PATCH v2 1/18 pci: mvebu: Fix Armada 38x support
Quoted 9 lines · Mario Six
From: Dirk Eibach <[email protected]>
Armada 38x has four PCI ports, not three.
The optimization in
pci_init_board()seems to assume that every port has three lanes. This is obviously wrong, and breaks support for Armada 38x.Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>
Thanks,
Stefan
PATCH v2 1/18 pci: mvebu: Fix Armada 38x support
In reply to Mario SixQuoted 9 lines · Mario Six
From: Dirk Eibach <[email protected]>
Armada 38x has four PCI ports, not three.
The optimization in
pci_init_board()seems to assume that every port has three lanes. This is obviously wrong, and breaks support for Armada 38x.Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 2/18 net: phy: Support Marvell 88E1680
In reply to Mario SixFrom: Dirk Eibach <[email protected]>
Add support for Marvell 88E1680 Integrated Octal 10/100/1000 Mbps Energy Efficient Ethernet Transceiver.
---
Changes in v2:
* Switched to usage of pre-defined constant names where possible
* Added error handling for genphy_config_aneg call
--- drivers/net/phy/marvell.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/net/phy/marvell.c +54 -0
@@ -480,6 +480,49 @@ static int m88e1310_config(struct phy_device *phydev)return genphy_config_aneg (phydev); } +static int m88e1680_config (struct phy_device *phydev) +{ +/* +* As per Marvell Release Notes - Alaska V 88E1680 Rev A2 +* Errata Section 4.1 +*/ +u16 reg; +int res; + +/* Matrix LED mode (not neede if single LED mode is used */ +phy_write (phydev,MDIO_DEVAD_NONE ,MIIM_88E1118_PHY_PAGE ,0x0004 ); + reg =phy_read (phydev,MDIO_DEVAD_NONE ,27 ); + reg |= (1 <<5 ); +phy_write (phydev,MDIO_DEVAD_NONE ,27 , reg); + +/* QSGMII TX amplitude change */ +phy_write (phydev,MDIO_DEVAD_NONE ,MIIM_88E1118_PHY_PAGE ,0x00fd ); +phy_write (phydev,MDIO_DEVAD_NONE ,8 ,0x0b53 ); +phy_write (phydev,MDIO_DEVAD_NONE ,7 ,0x200d ); +phy_write (phydev,MDIO_DEVAD_NONE ,MIIM_88E1118_PHY_PAGE ,0x0000 ); + +/* EEE initialization */ +phy_write (phydev,MDIO_DEVAD_NONE ,MIIM_88E1118_PHY_PAGE ,0x00ff ); +phy_write (phydev,MDIO_DEVAD_NONE ,17 ,0xb030 ); +phy_write (phydev,MDIO_DEVAD_NONE ,16 ,0x215c ); +phy_write (phydev,MDIO_DEVAD_NONE ,22 ,0x00fc ); +phy_write (phydev,MDIO_DEVAD_NONE ,24 ,0x888c ); +phy_write (phydev,MDIO_DEVAD_NONE ,25 ,0x888c ); +phy_write (phydev,MDIO_DEVAD_NONE ,MIIM_88E1118_PHY_PAGE ,0x0000 ); +phy_write (phydev,MDIO_DEVAD_NONE ,0 ,0x9140 ); + + res =genphy_config_aneg (phydev); +if (res <0 ) +return res; + +/* soft reset */ + reg =phy_read (phydev,MDIO_DEVAD_NONE ,MII_BMCR ); + reg |=BMCR_RESET ; +phy_write (phydev,MDIO_DEVAD_NONE ,MII_BMCR , reg); + +return 0 ; +} +static struct phy_driver M88E1011S_driver = { .name ="Marvell 88E1011S" , .uid =0x1410c60 ,
@@ -580,6 +623,16 @@ static struct phy_driver M88E1310_driver = { .shutdown = &genphy_shutdown, }; +static struct phy_driver M88E1680_driver = { + .name ="Marvell 88E1680" , + .uid =0x1410ed0 , + .mask =0xffffff0 , + .features =PHY_GBIT_FEATURES , + .config = &m88e1680_config, + .startup = &genphy_startup, + .shutdown = &genphy_shutdown, +}; +int phy_marvell_init (void ) {phy_register (&M88E1310_driver);
@@ -592,6 +645,7 @@ int phy_marvell_init(void)phy_register (&M88E1011S_driver);phy_register (&M88E1510_driver);phy_register (&M88E1518_driver); +phy_register (&M88E1680_driver);return 0 ; }
--
2.9.0
PATCH v2 2/18 net: phy: Support Marvell 88E1680
Quoted 5 lines · Mario Six
From: Dirk Eibach <[email protected]>
Add support for Marvell 88E1680 Integrated Octal 10/100/1000 Mbps Energy Efficient Ethernet Transceiver.
Quoted 7 lines
Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Switched to usage of pre-defined constant names where possible
* Added error handling forgenphy_config_anegcall
Joe, I would like to include this patch with the patch series once all is fine. Do you see any issues with it? Could I have your Acked-by and push it via the Marvell git repository?
Thanks,
Stefan
PATCH v2 2/18 net: phy: Support Marvell 88E1680
Quoted 16 lines · Stefan Roese
Quoted 6 lines · Mario Six
From: Dirk Eibach <[email protected]>
Add support for Marvell 88E1680 Integrated Octal 10/100/1000 Mbps Energy Efficient Ethernet Transceiver.
Quoted 7 lines
Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Switched to usage of pre-defined constant names where possible
* Added error handling forgenphy_config_anegcall
Quoted 5 lines
Reviewed-by Stefan Roese <[email protected]>Joe, I would like to include this patch with the patch series once all is fine. Do you see any issues with it? Could I have your Acked-by and push it via the Marvell git repository?
Sounds good.
Cheers,
-Joe
PATCH v2 2/18 net: phy: Support Marvell 88E1680
In reply to Mario SixQuoted 7 lines · Mario Six
From: Dirk Eibach <[email protected]>
Add support for Marvell 88E1680 Integrated Octal 10/100/1000 Mbps Energy Efficient Ethernet Transceiver.
Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>
PATCH v2 2/18 net: phy: Support Marvell 88E1680
In reply to Mario SixQuoted 5 lines · Mario Six
From: Dirk Eibach <[email protected]>
Add support for Marvell 88E1680 Integrated Octal 10/100/1000 Mbps Energy Efficient Ethernet Transceiver.
Quoted 7 lines
Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Switched to usage of pre-defined constant names where possible
* Added error handling forgenphy_config_anegcall
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 3/18 mvebu: Add board_pex_config()
In reply to Mario SixAllow boards to do some initialization when PCIe comes up.
---
Changes in v2:
* Switched usage of __attribute(...) to __weak to simplify weak function declaration
--- arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.c | 8 ++++++++ arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.h | 2 ++ 2 files changed, 10 insertions(+)
arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.c +8 -0
@@ -13,6 +13,11 @@#include "ctrl_pex.h" #include "sys_env_lib.h" +__weak void board_pex_config (void ) +{ +/* nothing in this weak default implementation */ +} +int hws_pex_config (const struct serdes_map *serdes_map,u8 count) { u32 pex_idx, tmp, next_busno, first_busno, temp_pex_reg,
@@ -77,6 +82,9 @@ int hws_pex_config(const struct serdes_map *serdes_map, u8 count)/* Support gen1/gen2 */ DEBUG_INIT_FULL_S ("Support gen1/gen2\n" ); + +board_pex_config (); + next_busno =0 ;mdelay (150 );
arch/arm/mach-mvebu/serdes/a38x/ctrl_pex.h +2 -0
@@ -83,4 +83,6 @@ int pex_local_bus_num_set(u32 pex_if, u32 bus_num);int pex_local_dev_num_set (u32 pex_if,u32 dev_num);u32 pex_config_read (u32 pex_if,u32 bus,u32 dev,u32 func,u32 reg_off); +void board_pex_config (void ); +#endif
--
2.9.0
PATCH v2 3/18 mvebu: Add board_pex_config()
Quoted 9 lines · Mario Six
Allow boards to do some initialization when PCIe comes up.
Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Switched usage of
__attribute(...)to__weakto simplify weak function declaration
Thanks,
Stefan
PATCH v2 3/18 mvebu: Add board_pex_config()
In reply to Mario SixQuoted 9 lines · Mario Six
Allow boards to do some initialization when PCIe comes up.
Signed-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Switched usage of
__attribute(...)to__weakto simplify weak function declaration
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 4/18 arm: mvebu: spl.c: Remove useless gd declaration
In reply to Mario SixFrom: Reinhard Pfau <[email protected]>
ddaa905 ("arm: mvebu: Add DM (driver model) support") removed the assignment of the gd pointer, but kept the (now superfluous) declaration of the gd pointer.
Remove this declaration.
---
Changes in v2:
None
--- arch/arm/mach-mvebu/spl.c | 2 -- 1 file changed, 2 deletions(-)
arch/arm/mach-mvebu/spl.c +0 -2
@@ -13,8 +13,6 @@#include <asm/arch/cpu.h> #include <asm/arch/soc.h> -DECLARE_GLOBAL_DATA_PTR ; -static u32 get_boot_device (void ) {u32 val;
--
2.9.0
PATCH v2 4/18 arm: mvebu: spl.c: Remove useless gd declaration
Quoted 6 lines · Mario Six
From: Reinhard Pfau <[email protected]>
ddaa905 ("arm: mvebu: Add DM (driver model) support") removed the assignment of the gd pointer, but kept the (now superfluous) declaration of the gd pointer.
Quoted 7 lines
Remove this declaration.
Signed-off-by Reinhard Pfau <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 4/18 arm: mvebu: spl.c: Remove useless gd declaration
In reply to Mario SixQuoted 6 lines · Mario Six
From: Reinhard Pfau <[email protected]>
ddaa905 ("arm: mvebu: Add DM (driver model) support") removed the assignment of the gd pointer, but kept the (now superfluous) declaration of the gd pointer.
Quoted 7 lines
Remove this declaration.
Signed-off-by Reinhard Pfau <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 5/18 dm: Add callback to modify the device tree
In reply to Mario SixCertain boards come in different variations by way of utilizing daughter boards, for example. These boards might contain additional chips, which are added to the main board's busses, e.g. I2C.
The device tree support for such boards would either, quite naturally, employ the overlay mechanism to add such chips to the tree, or would use one large default device tree, and delete the devices that are actually not present.
Regardless of approach, even on the U-Boot level, a modification of the device tree is a prerequisite to have such modular families of boards supported properly.
Therefore, we add an option to make the U-Boot device tree (the actual copy later used by the driver model) writeable, and add a callback method that allows boards to modify the device tree at an early stage, at which, hopefully, also the application of device tree overlays will be possible.
---
Changes in v2:
* Switched from usage of globally writeable global data pointer to a locally writeable pointer passed to board_fix_fdt
* Added comments for board_fix_fdt in include/common.h
* Added documentation for pre-relocation device tree manipulation
--- common/board_f.c | 10 ++++ doc/driver-model/fdt-fixup.txt | 132 +++++++++++++++++++++++++++++++++++++++++ dts/Kconfig | 10 ++++ include/common.h | 1 + 4 files changed, 153 insertions(+) create mode 100644 doc/driver-model/fdt-fixup.txt
common/board_f.c +10 -0
@@ -767,6 +767,13 @@ static int setup_reloc(void)return 0 ; } +#ifdef CONFIG_OF_BOARD_FIXUP +static int fix_fdt (void ) +{ +return board_fix_fdt ((void *)gd->fdt_blob); +} +#endif +/* ARM calls relocate_code from its crt0.S */ #if !defined(CONFIG_ARM ) && !defined(CONFIG_SANDBOX )
@@ -1037,6 +1044,9 @@ static init_fnc_t init_sequence_f[] = {#ifdef CONFIG_SYS_EXTBDINFO setup_board_extra,#endif +#ifdef CONFIG_OF_BOARD_FIXUP + fix_fdt, +#endif INIT_FUNC_WATCHDOG_RESET reloc_fdt, setup_reloc,
doc/driver-model/fdt-fixup.txt new file +132 -0
132 lines not on this page · raw message
dts/Kconfig +10 -0
@@ -14,6 +14,16 @@ config OF_CONTROL This feature provides for run-time configuration of U-Boot via a flattened device tree. +config OF_BOARD_FIXUP + bool "Board-specific manipulation of Device Tree" + help + In certain circumstances it is necessary to be able to modify + U-Boot's device tree (e.g. to delete device from it). This option + make the Device Tree writeable and provides a board-specific + "board_fix_fdt" callback (called during pre-relocation time), which + enables the board initialization to modifiy the Device Tree. The + modified copy is subsequently used by U-Boot after relocation. + config SPL_OF_CONTROL bool "Enable run-time configuration via Device Tree in SPL" depends on SPL && OF_CONTROL
include/common.h +1 -0
@@ -502,6 +502,7 @@ extern ssize_t spi_write (uchar *, int, uchar *, int);/* $(BOARD)/$(BOARD).c */ int board_early_init_f (void ); +int board_fix_fdt (void *rw_fdt_blob);/* manipulate the U-Boot fdt before its relocation */ int board_late_init (void );int board_postclk_init (void );/* after clocks/timebase, before env/serial */ int board_early_init_r (void );
--
2.9.0
PATCH v2 5/18 dm: Add callback to modify the device tree
Quoted 19 lines · Mario Six
Certain boards come in different variations by way of utilizing daughter boards, for example. These boards might contain additional chips, which are added to the main board's busses, e.g. I2C.
The device tree support for such boards would either, quite naturally, employ the overlay mechanism to add such chips to the tree, or would use one large default device tree, and delete the devices that are actually not present.
Regardless of approach, even on the U-Boot level, a modification of the device tree is a prerequisite to have such modular families of boards supported properly.
Therefore, we add an option to make the U-Boot device tree (the actual copy later used by the driver model) writeable, and add a callback method that allows boards to modify the device tree at an early stage, at which, hopefully, also the application of device tree overlays will be possible.
Quoted 8 lines
Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Switched from usage of globally writeable global data pointer to a locally writeable pointer passed to
board_fix_fdt
* Added comments forboard_fix_fdtininclude/common.h
* Added documentation for pre-relocation device tree manipulation
Mario, thanks for the extensive documentation in this new version. I would like to see some review comments from Simon (who is working on a live DT as I've noticed just today) and perhaps others on this patch.
Simon, could you please take a look at this?
Thanks,
Stefan
Quoted 208 lines
--- common/board_f.c | 10 ++++ doc/driver-model/fdt-fixup.txt | 132 +++++++++++++++++++++++++++++++++++++++++ dts/Kconfig | 10 ++++ include/common.h | 1 + 4 files changed, 153 insertions(+) create mode 100644 doc/driver-model/fdt-fixup.txtcommon/board_f.c +10
-0@@ -767,6 +767,13 @@ static int setup_reloc(void)return 0 ; } +#ifdef CONFIG_OF_BOARD_FIXUP +static int fix_fdt (void ) +{ +return board_fix_fdt ((void *)gd->fdt_blob); +} +#endif +/* ARM calls relocate_code from its crt0.S */ #if !defined(CONFIG_ARM ) && !defined(CONFIG_SANDBOX )@@ -1037,6 +1044,9 @@ static init_fnc_t init_sequence_f[] = {#ifdef CONFIG_SYS_EXTBDINFO setup_board_extra,#endif +#ifdef CONFIG_OF_BOARD_FIXUP + fix_fdt, +#endif INIT_FUNC_WATCHDOG_RESET reloc_fdt, setup_reloc,doc/driver-model/fdt-fixup.txt new file +132
-0@@ -0,0 +1,132 @@ +Pre-relocation device tree manipulation +======================================= + +Contents: + +1. Purpose +2. Implementation +3. Example +4. Work to be done + +1. Purpose +---------- + +In certain markets, it is beneficial for manufacturers of embedded devices to +offer certain ranges of products, where the functionality of the devices within +one series either don't differ greatly from another, or can be thought of as +"extensions" of each other, where one device only differs from another in the +addition of a small number of features (e.g. an additional output connector). + +To realize this in hardware, one method is to have a motherboard, and several +possible daughter boards that can be attached to this mother board. Different +daughter boards then either offer the slightly different functionality, or the +addition of the daughter board to the device realizes the "extension" of +functionality to the device described previously. + +For the software, we obviously want to reuse components for all these +variations of the device. This means that the software somehow needs to cope +with the situation that certain ICs may or may not be present on any given +system, depending on which daughter boards are connected to the motherboard. + +In the Linux kernel, one possible solution to this problem is to employ the +device tree overlay mechanism: There exists one "base" device tree, which +features only the components guaranteed to exist in all varieties of the +device. At the start of the kernel, the presence and type of the daughter +boards is then detected, and the corresponding device tree overlays are applied +to support the components on the daughter boards. + +Note that the components present on every variety of the board must, of course, +provide a way to find out if and which daughter boards are installed for this +mechanism to work. + +In the U-Boot boot loader, support for device tree overlays has recently been +integrated, and is used on some boards to alter the device tree that is later +passed to Linux. But since U-Boot's driver model, which is device tree-based as +well, is being used in more and more drivers, the same problem of altering the +device tree starts cropping up in U-Boot itself as well. + +An additional problem with the device tree in U-Boot is that it is read-only, +and the current mechanisms don't allow easy manipulation of the device tree +after the driver model has been initialized. While migrating to a live device +tree (at least after the relocation) would greatly simplify the solution of +this problem, it is a non-negligible task to implement it, an a interim +solution is needed to address the problem at least in the medium-term. + +Hence, we propose a solution to this problem by offering a board-specific +call-back function, which is passed a writeable pointer to the device tree. +This function is called before the device tree is relocated, and specifically +before the main U-Boot's driver model is instantiated, hence the main U-Boot +"sees" all modifications to the device tree made in this function. Furthermore, +we have the pre-relocation driver model at our disposal at this stage, which +means that we can query the hardware for the existence and variety of the +components easily. + +2. Implementation +----------------- + +To take advantage of the pre-relocation device tree manipulation mechanism, +boards have to implement the function board_fix_fdt, which has the following +signature: + +int board_fix_fdt (void *rw_fdt_blob) + +The passed-in void pointer is a writeable pointer to the device tree, which can +be used to manipulate the device tree using e.g. functions from +include/fdt_support.h. The return value should either be 0 in case of +successful execution of the device tree manipulation or something else for a +failure. Note that returning a non-null value from the function will +unrecoverably halt the boot process, as with any function from init_sequence_f +(in common/board_f.c). + +Furthermore, the Kconfig option OF_BOARD_FIXUP has to be set for the function +to be called: + +Device Tree Control +-> [*] Board-specific manipulation of Device Tree + ++----------------------------------------------------------+ +| WARNING: The actual manipulation of the device tree has | +| to be the _last_ set of operations in board_fix_fdt! | +| Since the pre-relocation driver model does not adapt to | +| changes made to the device tree either, its references | +| into the device tree will be invalid after manipulating | +| it, and unpredictable behavior might occur when | +| functions that rely on them are executed! | ++----------------------------------------------------------+ + +Hence, the recommended layout of the board_fixup_fdt call-back function is the +following: + +int board_fix_fdt(void *rw_fdt_blob) +{ + /* Collect information about device's hardware and store them in e.g. + local variables */ + + /* Do device tree manipulation using the values previously collected */ + + /* Return 0 on successful manipulation and non-zero otherwise */ +} + +If this convention is kept, both an "additive" approach, meaning that nodes for +detected components are added to the device tree, as well as a "subtractive" +approach, meaning that nodes for absent components are removed from the tree, +as well as a combination of both approaches should work. + +3. Example +---------- + +The controlcenterdc board (board/gdsys/a38x/controlcenterdc.c) features a +board_fix_fdt function, in which six GPIO expanders (which might be present or +not, since they are on daughter boards) on a I2C bus are queried for, and +subsequently deactivated in the device tree if they are not present. + +Note that the dm_i2c_simple_probe function does not use the device tree, hence +it is safe to call it after the tree has already been manipulated. + +4. Work to be done +------------------ + +* The application of device tree overlay should be possible in board_fixup_fdt, + but has not been tested at this stage. + +2017-01-06, Mario Six <[email protected]>dts/Kconfig +10
-0@@ -14,6 +14,16 @@ config OF_CONTROL This feature provides for run-time configuration of U-Boot via a flattened device tree. +config OF_BOARD_FIXUP + bool "Board-specific manipulation of Device Tree" + help + In certain circumstances it is necessary to be able to modify + U-Boot's device tree (e.g. to delete device from it). This option + make the Device Tree writeable and provides a board-specific + "board_fix_fdt" callback (called during pre-relocation time), which + enables the board initialization to modifiy the Device Tree. The + modified copy is subsequently used by U-Boot after relocation. + config SPL_OF_CONTROL bool "Enable run-time configuration via Device Tree in SPL" depends on SPL && OF_CONTROLinclude/common.h +1
-1@@ -502,6 +502,7 @@ extern ssize_t spi_write (uchar *, int, uchar *, int);/* $(BOARD)/$(BOARD).c */ int board_early_init_f (void ); +int board_fix_fdt (void *rw_fdt_blob);/* manipulate the U-Boot fdt before its relocation */ int board_late_init (void );int board_postclk_init (void );/* after clocks/timebase, before env/serial */ int board_early_init_r (void ); --
Quoted 2 lines
2.9.0
Viele Gr??e,
Stefan
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
PATCH v2 6/18 lib: tpm: Add command to flush resources
In reply to Mario SixThis patch adds a function to the TPM library, which allows U-Boot to flush resources, e.g. keys, from the TPM.
---
Changes in v2:
* Added U-Boot command for resource flushing ("tpm flush"), and made the command and the library function deactivate-able via config
--- board/gdsys/p1022/controlcenterd-id.c | 9 ----- cmd/tpm.c | 70 +++++++++++++++++++++++++++++++++++ drivers/tpm/Kconfig | 6 +++ include/tpm.h | 45 ++++++++++++++++++++++ lib/tpm.c | 29 +++++++++++++++ 5 files changed, 150 insertions(+), 9 deletions(-)
board/gdsys/p1022/controlcenterd-id.c +0 -9
@@ -43,15 +43,6 @@#define CCDM_AUTO_FIRST_STAGE #endif -/* enums from TCG specs */ -enum { -/* capability areas */ -TPM_CAP_NV_INDEX =0x00000011 , -TPM_CAP_HANDLE =0x00000014 , -/* resource types */ -TPM_RT_KEY =0x00000001 , -}; -/* CCDM specific contants */ enum {/* NV indices */
cmd/tpm.c +70 -0
88 lines not on this page · raw message
drivers/tpm/Kconfig +6 -0
@@ -82,4 +82,10 @@ config TPM_ST33ZP24_SPI to the device using the standard TPM Interface Specification (TIS) protocol +config TPM_FLUSH_RESOURCES + bool "Enable TPM resource flushing support" + depends on TPM + help + Enable support to flush specific resources (e.g. keys) from the TPM. + The functionality is available via the 'tpm' command as well. endmenu
include/tpm.h +45 -0
55 lines not on this page · raw message
lib/tpm.c +29 -0
@@ -645,6 +645,35 @@ uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm)return 0 ; } +#ifdef CONFIG_TPM_FLUSH_RESOURCES +uint32_t tpm_flush_specific (uint32_t key_handle,uint32_t resource_type) +{ +const uint8_t command[18 ] = { +0x00 ,0xc1 ,/* TPM_TAG */ +0x00 ,0x00 ,0x00 ,0x12 ,/* parameter size */ +0x00 ,0x00 ,0x00 ,0xba ,/* TPM_COMMAND_CODE */ +0x00 ,0x00 ,0x00 ,0x00 ,/* key handle */ +0x00 ,0x00 ,0x00 ,0x00 ,/* resource type */ + }; +const size_t key_handle_offset =10 ; +const size_t resource_type_offset =14 ; +uint8_t buf[COMMAND_BUFFER_SIZE ], response[COMMAND_BUFFER_SIZE ]; +size_t response_length =sizeof (response); +uint32_t err; + +if (pack_byte_string (buf,sizeof (buf),"sdd" , +0 , command,sizeof (command), + key_handle_offset, key_handle, + resource_type_offset, resource_type)) +return TPM_LIB_ERROR ; + + err =tpm_sendrecv_command (buf, response, &response_length); +if (err) +return err; +return 0 ; +} +#endif /* CONFIG_TPM_FLUSH_RESOURCES */ +#ifdef CONFIG_TPM_AUTH_SESSIONS /**
--
2.9.0
PATCH v2 6/18 lib: tpm: Add command to flush resources
Quoted 233 lines · Mario Six
This patch adds a function to the TPM library, which allows U-Boot to flush resources, e.g. keys, from the TPM.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Added U-Boot command for resource flushing ("tpm flush"), and made the command and the library function deactivate-able via config
--- board/gdsys/p1022/controlcenterd-id.c | 9 ----- cmd/tpm.c | 70 +++++++++++++++++++++++++++++++++++ drivers/tpm/Kconfig | 6 +++ include/tpm.h | 45 ++++++++++++++++++++++ lib/tpm.c | 29 +++++++++++++++ 5 files changed, 150 insertions(+), 9 deletions(-)board/gdsys/p1022/controlcenterd-id.c +0
-9@@ -43,15 +43,6 @@#define CCDM_AUTO_FIRST_STAGE #endif -/* enums from TCG specs */ -enum { -/* capability areas */ -TPM_CAP_NV_INDEX =0x00000011 , -TPM_CAP_HANDLE =0x00000014 , -/* resource types */ -TPM_RT_KEY =0x00000001 , -}; -/* CCDM specific contants */ enum {/* NV indices */ cmd/tpm.c +70
-0@@ -646,6 +646,64 @@ TPM_COMMAND_NO_ARG(tpm_end_oiap)#endif /* CONFIG_TPM_AUTH_SESSIONS */ +#ifdef CONFIG_TPM_FLUSH_RESOURCES +static int do_tpm_flush (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +int type =0 ; + +if (argc !=2 ) +return CMD_RET_USAGE ; + +if (strcasecmp (argv[1 ],"key" )) + type =TPM_RT_KEY ; +else if (strcasecmp (argv[1 ],"auth" )) + type =TPM_RT_AUTH ; +else if (strcasecmp (argv[1 ],"hash" )) + type =TPM_RT_HASH ; +else if (strcasecmp (argv[1 ],"trans" )) + type =TPM_RT_TRANS ; +else if (strcasecmp (argv[1 ],"context" )) + type =TPM_RT_CONTEXT ; +else if (strcasecmp (argv[1 ],"counter" )) + type =TPM_RT_COUNTER ; +else if (strcasecmp (argv[1 ],"delegate" )) + type =TPM_RT_DELEGATE ; +else if (strcasecmp (argv[1 ],"daa_tpm" )) + type =TPM_RT_DAA_TPM ; +else if (strcasecmp (argv[1 ],"daa_v0" )) + type =TPM_RT_DAA_V0 ; +else if (strcasecmp (argv[1 ],"daa_v1" )) + type =TPM_RT_DAA_V1 ; + +if (strcasecmp (argv[2 ],"all" )) { +uint16_t res_count; +uint8_t buf[288 ]; +uint8_t *ptr; +int err; +uint i; + +/* fetch list of already loaded resources in the TPM */ + err =tpm_get_capability (TPM_CAP_HANDLE , type, buf, +sizeof (buf)); +if (err) +return -1 ; + res_count =get_unaligned_be16 (buf); + ptr = buf +2 ; +for (i =0 ; i < res_count; ++i, ptr +=4 ) +tpm_flush_specific (get_unaligned_be32 (ptr), type); + }else { +uint32_t handle =simple_strtoul (argv[2 ],NULL ,0 ); + +if (!handle) +return -1 ; +tpm_flush_specific (cpu_to_be32 (handle), type); + } + +return 0 ; +} +#endif /* CONFIG_TPM_FLUSH_RESOURCES */ +#define MAKE_TPM_CMD_ENTRY (cmd) \ U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")@@ -701,6 +759,10 @@ static cmd_tbl_t tpm_commands[] = { U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1, do_tpm_get_pub_key_oiap, "", ""),#endif /* CONFIG_TPM_AUTH_SESSIONS */ +#ifdef CONFIG_TPM_FLUSH_RESOURCES + U_BOOT_CMD_MKENT(flush, 0, 1, + do_tpm_flush, "", ""), +#endif /* CONFIG_TPM_FLUSH_RESOURCES */ };static int do_tpm (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[])@@ -750,6 +812,14 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, " get_capability cap_area sub_cap addr count\n" " - Read <count> bytes of TPM capability indexed by <cap_area> and\n" " <sub_cap> to memory address <addr>.\n" +#ifdef CONFIG_TPM_FLUSH_RESOURCES +"Resource management functions\n" +" flush resource_type id\n" +" - flushes a resource of type <resource_type> (may be one of key, auth,\n" +" hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n" +" and id <id> from the TPM. Use an <id> of \"all\" to flush all\n" +" resources of that type.\n" +#endif /* CONFIG_TPM_FLUSH_RESOURCES */#ifdef CONFIG_TPM_AUTH_SESSIONS "Storage functions\n" " loadkey2_oiap parent_handle key_addr key_len usage_auth\n" drivers/tpm/Kconfig +6
-0@@ -82,4 +82,10 @@ config TPM_ST33ZP24_SPI to the device using the standard TPM Interface Specification (TIS) protocol +config TPM_FLUSH_RESOURCES + bool "Enable TPM resource flushing support" + depends on TPM + help + Enable support to flush specific resources (e.g. keys) from the TPM. + The functionality is available via the 'tpm' command as well. endmenuinclude/tpm.h +45
-0@@ -47,6 +47,42 @@ enum tpm_nv_index { TPM_NV_INDEX_DIR = 0x10000001, }; +enum tpm_resource_type { +TPM_RT_KEY =0x00000001 , +TPM_RT_AUTH =0x00000002 , +TPM_RT_HASH =0x00000003 , +TPM_RT_TRANS =0x00000004 , +TPM_RT_CONTEXT =0x00000005 , +TPM_RT_COUNTER =0x00000006 , +TPM_RT_DELEGATE =0x00000007 , +TPM_RT_DAA_TPM =0x00000008 , +TPM_RT_DAA_V0 =0x00000009 , +TPM_RT_DAA_V1 =0x0000000A , +}; + +enum tpm_capability_areas { +TPM_CAP_ORD =0x00000001 , +TPM_CAP_ALG =0x00000002 , +TPM_CAP_PID =0x00000003 , +TPM_CAP_FLAG =0x00000004 , +TPM_CAP_PROPERTY =0x00000005 , +TPM_CAP_VERSION =0x00000006 , +TPM_CAP_KEY_HANDLE =0x00000007 , +TPM_CAP_CHECK_LOADED =0x00000008 , +TPM_CAP_SYM_MODE =0x00000009 , +TPM_CAP_KEY_STATUS =0x0000000C , +TPM_CAP_NV_LIST =0x0000000D , +TPM_CAP_MFR =0x00000010 , +TPM_CAP_NV_INDEX =0x00000011 , +TPM_CAP_TRANS_ALG =0x00000012 , +TPM_CAP_HANDLE =0x00000014 , +TPM_CAP_TRANS_ES =0x00000015 , +TPM_CAP_AUTH_ENCRYPT =0x00000017 , +TPM_CAP_SELECT_SIZE =0x00000018 , +TPM_CAP_DA_LOGIC =0x00000019 , +TPM_CAP_VERSION_VAL =0x0000001A , +}; +#define TPM_NV_PER_GLOBALLOCK (1U << 15)#define TPM_NV_PER_PPWRITE (1U << 0)#define TPM_NV_PER_READ_STCLEAR (1U << 31)@@ -594,4 +630,13 @@ uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags);*/ uint32_t tpm_get_permissions (uint32_t index,uint32_t *perm); +/** +* Flush a resource with a given handle and type from the TPM +* +* @param key_handle handle of the resource +* @param resource_type type of the resource +* @return return code of the operation +*/ +uint32_t tpm_flush_specific (uint32_t key_handle,uint32_t resource_type); +#endif /* __TPM_H */ lib/tpm.c +17
-0@@ -645,6 +645,35 @@ uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm)return 0 ; } +#ifdef CONFIG_TPM_FLUSH_RESOURCES +uint32_t tpm_flush_specific (uint32_t key_handle,uint32_t resource_type) +{ +const uint8_t command[18 ] = { +0x00 ,0xc1 ,/* TPM_TAG */ +0x00 ,0x00 ,0x00 ,0x12 ,/* parameter size */ +0x00 ,0x00 ,0x00 ,0xba ,/* TPM_COMMAND_CODE */ +0x00 ,0x00 ,0x00 ,0x00 ,/* key handle */ +0x00 ,0x00 ,0x00 ,0x00 ,/* resource type */ + }; +const size_t key_handle_offset =10 ; +const size_t resource_type_offset =14 ; +uint8_t buf[COMMAND_BUFFER_SIZE ], response[COMMAND_BUFFER_SIZE ]; +size_t response_length =sizeof (response); +uint32_t err; + + if (pack_byte_string(buf, sizeof(buf), "sdd",
lib/tpm.c uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm) · line 674
Quoted 10 lines
lib/tpm.c +10
-0+0 , command,sizeof (command), + key_handle_offset, key_handle, + resource_type_offset, resource_type)) + return TPM_LIB_ERROR; + + err =tpm_sendrecv_command (buf, response, &response_length); +if (err) +return err; +return 0 ; +}
You don't need "err" here. Simpler is this version:
return tpm_sendrecv_command(buf, response, &response_length);
Other than this:
Thanks,
Stefan
PATCH v2 6/18 lib: tpm: Add command to flush resources
In reply to Mario SixQuoted 10 lines · Mario Six
This patch adds a function to the TPM library, which allows U-Boot to flush resources, e.g. keys, from the TPM.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Added U-Boot command for resource flushing ("tpm flush"), and made the command and the library function deactivate-able via config
Quoted 7 lines
--- board/gdsys/p1022/controlcenterd-id.c | 9 ----- cmd/tpm.c | 70 +++++++++++++++++++++++++++++++++++ drivers/tpm/Kconfig | 6 +++ include/tpm.h | 45 ++++++++++++++++++++++ lib/tpm.c | 29 +++++++++++++++ 5 files changed, 150 insertions(+), 9 deletions(-)
PATCH v2 6/18 lib: tpm: Add command to flush resources
In reply to Mario SixQuoted 9 lines · Mario Six
This patch adds a function to the TPM library, which allows U-Boot to flush resources, e.g. keys, from the TPM.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Added U-Boot command for resource flushing ("tpm flush"), and made the command and the library function deactivate-able via config
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 7/18 core: device: Add dev_get_by_ofname function
In reply to Mario SixOn boards that use DM, it is sometimes convenient and quicker to get a device via its device tree path, since the devices used in the board initialization routines are usually known beforehand.
This patch adds such a convenience function.
---
Changes in v2:
New in v2
--- drivers/core/device.c | 7 +++++++ include/dm/device.h | 8 ++++++++ 2 files changed, 15 insertions(+)
drivers/core/device.c +7 -0
@@ -627,6 +627,13 @@ const char *dev_get_uclass_name(struct udevice *dev)return dev->uclass->uc_drv->name; } +void dev_get_by_ofname (char *ofname,struct udevice *dev) +{ +int offset =fdt_path_offset (gd->fdt_blob, ofname); + +device_get_global_by_of_offset (offset, &dev); +} +fdt_addr_t dev_get_addr_index (struct udevice *dev,int index) {#if CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )
include/dm/device.h +8 -0
@@ -340,6 +340,14 @@ enum uclass_id device_get_uclass_id(struct udevice *dev);const char *dev_get_uclass_name (struct udevice *dev);/** +* dev_get_by_ofname() - find a device via its device tree path +* +* @ofname: Device tree path to use ("/path1/path2/...") +* @dev: The found device or NULL +*/ +void dev_get_by_ofname (char *ofname,struct udevice *dev); + +/** * device_get_child() - Get the child of a device by index * * Returns the numbered child, 0 being the first. This does not use
--
2.9.0
PATCH v2 7/18 core: device: Add dev_get_by_ofname function
Quoted 39 lines · Mario Six
On boards that use DM, it is sometimes convenient and quicker to get a device via its device tree path, since the devices used in the board initialization routines are usually known beforehand.
This patch adds such a convenience function.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:New in v2
--- drivers/core/device.c | 7 +++++++ include/dm/device.h | 8 ++++++++ 2 files changed, 15 insertions(+)drivers/core/device.c +7
-0@@ -627,6 +627,13 @@ const char *dev_get_uclass_name(struct udevice *dev)return dev->uclass->uc_drv->name; } +void dev_get_by_ofname (char *ofname,struct udevice *dev) +{ +int offset =fdt_path_offset (gd->fdt_blob, ofname); + +device_get_global_by_of_offset (offset, &dev); +} +fdt_addr_t dev_get_addr_index (struct udevice *dev,int index) {#if CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )include/dm/device.h +0
-0
include/dm/device.h enum uclass_id device_get_uclass_id(struct udevice *dev); · line 348
Quoted 9 lines
include/dm/device.h +6
-0@@ -340,6 +340,14 @@ enum uclass_id device_get_uclass_id(struct udevice *dev);const char *dev_get_uclass_name (struct udevice *dev);/** +* dev_get_by_ofname() - find a device via its device tree path +* +* @ofname: Device tree path to use ("/path1/path2/...") +* @dev: The found device or NULL +*/ +void dev_get_by_ofname (char *ofname,struct udevice *dev);
I'm not 100% sure if the function naming is perfect here. Usually these dev_get_xxx function work on a "dev" provided by the caller and return something else (addr, size). The functions returning a "device" are called device_get_xxx. And perhaps its also better stick with using "struct udevice **devp" as parameter for consistency as the other device_ functions do.
Simon, what do you think?
Thanks,
Stefan
PATCH v2 7/18 core: device: Add dev_get_by_ofname function
Hi,
Quoted 62 lines · Stefan Roese
Quoted 42 lines · Mario Six
On boards that use DM, it is sometimes convenient and quicker to get a device
via its device tree path, since the devices used in the board initialization
routines are usually known beforehand.This patch adds such a convenience function.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:New in v2
--- drivers/core/device.c | 7 +++++++ include/dm/device.h | 8 ++++++++ 2 files changed, 15 insertions(+)drivers/core/device.c +7
-0@@ -627,6 +627,13 @@ const char *dev_get_uclass_name(struct udevice *dev)return dev->uclass->uc_drv->name; } +void dev_get_by_ofname (char *ofname,struct udevice *dev) +{ +int offset =fdt_path_offset (gd->fdt_blob, ofname); + +device_get_global_by_of_offset (offset, &dev); +} +fdt_addr_t dev_get_addr_index (struct udevice *dev,int index) {#if CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )include/dm/device.h +0
-0include/dm/device.h enum uclass_id device_get_uclass_id(struct udevice · line 349
Quoted 10 lines
include/dm/device.h +6
-0@@ -340,6 +340,14 @@ enum uclass_id device_get_uclass_id(struct udevice *dev);const char *dev_get_uclass_name (struct udevice *dev);/** +* dev_get_by_ofname() - find a device via its device tree path +* +* @ofname: Device tree path to use ("/path1/path2/...") +* @dev: The found device or NULL +*/ +void dev_get_by_ofname (char *ofname,struct udevice *dev);I'm not 100% sure if the function naming is perfect here. Usually these
dev_get_xxxfunction work on a "dev" provided by the caller and return something else (addr, size). The functions returning a "device" are calleddevice_get_xxx. And perhaps its also better stick with using "struct udevice **devp" as parameter for
consistency as the otherdevice_functions do.
Quoted 1 line
Simon, what do you think?
Agreed.
Also I'm not sure we should be hunting around a path in the DT. Shouldn't we use compatible strings?
Regards,
Simon
PATCH v2 8/18 gpio: Add gpio_request_simple function
In reply to Mario SixFor board initialization, usage of GPIOs is sometimes needed, e.g. to initialize certain devices such as FPGAs. But since there currently is no device associated to the board itself, initialization routines have to cumbersomely get GPIOs via gpio_request_by_name_nodev.
This patch adds a convenience function aimed at such scenarios, which wraps the gpio_request_by_name_nodev and some error checking. The GPIO is identified via its compatible string in the device tree.
---
Changes in v2:
New in v2
--- drivers/gpio/gpio-uclass.c | 17 +++++++++++++++++ include/asm-generic/gpio.h | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/gpio/gpio-uclass.c +17 -0
@@ -751,6 +751,23 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name, flags); } +bool gpio_request_simple (char *name,struct gpio_desc *gpio) +{ +int node =fdt_node_offset_by_compatible (gd->fdt_blob,0 , name); +int ret; + +if (node <0 ) +return false; + + ret =gpio_request_by_name_nodev (gd->fdt_blob, node,"gpios" ,0 , gpio, +0 ); + +if (ret <0 ) +return false; + +return dm_gpio_is_valid (gpio); +} +int gpio_get_list_count (struct udevice *dev,const char *list_name) {int ret;
include/asm-generic/gpio.h +22 -0
@@ -457,6 +457,28 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name, int flags);/** +* gpio_request_simple() - Simple wrapper function to request GPIO via +* fdt compatible name +* +* Convenience method to get useable GPIO description information from a device +* tree declaration such as: +* +* fpga_ready_gpio { +* compatible = "generic,fpga-ready-gpio"; +* gpios = <&PCA22 27 0>; +* }; +* +* This is convenient for setting and reading GPIOs from board files (where no +* associated device is in play). +* +* @name: The fdt compatible string of the GPIO in question +* @gpio: Return the GPIO description information of the GPIO in question +* +* @return true if the operation succeeded, false if not +*/ +bool gpio_request_simple (char *name,struct gpio_desc *gpio); + +/** * dm_gpio_request() - manually request a GPIO * * Note: This function should only be used for testing / debugging. Instead.
--
2.9.0
PATCH v2 8/18 gpio: Add gpio_request_simple function
Quoted 65 lines · Mario Six
For board initialization, usage of GPIOs is sometimes needed, e.g. to initialize certain devices such as FPGAs. But since there currently is no device associated to the board itself, initialization routines have to cumbersomely get GPIOs via
gpio_request_by_name_nodev.This patch adds a convenience function aimed at such scenarios, which wraps the
gpio_request_by_name_nodevand some error checking. The GPIO is identified via its compatible string in the device tree.Signed-off-by Mario Six <[email protected]>---
Changes in v2:New in v2
--- drivers/gpio/gpio-uclass.c | 17 +++++++++++++++++ include/asm-generic/gpio.h | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+)drivers/gpio/gpio-uclass.c +17
-0@@ -751,6 +751,23 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name, flags); } +bool gpio_request_simple (char *name,struct gpio_desc *gpio) +{ +int node =fdt_node_offset_by_compatible (gd->fdt_blob,0 , name); +int ret; + +if (node <0 ) +return false; + + ret =gpio_request_by_name_nodev (gd->fdt_blob, node,"gpios" ,0 , gpio, +0 ); + +if (ret <0 ) +return false; + +return dm_gpio_is_valid (gpio); +} +int gpio_get_list_count (struct udevice *dev,const char *list_name) {int ret;include/asm-generic/gpio.h +10
-0@@ -457,6 +457,28 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name, int flags);/** +* gpio_request_simple() - Simple wrapper function to request GPIO via +* fdt compatible name +* +* Convenience method to get useable GPIO description information from a device +* tree declaration such as: +* +* fpga_ready_gpio { +* compatible = "generic,fpga-ready-gpio"; +* gpios = <&PCA22 27 0>; +* };
include/asm-generic/gpio.h int gpio_request_list_by_name(struct udevice *dev, const char *list_name, · line 479
Quoted 10 lines
include/asm-generic/gpio.h +10
-0+* +* This is convenient for setting and reading GPIOs from board files (where no +* associated device is in play). +* +* @name: The fdt compatible string of the GPIO in question +* @gpio: Return the GPIO description information of the GPIO in question +* +* @return true if the operation succeeded, false if not +*/ +bool gpio_request_simple (char *name,struct gpio_desc *gpio);
So you have GPIOs that are not directly integrated in some other device, like its usually the case for some power or reset GPIOs that are e.g. used in USB DT nodes?
I'm not sure if this DT implementation would be accepted in the Linux kernel. How do you handle it in Linux?
Thanks,
Stefan
PATCH v2 9/18 tools: kwbimage: Fix dest addr
In reply to Mario SixTo enable secure boot, we need to jump back into the BootROM to continue the SoC's boot process instead of letting the SPL load and run the main U-Boot image.
But, since the u-boot-spl.img (including the 64 byte header) is loaded by the SoC as the main image, we need to compensate for the header length to get a correct entry point.
Thus, we subtract the header size from the destination address, so that the execution address points at the actual entry point of the image.
The current boards ignore both parameters anyway, so this change shouldn't concern them.
---
Changes in v2:
None
--- tools/kwbimage.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/kwbimage.c +2 -1
@@ -410,7 +410,8 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,cpu_to_le32 (payloadsz - headersz +sizeof (uint32_t )); main_hdr->headersz_lsb =cpu_to_le16 (headersz &0xFFFF ); main_hdr->headersz_msb = (headersz &0xFFFF0000 ) >>16 ; - main_hdr->destaddr =cpu_to_le32 (params->addr); + main_hdr->destaddr =cpu_to_le32 (params->addr) + -sizeof (image_header_t); main_hdr->execaddr =cpu_to_le32 (params->ep); main_hdr->srcaddr =cpu_to_le32 (headersz); main_hdr->ext = hasext;
--
2.9.0
PATCH v2 9/18 tools: kwbimage: Fix dest addr
Quoted 11 lines · Mario Six
To enable secure boot, we need to jump back into the BootROM to continue the SoC's boot process instead of letting the SPL load and run the main U-Boot image.
But, since the u-boot-spl.img (including the 64 byte header) is loaded by the SoC as the main image, we need to compensate for the header length to get a correct entry point.
Thus, we subtract the header size from the destination address, so that the execution address points at the actual entry point of the image.
Quoted 8 lines
The current boards ignore both parameters anyway, so this change shouldn't concern them.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 9/18 tools: kwbimage: Fix dest addr
In reply to Mario SixQuoted 11 lines · Mario Six
To enable secure boot, we need to jump back into the BootROM to continue the SoC's boot process instead of letting the SPL load and run the main U-Boot image.
But, since the u-boot-spl.img (including the 64 byte header) is loaded by the SoC as the main image, we need to compensate for the header length to get a correct entry point.
Thus, we subtract the header size from the destination address, so that the execution address points at the actual entry point of the image.
Quoted 8 lines
The current boards ignore both parameters anyway, so this change shouldn't concern them.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 10/18 tools: kwbimage: Fix style violations
In reply to Mario SixFix some style violations:
- nine instances of missing blank lines after declarations
- one overly long line
- one split string (which also rewords an error message more concisely)
- two superfluous else
---
Changes in v2:
None
--- tools/kwbimage.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
tools/kwbimage.c +17 -8
@@ -103,6 +103,7 @@ struct image_cfg_element {static const char *image_boot_mode_name (unsigned int id) {int i; +for (i =0 ; boot_modes[i].name; i++)if (boot_modes[i].id == id)return boot_modes[i].name;
@@ -112,6 +113,7 @@ static const char *image_boot_mode_name(unsigned int id)int image_boot_mode_id (const char *boot_mode_name) {int i; +for (i =0 ; boot_modes[i].name; i++)if (!strcmp (boot_modes[i].name, boot_mode_name))return boot_modes[i].id;
@@ -122,6 +124,7 @@ int image_boot_mode_id(const char *boot_mode_name)int image_nand_ecc_mode_id (const char *nand_ecc_mode_name) {int i; +for (i =0 ; nand_ecc_modes[i].name; i++)if (!strcmp (nand_ecc_modes[i].name, nand_ecc_mode_name))return nand_ecc_modes[i].id;
@@ -359,14 +362,14 @@ static size_t image_headersz_v1(struct image_tool_params *params,#if defined(CONFIG_SYS_U_BOOT_OFFS )if (headersz >CONFIG_SYS_U_BOOT_OFFS ) { -fprintf (stderr,"Error: Image header (incl. SPL image) too big!\n" ); +fprintf (stderr, +"Error: Image header (incl. SPL image) too big!\n" );fprintf (stderr,"header=0x%x CONFIG_SYS_U_BOOT_OFFS=0x%x!\n" , (int )headersz,CONFIG_SYS_U_BOOT_OFFS );fprintf (stderr,"Increase CONFIG_SYS_U_BOOT_OFFS!\n" );return 0 ; - }else { - headersz =CONFIG_SYS_U_BOOT_OFFS ; } + headersz =CONFIG_SYS_U_BOOT_OFFS ;#endif /*
@@ -514,11 +517,13 @@ static int image_create_config_parse_oneline(char *line, keyword =strtok_r (line, deliminiters, &saveptr);if (!strcmp (keyword,"VERSION" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); + el->type =IMAGE_CFG_VERSION ; el->version =atoi (value); }else if (!strcmp (keyword,"BOOT_FROM" )) {char *value =strtok_r (NULL , deliminiters, &saveptr);int ret =image_boot_mode_id (value); +if (ret <0 ) {fprintf (stderr,"Invalid boot media '%s'\n" , value);
@@ -528,16 +533,19 @@ static int image_create_config_parse_oneline(char *line, el->bootfrom = ret; }else if (!strcmp (keyword,"NAND_BLKSZ" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); + el->type =IMAGE_CFG_NAND_BLKSZ ; el->nandblksz =strtoul (value,NULL ,16 ); }else if (!strcmp (keyword,"NAND_BADBLK_LOCATION" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); + el->type =IMAGE_CFG_NAND_BADBLK_LOCATION ; el->nandbadblklocation =strtoul (value,NULL ,16 ); }else if (!strcmp (keyword,"NAND_ECC_MODE" )) {char *value =strtok_r (NULL , deliminiters, &saveptr);int ret =image_nand_ecc_mode_id (value); +if (ret <0 ) {fprintf (stderr,"Invalid NAND ECC mode '%s'\n" , value);
@@ -547,6 +555,7 @@ static int image_create_config_parse_oneline(char *line, el->nandeccmode = ret; }else if (!strcmp (keyword,"NAND_PAGE_SIZE" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); + el->type =IMAGE_CFG_NAND_PAGESZ ; el->nandpagesz =strtoul (value,NULL ,16 ); }else if (!strcmp (keyword,"BINARY" )) {
@@ -800,8 +809,8 @@ static int kwbimage_check_image_types(uint8_t type) {if (type ==IH_TYPE_KWBIMAGE )return EXIT_SUCCESS ; -else -return EXIT_FAILURE ; + +return EXIT_FAILURE ; } static int kwbimage_verify_header(unsigned char *ptr, int image_size,
@@ -874,9 +883,9 @@ static int kwbimage_generate(struct image_tool_params *params,static int kwbimage_check_params (struct image_tool_params *params) {if (!strlen (params->imagename)) { -fprintf (stderr,"Error:%s - Configuration file not specified, " -"it is needed for kwbimage generation\n" , - params->cmdname); +char *msg ="Configuration file for kwbimage creation omitted" ; + +fprintf (stderr,"Error:%s - %s\n" , params->cmdname, msg);return CFG_INVALID ; }
--
2.9.0
PATCH v2 10/18 tools: kwbimage: Fix style violations
Quoted 7 lines · Mario Six
Fix some style violations:
- nine instances of missing blank lines after declarations
- one overly long line
- one split string (which also rewords an error message more concisely)
- two superfluous else
Quoted 5 lines
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 10/18 tools: kwbimage: Fix style violations
In reply to Mario SixQuoted 7 lines · Mario Six
Fix some style violations:
- nine instances of missing blank lines after declarations
- one overly long line
- one split string (which also rewords an error message more concisely)
- two superfluous else
Quoted 5 lines
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 11/18 tools: kwbimage: Fix arithmetic with void pointers
In reply to Mario SixArithmetic with void pointers, e.g. a - b where both a and b are void pointers, is undefined in the C standard. Since we are operating with byte data here, we switch the void pointers to uint8_t pointers, and add the necessary casts.
---
Changes in v2:
None
--- tools/kwbimage.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
tools/kwbimage.c +12 -10
@@ -231,7 +231,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,size_t headersz;struct main_hdr_v0 *main_hdr;struct ext_hdr_v0 *ext_hdr; -void *image; +uint8_t *image;int has_ext =0 ;/*
@@ -258,7 +258,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,memset (image,0 , headersz); - main_hdr = image; + main_hdr = (struct main_hdr_v0 *)image;/* Fill in the main header */ main_hdr->blocksize =
@@ -284,7 +284,8 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,if (has_ext) {int cfgi, datai; - ext_hdr = image +sizeof (struct main_hdr_v0 ); + ext_hdr = (struct ext_hdr_v0 *) + (image +sizeof (struct main_hdr_v0 )); ext_hdr->offset =cpu_to_le32 (0x40 );for (cfgi =0 , datai =0 ; cfgi < cfgn; cfgi++) {
@@ -385,7 +386,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,struct image_cfg_element *e, *binarye;struct main_hdr_v1 *main_hdr;size_t headersz; -void *image, *cur; +uint8_t *image, *cur;int hasext =0 ;int ret;
@@ -405,8 +406,8 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,memset (image,0 , headersz); - cur = main_hdr = image; - cur +=sizeof (struct main_hdr_v1 ); + main_hdr = (struct main_hdr_v1 *)image; + cur = image +sizeof (struct main_hdr_v1 );/* Fill the main header */ main_hdr->blocksize =
@@ -437,7 +438,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, binarye =image_find_option (IMAGE_CFG_BINARY );if (binarye) { -struct opt_hdr_v1 *hdr = cur; +struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)cur;uint32_t *args;size_t binhdrsz;struct stat s;
@@ -470,7 +471,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, cur +=sizeof (struct opt_hdr_v1 ); - args = cur; + args = (uint32_t *)cur; *args =cpu_to_le32 (binarye->binary.nargs); args++;for (argi =0 ; argi < binarye->binary.nargs; argi++)
@@ -820,7 +821,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,struct ext_hdr_v0 *ext_hdr;uint8_t checksum; - main_hdr = (void *)ptr; + main_hdr = (struct main_hdr_v0 *)ptr; checksum =image_checksum8 (ptr,sizeof (struct main_hdr_v0 ) -sizeof (uint8_t ));
@@ -829,7 +830,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,/* Only version 0 extended header has checksum */ if (image_version ((void *)ptr) ==0 ) { - ext_hdr = (void *)ptr +sizeof (struct main_hdr_v0 ); + ext_hdr = (struct ext_hdr_v0 *) + (ptr +sizeof (struct main_hdr_v0 )); checksum =image_checksum8 (ext_hdr,sizeof (struct ext_hdr_v0 ) -sizeof (uint8_t ));
--
2.9.0
PATCH v2 11/18 tools: kwbimage: Fix arithmetic with void pointers
Quoted 10 lines · Mario Six
Arithmetic with void pointers, e.g. a - b where both a and b are void pointers, is undefined in the C standard. Since we are operating with byte data here, we switch the void pointers to
uint8_tpointers, and add the necessary casts.Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 11/18 tools: kwbimage: Fix arithmetic with void pointers
In reply to Mario SixQuoted 10 lines · Mario Six
Arithmetic with void pointers, e.g. a - b where both a and b are void pointers, is undefined in the C standard. Since we are operating with byte data here, we switch the void pointers to
uint8_tpointers, and add the necessary casts.Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 12/18 tools: kwbimage: Reduce scope of variables
In reply to Mario SixThis patch reduces the scope of some variables.
---
Changes in v2:
None
--- tools/kwbimage.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
tools/kwbimage.c +5 -4
@@ -230,7 +230,6 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,struct image_cfg_element *e;size_t headersz;struct main_hdr_v0 *main_hdr; -struct ext_hdr_v0 *ext_hdr;uint8_t *image;int has_ext =0 ;
@@ -282,6 +281,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,/* Generate the ext header */ if (has_ext) { +struct ext_hdr_v0 *ext_hdr;int cfgi, datai; ext_hdr = (struct ext_hdr_v0 *)
@@ -313,7 +313,6 @@ static size_t image_headersz_v1(struct image_tool_params *params, {struct image_cfg_element *binarye;size_t headersz; -int ret;/* * Calculate the size of the header and the size of the
@@ -333,6 +332,7 @@ static size_t image_headersz_v1(struct image_tool_params *params, binarye =image_find_option (IMAGE_CFG_BINARY );if (binarye) { +int ret;struct stat s; ret =stat (binarye->binary.file, &s);
@@ -388,7 +388,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,size_t headersz;uint8_t *image, *cur;int hasext =0 ; -int ret;/* * Calculate the size of the header and the size of the
@@ -444,6 +443,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,struct stat s;int argi;FILE *bin; +int ret; hdr->headertype =OPT_HDR_V1_BINARY_TYPE ;
@@ -818,7 +818,6 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, struct image_tool_params *params) {struct main_hdr_v0 *main_hdr; -struct ext_hdr_v0 *ext_hdr;uint8_t checksum; main_hdr = (struct main_hdr_v0 *)ptr;
@@ -830,6 +829,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,/* Only version 0 extended header has checksum */ if (image_version ((void *)ptr) ==0 ) { +struct ext_hdr_v0 *ext_hdr; + ext_hdr = (struct ext_hdr_v0 *) (ptr +sizeof (struct main_hdr_v0 )); checksum = image_checksum8(ext_hdr,
--
2.9.0
PATCH v2 12/18 tools: kwbimage: Reduce scope of variables
Quoted 7 lines · Mario Six
This patch reduces the scope of some variables.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 12/18 tools: kwbimage: Reduce scope of variables
In reply to Mario SixQuoted 7 lines · Mario Six
This patch reduces the scope of some variables.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 13/18 tools: kwbimage: Remove unused parameter
In reply to Mario SixThe parameter 'params' of the image_headersz_v1 function is never used by the function.
Hence, remove it.
---
Changes in v2:
None
--- tools/kwbimage.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/kwbimage.c +3 -4
@@ -308,8 +308,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,return image; } -static size_t image_headersz_v1 (struct image_tool_params *params, -int *hasext) +static size_t image_headersz_v1 (int *hasext) {struct image_cfg_element *binarye;size_t headersz;
@@ -393,7 +392,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,* Calculate the size of the header and the size of the * payload */ - headersz =image_headersz_v1 (params, &hasext); + headersz =image_headersz_v1 (&hasext);if (headersz ==0 )return NULL ;
@@ -855,7 +854,7 @@ static int kwbimage_generate(struct image_tool_params *params, alloc_len =sizeof (struct main_hdr_v0 ) +sizeof (struct ext_hdr_v0 ); }else { - alloc_len =image_headersz_v1 (params,NULL ); + alloc_len =image_headersz_v1 (NULL ); } hdr =malloc (alloc_len);
--
2.9.0
PATCH v2 13/18 tools: kwbimage: Remove unused parameter
Quoted 10 lines · Mario Six
The parameter 'params' of the
image_headersz_v1function is never used by the function.Hence, remove it.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 13/18 tools: kwbimage: Remove unused parameter
In reply to Mario SixQuoted 10 lines · Mario Six
The parameter 'params' of the
image_headersz_v1function is never used by the function.Hence, remove it.
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 14/18 tools: kwbimage: Factor out add_binary_header_v1
In reply to Mario SixIn preparation of adding the creation of secure headers, we factor the add_binary_header_v1 function out of the image_create_v1 function.
---
Changes in v2:
None
--- tools/kwbimage.c | 146 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 67 deletions(-)
tools/kwbimage.c +79 -67
@@ -369,6 +369,7 @@ static size_t image_headersz_v1(int *hasext)fprintf (stderr,"Increase CONFIG_SYS_U_BOOT_OFFS!\n" ); return 0; } + headersz =CONFIG_SYS_U_BOOT_OFFS ;#endif
@@ -379,10 +380,85 @@ static size_t image_headersz_v1(int *hasext)return ALIGN_SUP (headersz,4096 ); } +int add_binary_header_v1 (uint8_t *cur) +{ +struct image_cfg_element *binarye; +struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)cur; +uint32_t *args; +size_t binhdrsz; +struct stat s; +int argi; +FILE *bin; +int ret; + + binarye =image_find_option (IMAGE_CFG_BINARY ); + +if (!binarye) +return 0 ; + + hdr->headertype =OPT_HDR_V1_BINARY_TYPE ; + + bin =fopen (binarye->binary.file,"r" ); +if (!bin) { +fprintf (stderr,"Cannot open binary file %s\n" , + binarye->binary.file); +return -1 ; + } + +fstat (fileno (bin), &s); + + binhdrsz =sizeof (struct opt_hdr_v1 ) + + (binarye->binary.nargs +2 ) *sizeof (uint32_t ) + + s.st_size; + +/* +* The size includes the binary image size, rounded +* up to a 4-byte boundary. Plus 4 bytes for the +* next-header byte and 3-byte alignment at the end. +*/ + binhdrsz =ALIGN_SUP (binhdrsz,4 ) +4 ; + hdr->headersz_lsb =cpu_to_le16 (binhdrsz &0xFFFF ); + hdr->headersz_msb = (binhdrsz &0xFFFF0000 ) >>16 ; + + cur +=sizeof (struct opt_hdr_v1 ); + + args = (uint32_t *)cur; + *args =cpu_to_le32 (binarye->binary.nargs); + args++; +for (argi =0 ; argi < binarye->binary.nargs; argi++) + args[argi] =cpu_to_le32 (binarye->binary.args[argi]); + + cur += (binarye->binary.nargs +1 ) *sizeof (uint32_t ); + + ret =fread (cur, s.st_size,1 , bin); +if (ret !=1 ) { +fprintf (stderr, +"Could not read binary image %s\n" , + binarye->binary.file); +return -1 ; + } + +fclose (bin); + + cur +=ALIGN_SUP (s.st_size,4 ); + +/* +* For now, we don't support more than one binary +* header, and no other header types are +* supported. So, the binary header is necessarily the +* last one +*/ + *((uint32_t *)cur) =0x00000000 ; + + cur +=sizeof (uint32_t ); + +return 0 ; +} +static void *image_create_v1 (size_t *imagesz,struct image_tool_params *params,int payloadsz) { -struct image_cfg_element *e, *binarye; +struct image_cfg_element *e;struct main_hdr_v1 *main_hdr;size_t headersz;uint8_t *image, *cur;
@@ -434,72 +510,8 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,if (e) main_hdr->flags = e->debug ?0x1 :0 ; - binarye =image_find_option (IMAGE_CFG_BINARY ); -if (binarye) { -struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)cur; -uint32_t *args; -size_t binhdrsz; -struct stat s; -int argi; -FILE *bin; -int ret; - - hdr->headertype =OPT_HDR_V1_BINARY_TYPE ; - - bin =fopen (binarye->binary.file,"r" ); -if (!bin) { -fprintf (stderr,"Cannot open binary file %s\n" , - binarye->binary.file); -return NULL ; - } - -fstat (fileno (bin), &s); - - binhdrsz =sizeof (struct opt_hdr_v1 ) + - (binarye->binary.nargs +2 ) *sizeof (uint32_t ) + - s.st_size; - -/* -* The size includes the binary image size, rounded -* up to a 4-byte boundary. Plus 4 bytes for the -* next-header byte and 3-byte alignment at the end. -*/ - binhdrsz =ALIGN_SUP (binhdrsz,4 ) +4 ; - hdr->headersz_lsb =cpu_to_le16 (binhdrsz &0xFFFF ); - hdr->headersz_msb = (binhdrsz &0xFFFF0000 ) >>16 ; - - cur +=sizeof (struct opt_hdr_v1 ); - - args = (uint32_t *)cur; - *args =cpu_to_le32 (binarye->binary.nargs); - args++; -for (argi =0 ; argi < binarye->binary.nargs; argi++) - args[argi] =cpu_to_le32 (binarye->binary.args[argi]); - - cur += (binarye->binary.nargs +1 ) *sizeof (uint32_t ); - - ret =fread (cur, s.st_size,1 , bin); -if (ret !=1 ) { -fprintf (stderr, -"Could not read binary image %s\n" , - binarye->binary.file); -return NULL ; - } - -fclose (bin); - - cur +=ALIGN_SUP (s.st_size,4 ); - -/* -* For now, we don't support more than one binary -* header, and no other header types are -* supported. So, the binary header is necessarily the -* last one -*/ - *((uint32_t *)cur) =0x00000000 ; - - cur +=sizeof (uint32_t ); - } +if (add_binary_header_v1 (cur)) +return NULL ;/* Calculate and set the header checksum */ main_hdr->checksum =image_checksum8 (main_hdr, headersz);
--
2.9.0
PATCH v2 14/18 tools: kwbimage: Factor out add_binary_header_v1
Quoted 8 lines · Mario Six
In preparation of adding the creation of secure headers, we factor the
add_binary_header_v1function out of theimage_create_v1function.Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 14/18 tools: kwbimage: Factor out add_binary_header_v1
In reply to Mario SixQuoted 8 lines · Mario Six
In preparation of adding the creation of secure headers, we factor the
add_binary_header_v1function out of theimage_create_v1function.Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 15/18 tools: kwbimage: Refactor line parsing and fix error
In reply to Mario SixThe function image_create_config_parse_oneline is pretty complex, and since more parameters will be added to support secure booting, we refactor the function to make it more readable.
Also, when a line contained just a keyword without any parameters, strtok_r returned NULL, which was then indiscriminately fed into atoi, causing a segfault. To correct this, we add a NULL check before feeding the extracted token to atoi, and print an error message in case the token is NULL.
---
Changes in v2:
None
--- tools/kwbimage.c | 177 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 106 insertions(+), 71 deletions(-)
tools/kwbimage.c +106 -71
@@ -55,22 +55,43 @@ struct nand_ecc_mode nand_ecc_modes[] = {#define BINARY_MAX_ARGS 8/* In-memory representation of a line of the configuration file */ + +enum image_cfg_type { +IMAGE_CFG_VERSION =0x1 , +IMAGE_CFG_BOOT_FROM , +IMAGE_CFG_DEST_ADDR , +IMAGE_CFG_EXEC_ADDR , +IMAGE_CFG_NAND_BLKSZ , +IMAGE_CFG_NAND_BADBLK_LOCATION , +IMAGE_CFG_NAND_ECC_MODE , +IMAGE_CFG_NAND_PAGESZ , +IMAGE_CFG_BINARY , +IMAGE_CFG_PAYLOAD , +IMAGE_CFG_DATA , +IMAGE_CFG_BAUDRATE , +IMAGE_CFG_DEBUG , + +IMAGE_CFG_COUNT +} type; + +static const char *const id_strs[] = { + [IMAGE_CFG_VERSION ] ="VERSION" , + [IMAGE_CFG_BOOT_FROM ] ="BOOT_FROM" , + [IMAGE_CFG_DEST_ADDR ] ="DEST_ADDR" , + [IMAGE_CFG_EXEC_ADDR ] ="EXEC_ADDR" , + [IMAGE_CFG_NAND_BLKSZ ] ="NAND_BLKSZ" , + [IMAGE_CFG_NAND_BADBLK_LOCATION ] ="NAND_BADBLK_LOCATION" , + [IMAGE_CFG_NAND_ECC_MODE ] ="NAND_ECC_MODE" , + [IMAGE_CFG_NAND_PAGESZ ] ="NAND_PAGE_SIZE" , + [IMAGE_CFG_BINARY ] ="BINARY" , + [IMAGE_CFG_PAYLOAD ] ="PAYLOAD" , + [IMAGE_CFG_DATA ] ="DATA" , + [IMAGE_CFG_BAUDRATE ] ="BAUDRATE" , + [IMAGE_CFG_DEBUG ] ="DEBUG" , +}; +struct image_cfg_element { -enum { -IMAGE_CFG_VERSION =0x1 , -IMAGE_CFG_BOOT_FROM , -IMAGE_CFG_DEST_ADDR , -IMAGE_CFG_EXEC_ADDR , -IMAGE_CFG_NAND_BLKSZ , -IMAGE_CFG_NAND_BADBLK_LOCATION , -IMAGE_CFG_NAND_ECC_MODE , -IMAGE_CFG_NAND_PAGESZ , -IMAGE_CFG_BINARY , -IMAGE_CFG_PAYLOAD , -IMAGE_CFG_DATA , -IMAGE_CFG_BAUDRATE , -IMAGE_CFG_DEBUG , - } type; +enum image_cfg_type type;union {unsigned int version;unsigned int bootfrom;
@@ -520,78 +541,94 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,return image; } +int recognize_keyword (char *keyword) +{ +int kw_id; + +for (kw_id =1 ; kw_id <IMAGE_CFG_COUNT ; ++kw_id) +if (!strcmp (keyword, id_strs[kw_id])) +return kw_id; + +return 0 ; +} +static int image_create_config_parse_oneline (char *line,struct image_cfg_element *el) { -char *keyword, *saveptr; -char deliminiters[] =" \t" ; +char *keyword, *saveptr, *value1, *value2; +char delimiters[] =" \t" ; +int keyword_id, ret, argi; +char *unknown_msg ="Ignoring unknown line '%s'\n" ; - keyword =strtok_r (line, deliminiters, &saveptr); -if (!strcmp (keyword,"VERSION" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); + keyword =strtok_r (line, delimiters, &saveptr); + keyword_id =recognize_keyword (keyword); - el->type =IMAGE_CFG_VERSION ; - el->version =atoi (value); - }else if (!strcmp (keyword,"BOOT_FROM" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); -int ret =image_boot_mode_id (value); +if (!keyword_id) { +fprintf (stderr, unknown_msg, line); +return 0 ; + } + + el->type = keyword_id; + + value1 =strtok_r (NULL , delimiters, &saveptr); + +if (!value1) { +fprintf (stderr,"Parameter missing in line '%s'\n" , line); +return -1 ; + } + +switch (keyword_id) { +case IMAGE_CFG_VERSION : + el->version =atoi (value1); +break ; +case IMAGE_CFG_BOOT_FROM : + ret =image_boot_mode_id (value1);if (ret <0 ) { -fprintf (stderr, -"Invalid boot media '%s'\n" , value); +fprintf (stderr,"Invalid boot media '%s'\n" , value1);return -1 ; } - el->type =IMAGE_CFG_BOOT_FROM ; el->bootfrom = ret; - }else if (!strcmp (keyword,"NAND_BLKSZ" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); - - el->type =IMAGE_CFG_NAND_BLKSZ ; - el->nandblksz =strtoul (value,NULL ,16 ); - }else if (!strcmp (keyword,"NAND_BADBLK_LOCATION" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); - - el->type =IMAGE_CFG_NAND_BADBLK_LOCATION ; - el->nandbadblklocation = -strtoul (value,NULL ,16 ); - }else if (!strcmp (keyword,"NAND_ECC_MODE" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); -int ret =image_nand_ecc_mode_id (value); +break ; +case IMAGE_CFG_NAND_BLKSZ : + el->nandblksz =strtoul (value1,NULL ,16 ); +break ; +case IMAGE_CFG_NAND_BADBLK_LOCATION : + el->nandbadblklocation =strtoul (value1,NULL ,16 ); +break ; +case IMAGE_CFG_NAND_ECC_MODE : + ret =image_nand_ecc_mode_id (value1);if (ret <0 ) { -fprintf (stderr, -"Invalid NAND ECC mode '%s'\n" , value); +fprintf (stderr,"Invalid NAND ECC mode '%s'\n" , value1);return -1 ; } - el->type =IMAGE_CFG_NAND_ECC_MODE ; el->nandeccmode = ret; - }else if (!strcmp (keyword,"NAND_PAGE_SIZE" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); - - el->type =IMAGE_CFG_NAND_PAGESZ ; - el->nandpagesz =strtoul (value,NULL ,16 ); - }else if (!strcmp (keyword,"BINARY" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); -int argi =0 ; +break ; +case IMAGE_CFG_NAND_PAGESZ : + el->nandpagesz =strtoul (value1,NULL ,16 ); +break ; +case IMAGE_CFG_BINARY : + argi =0 ; - el->type =IMAGE_CFG_BINARY ; - el->binary.file =strdup (value); + el->binary.file =strdup (value1);while (1 ) { - value =strtok_r (NULL , deliminiters, &saveptr); +char *value =strtok_r (NULL , delimiters, &saveptr); +if (!value)break ; el->binary.args[argi] =strtoul (value,NULL ,16 ); argi++;if (argi >=BINARY_MAX_ARGS ) {fprintf (stderr, -"Too many argument for binary\n" ); +"Too many arguments for BINARY\n" );return -1 ; } } el->binary.nargs = argi; - }else if (!strcmp (keyword,"DATA" )) { -char *value1 =strtok_r (NULL , deliminiters, &saveptr); -char *value2 =strtok_r (NULL , deliminiters, &saveptr); +break ; +case IMAGE_CFG_DATA : + value2 =strtok_r (NULL , delimiters, &saveptr);if (!value1 || !value2) { fprintf(stderr,
@@ -599,19 +636,17 @@ static int image_create_config_parse_oneline(char *line,return -1 ; } - el->type =IMAGE_CFG_DATA ; el->regdata.raddr =strtoul (value1,NULL ,16 ); el->regdata.rdata =strtoul (value2,NULL ,16 ); - }else if (!strcmp (keyword,"BAUDRATE" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_BAUDRATE ; - el->baudrate =strtoul (value,NULL ,10 ); - }else if (!strcmp (keyword,"DEBUG" )) { -char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_DEBUG ; - el->debug =strtoul (value,NULL ,10 ); - }else { -fprintf (stderr,"Ignoring unknown line '%s'\n" , line); +break ; +case IMAGE_CFG_BAUDRATE : + el->baudrate =strtoul (value1,NULL ,10 ); +break ; +case IMAGE_CFG_DEBUG : + el->debug =strtoul (value1,NULL ,10 ); +break ; +default : +fprintf (stderr, unknown_msg, line); }return 0 ;
--
2.9.0
PATCH v2 15/18 tools: kwbimage: Refactor line parsing and fix error
Quoted 10 lines · Mario Six
The function
image_create_config_parse_onelineis pretty complex, and since more parameters will be added to support secure booting, we refactor the function to make it more readable.Also, when a line contained just a keyword without any parameters,
strtok_rreturned NULL, which was then indiscriminately fed into atoi, causing a segfault. To correct this, we add a NULL check before feeding the extracted token to atoi, and print an error message in case the token is NULL.
Quoted 5 lines
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Thanks,
Stefan
PATCH v2 15/18 tools: kwbimage: Refactor line parsing and fix error
In reply to Mario SixQuoted 10 lines · Mario Six
The function
image_create_config_parse_onelineis pretty complex, and since more parameters will be added to support secure booting, we refactor the function to make it more readable.Also, when a line contained just a keyword without any parameters,
strtok_rreturned NULL, which was then indiscriminately fed into atoi, causing a segfault. To correct this, we add a NULL check before feeding the extracted token to atoi, and print an error message in case the token is NULL.
Quoted 5 lines
Signed-off-by Mario Six <[email protected]>---
Changes in v2:None
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 16/18 arm: mvebu: Implement secure boot
In reply to Mario SixThe patch implements secure booting for the mvebu architecture.
This includes:
- The addition of secure headers and all needed signatures and keys in mkimage
- Commands capable of writing the board's efuses to both write the needed cryptographic data and enable the secure booting mechanism
- The creation of convenience text files containing the necessary commands to write the efuses
The KAK and CSK keys are expected to reside in the files kwb_kak.key and kwb_csk.key (OpenSSL 2048 bit private keys) in the top-level directory.
---
Changes in v2:
* Added help text for MVEBU_EFUSE
* Removed superfluous defined(CONFIG_MVEBU_EFUSE) from arch/arm/mach-mvebu/Makefile
* Rewrote disable_efuse_program to use clrbits_le32
* Remove superfluous blank lines from arch/arm/mach-mvebu/include/mach/efuse.h
--- Makefile | 3 +- arch/arm/mach-mvebu/Kconfig | 35 ++ arch/arm/mach-mvebu/Makefile | 1 + arch/arm/mach-mvebu/efuse.c | 264 +++++++++++ arch/arm/mach-mvebu/include/mach/cpu.h | 2 + arch/arm/mach-mvebu/include/mach/efuse.h | 69 +++ doc/README.armada-secureboot | 373 ++++++++++++++++ tools/Makefile | 6 +- tools/kwbimage.c | 744 ++++++++++++++++++++++++++++++- tools/kwbimage.h | 37 ++ 10 files changed, 1526 insertions(+), 8 deletions(-) create mode 100644 arch/arm/mach-mvebu/efuse.c create mode 100644 arch/arm/mach-mvebu/include/mach/efuse.h create mode 100644 doc/README.armada-secureboot
Makefile +2 -1
@@ -957,7 +957,8 @@ MKIMAGEFLAGS_u-boot.kwb = -n $(srctree)/$(CONFIG_SYS_KWD_CONFIG:"%"=%) \ -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) MKIMAGEFLAGS_u-boot-spl.kwb = -n $(srctree)/$(CONFIG_SYS_KWD_CONFIG:"%"=%) \ - -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) + -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \ + $(if $(KEYDIR),-k $(KEYDIR)) MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \ -R $(srctree)/$(CONFIG_SYS_FSL_PBL_PBI:"%"=%) -T pblimage
arch/arm/mach-mvebu/Kconfig +35 -0
@@ -1,5 +1,9 @@ if ARCH_MVEBU +config HAVE_MVEBU_EFUSE + bool + default n + config ARMADA_32BIT bool select CPU_V7
@@ -21,6 +25,7 @@ config ARMADA_375 config ARMADA_38X bool select ARMADA_32BIT + select HAVE_MVEBU_EFUSE config ARMADA_XP bool
@@ -142,4 +147,34 @@ config SYS_VENDOR config SYS_SOC default "mvebu" +config MVEBU_EFUSE + bool "Enable eFuse support" + default n + depends on HAVE_MVEBU_EFUSE + help + Enable support for reading and writing eFuses on mvebu SoCs. + +config MVEBU_EFUSE_FAKE + bool "Fake eFuse access (dry run)" + default n + depends on MVEBU_EFUSE + help + This enables a "dry run" mode where eFuses are not really programmed. + Instead the eFuse accesses are emulated by writing to and reading + from a memory block. + This is can be used for testing prog scripts. + +config SECURED_MODE_IMAGE + bool "Build image for trusted boot" + default false + depends on 88F6820 + help + Build an image that employs the ARMADA SoC's trusted boot framework + for securely booting images. + +config SECURED_MODE_CSK_INDEX + int "Index of active CSK" + default 0 + depends on SECURED_MODE_IMAGE + endif
arch/arm/mach-mvebu/Makefile +1 -0
@@ -27,6 +27,7 @@ ifndef CONFIG_SPL_BUILD obj-$(CONFIG_ARMADA_375) += ../../../drivers/ddr/marvell/axp/xor.o obj-$(CONFIG_ARMADA_38X) += ../../../drivers/ddr/marvell/a38x/xor.o obj-$(CONFIG_ARMADA_XP) += ../../../drivers/ddr/marvell/axp/xor.o +obj-$(CONFIG_MVEBU_EFUSE) += efuse.o endif # CONFIG_SPL_BUILD obj-y += gpio.o obj-y += mbus.o
arch/arm/mach-mvebu/efuse.c new file +264 -0
264 lines not on this page · raw message
arch/arm/mach-mvebu/include/mach/cpu.h +2 -0
@@ -36,7 +36,9 @@ enum cpu_target {CPU_TARGET_ETH01 =0x7 ,CPU_TARGET_PCIE13 =0x8 ,CPU_TARGET_SASRAM =0x9 , +CPU_TARGET_SATA01 =0xa ,/* A38X */ CPU_TARGET_NAND =0xd , + CPU_TARGET_SATA23_DFX = 0xe, /* A38X */ }; enum cpu_attrib {
arch/arm/mach-mvebu/include/mach/efuse.h new file +69 -0
69 lines not on this page · raw message
doc/README.armada-secureboot new file +373 -0
373 lines not on this page · raw message
tools/Makefile +5 -1
@@ -141,8 +141,12 @@ ifdef CONFIG_SYS_U_BOOT_OFFS HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS) endif +ifneq ($(CONFIG_ARMADA_38X)$(CONFIG_ARMADA_39X),) +HOSTCFLAGS_kwbimage.o += -DCONFIG_KWB_SECURE +endif + # MXSImage needs LibSSL -ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_FIT_SIGNATURE),) +ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_ARMADA_39X)$(CONFIG_FIT_SIGNATURE),) HOSTLOADLIBES_mkimage += \ $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto")
tools/kwbimage.c +738 -6
847 lines not on this page · raw message
tools/kwbimage.h +37 -0
@@ -114,6 +114,43 @@ struct opt_hdr_v1 { };/* +* Public Key data in DER format +*/ +struct pubkey_der_v1 { +uint8_t key[524 ]; +}; + +/* +* Signature (RSA 2048) +*/ +struct sig_v1 { +uint8_t sig[256 ]; +}; + +/* +* Structure of secure header (Armada 38x) +*/ +struct secure_hdr_v1 { +uint8_t headertype;/* 0x0 */ +uint8_t headersz_msb;/* 0x1 */ +uint16_t headersz_lsb;/* 0x2 - 0x3 */ +uint32_t reserved1;/* 0x4 - 0x7 */ +struct pubkey_der_v1 kak;/* 0x8 - 0x213 */ +uint8_t jtag_delay;/* 0x214 */ +uint8_t reserved2;/* 0x215 */ +uint16_t reserved3;/* 0x216 - 0x217 */ +uint32_t boxid;/* 0x218 - 0x21B */ +uint32_t flashid;/* 0x21C - 0x21F */ +struct sig_v1 hdrsig;/* 0x220 - 0x31F */ +struct sig_v1 imgsig;/* 0x320 - 0x41F */ +struct pubkey_der_v1 csk[16 ];/* 0x420 - 0x24DF */ +struct sig_v1 csksig;/* 0x24E0 - 0x25DF */ +uint8_t next;/* 0x25E0 */ +uint8_t reserved4;/* 0x25E1 */ +uint16_t reserved5;/* 0x25E2 - 0x25E3 */ +}; + +/* * Various values for the opt_hdr_v1->headertype field, describing the * different types of optional headers. The "secure" header contains * informations related to secure boot (encryption keys, etc.). The
--
2.9.0
PATCH v2 16/18 arm: mvebu: Implement secure boot
Quoted 15 lines · Mario Six
The patch implements secure booting for the mvebu architecture.
This includes:
- The addition of secure headers and all needed signatures and keys in mkimage
- Commands capable of writing the board's efuses to both write the needed cryptographic data and enable the secure booting mechanism
- The creation of convenience text files containing the necessary commands to write the efusesThe KAK and CSK keys are expected to reside in the files kwb_kak.key and kwb_csk.key (OpenSSL 2048 bit private keys) in the top-level directory.
Signed-off-by Reinhard Pfau <[email protected]>Signed-off-by Mario Six <[email protected]>
Quoted 8 lines
---
Changes in v2:* Added help text for
MVEBU_EFUSE
* Removed superfluousdefined(CONFIG_MVEBU_EFUSE)fromarch/arm/mach-mvebu/Makefile
* Rewrotedisable_efuse_programto useclrbits_le32
* Remove superfluous blank lines fromarch/arm/mach-mvebu/include/mach/efuse.h
Thanks Mario for the nice and extensive documentation that you have added in this patch version. Really appreciated. I only skimmed though the patch and will re-test building for some other AXP / A38x board once I apply this patch series for upstreaming - perhaps next week. For now:
Thanks,
Stefan
PATCH v2 16/18 arm: mvebu: Implement secure boot
In reply to Mario SixQuoted 23 lines · Mario Six
The patch implements secure booting for the mvebu architecture.
This includes:
- The addition of secure headers and all needed signatures and keys in mkimage
- Commands capable of writing the board's efuses to both write the needed cryptographic data and enable the secure booting mechanism
- The creation of convenience text files containing the necessary commands to write the efusesThe KAK and CSK keys are expected to reside in the files kwb_kak.key and kwb_csk.key (OpenSSL 2048 bit private keys) in the top-level directory.
Signed-off-by Reinhard Pfau <[email protected]>Signed-off-by Mario Six <[email protected]>---
Changes in v2:* Added help text for
MVEBU_EFUSE
* Removed superfluousdefined(CONFIG_MVEBU_EFUSE)fromarch/arm/mach-mvebu/Makefile
* Rewrotedisable_efuse_programto useclrbits_le32
* Remove superfluous blank lines fromarch/arm/mach-mvebu/include/mach/efuse.h
Quoted 16 lines
--- Makefile | 3 +- arch/arm/mach-mvebu/Kconfig | 35 ++ arch/arm/mach-mvebu/Makefile | 1 + arch/arm/mach-mvebu/efuse.c | 264 +++++++++++ arch/arm/mach-mvebu/include/mach/cpu.h | 2 + arch/arm/mach-mvebu/include/mach/efuse.h | 69 +++ doc/README.armada-secureboot | 373 ++++++++++++++++ tools/Makefile | 6 +- tools/kwbimage.c | 744 ++++++++++++++++++++++++++++++- tools/kwbimage.h | 37 ++ 10 files changed, 1526 insertions(+), 8 deletions(-) create mode 100644 arch/arm/mach-mvebu/efuse.c create mode 100644 arch/arm/mach-mvebu/include/mach/efuse.h create mode 100644 doc/README.armada-secureboot
PATCH v2 16/18 arm: mvebu: Implement secure boot
In reply to Mario SixQuoted 15 lines · Mario Six
The patch implements secure booting for the mvebu architecture.
This includes:
- The addition of secure headers and all needed signatures and keys in mkimage
- Commands capable of writing the board's efuses to both write the needed cryptographic data and enable the secure booting mechanism
- The creation of convenience text files containing the necessary commands to write the efusesThe KAK and CSK keys are expected to reside in the files kwb_kak.key and kwb_csk.key (OpenSSL 2048 bit private keys) in the top-level directory.
Signed-off-by Reinhard Pfau <[email protected]>Signed-off-by Mario Six <[email protected]>
Quoted 8 lines
---
Changes in v2:* Added help text for
MVEBU_EFUSE
* Removed superfluousdefined(CONFIG_MVEBU_EFUSE)fromarch/arm/mach-mvebu/Makefile
* Rewrotedisable_efuse_programto useclrbits_le32
* Remove superfluous blank lines fromarch/arm/mach-mvebu/include/mach/efuse.h
Applied to u-boot-marvell/master
Thanks,
Stefan
PATCH v2 17/18 arm: mvebu: Add gdsys ControlCenter-Compact board
In reply to Mario SixFrom: Dirk Eibach <[email protected]>
The gdsys ControlCenter Digital board is based on a Marvell Armada 38x SOC.
It boots from SPI-Flash but can be configured to boot from SD-card for factory programming and testing.
On board peripherals include:
- 2 x GbE
- Xilinx Kintex-7 FPGA connected via PCIe
- mSATA
- USB3 host
- Atmel TPM
---
Changes in v2:
* Renamed DTS and board name to include armada-38x
* Renamed 38x directory to a38x
* Removed leftover dummy test Kconfig variable from board/gdsys/38x/Kconfig
* Removed unneeded check for build target in board/gdsys/38x/Makefile
* Removed duplicated board/gdsys/38x/README
* Switched MIIPHY to new GPIO API
* Removed checkboard function
* Fixed multi-line comment in board/gdsys/controlcenterdc.c
* Switched to usage of ARRAY_SIZE in board/gdsys/controlcenterdc.c
* Factored out hydra.{c,h} and ihs_phys.{c,h} from board/gdsys/controlcenterdc.c and removed ifdefs
* Removed unaddressed TODO from HRE
--- arch/arm/Kconfig | 1 + arch/arm/dts/Makefile | 3 +- arch/arm/dts/armada-38x-controlcenterdc.dts | 643 ++++++++++++++++++++++++++++ arch/arm/mach-mvebu/Kconfig | 4 + board/gdsys/a38x/.gitignore | 1 + board/gdsys/a38x/Kconfig | 36 ++ board/gdsys/a38x/MAINTAINERS | 7 + board/gdsys/a38x/Makefile | 44 ++ board/gdsys/a38x/controlcenterdc.c | 273 ++++++++++++ board/gdsys/a38x/dt_helpers.c | 25 ++ board/gdsys/a38x/dt_helpers.h | 14 + board/gdsys/a38x/hre.c | 516 ++++++++++++++++++++++ board/gdsys/a38x/hre.h | 38 ++ board/gdsys/a38x/hydra.c | 138 ++++++ board/gdsys/a38x/hydra.h | 14 + board/gdsys/a38x/ihs_phys.c | 349 +++++++++++++++ board/gdsys/a38x/ihs_phys.h | 2 + board/gdsys/a38x/keyprogram.c | 158 +++++++ board/gdsys/a38x/keyprogram.h | 14 + board/gdsys/a38x/kwbimage.cfg.in | 12 + board/gdsys/a38x/spl.c | 21 + configs/controlcenterdc_defconfig | 57 +++ include/configs/controlcenterdc.h | 235 ++++++++++ 23 files changed, 2604 insertions(+), 1 deletion(-) create mode 100644 arch/arm/dts/armada-38x-controlcenterdc.dts create mode 100644 board/gdsys/a38x/.gitignore create mode 100644 board/gdsys/a38x/Kconfig create mode 100644 board/gdsys/a38x/MAINTAINERS create mode 100644 board/gdsys/a38x/Makefile create mode 100644 board/gdsys/a38x/controlcenterdc.c create mode 100644 board/gdsys/a38x/dt_helpers.c create mode 100644 board/gdsys/a38x/dt_helpers.h create mode 100644 board/gdsys/a38x/hre.c create mode 100644 board/gdsys/a38x/hre.h create mode 100644 board/gdsys/a38x/hydra.c create mode 100644 board/gdsys/a38x/hydra.h create mode 100644 board/gdsys/a38x/ihs_phys.c create mode 100644 board/gdsys/a38x/ihs_phys.h create mode 100644 board/gdsys/a38x/keyprogram.c create mode 100644 board/gdsys/a38x/keyprogram.h create mode 100644 board/gdsys/a38x/kwbimage.cfg.in create mode 100644 board/gdsys/a38x/spl.c create mode 100644 configs/controlcenterdc_defconfig create mode 100644 include/configs/controlcenterdc.h
arch/arm/Kconfig +1 -0
@@ -1028,6 +1028,7 @@ source "board/freescale/mx53loco/Kconfig" source "board/freescale/mx53smd/Kconfig" source "board/freescale/s32v234evb/Kconfig" source "board/freescale/vf610twr/Kconfig" +source "board/gdsys/a38x/Kconfig" source "board/gumstix/pepper/Kconfig" source "board/h2200/Kconfig" source "board/hisilicon/hikey/Kconfig"
arch/arm/dts/Makefile +2 -1
@@ -79,7 +79,8 @@ dtb-$(CONFIG_ARCH_MVEBU) += \ armada-xp-gp.dtb \ armada-xp-maxbcm.dtb \ armada-xp-synology-ds414.dtb \ - armada-xp-theadorable.dtb + armada-xp-theadorable.dtb \ + armada-38x-controlcenterdc.dtb dtb-$(CONFIG_ARCH_UNIPHIER) += \ uniphier-ld11-ref.dtb \
arch/arm/dts/armada-38x-controlcenterdc.dts new file +643 -0
643 lines not on this page · raw message
arch/arm/mach-mvebu/Kconfig +4 -0
@@ -108,6 +108,10 @@ config TARGET_THEADORABLE bool "Support theadorable Armada XP" select MV78260 +config TARGET_CONTROLCENTERDC + bool "Support CONTROLCENTERDC" + select 88F6820 + endchoice config SYS_BOARD
board/gdsys/a38x/.gitignore new file +1 -0
@@ -0,0 +1 @@ +kwbimage.cfg
board/gdsys/a38x/Kconfig new file +36 -0
@@ -0,0 +1,36 @@ +if TARGET_CONTROLCENTERDC + +config SYS_BOARD + default "a38x" + +config SYS_VENDOR + default "gdsys" + +config SYS_SOC + default "mvebu" + +config SYS_CONFIG_NAME + default "controlcenterdc" + +menu "Controlcenter DC board options" + +choice + prompt "Select boot method" + +config SPL_BOOT_DEVICE_SPI + bool "SPI" + +config SPL_BOOT_DEVICE_MMC + bool "MMC" + select SPL_LIBDISK_SUPPORT + +endchoice + +#config SPL_BOOT_DEVICE +# int +# default 1 if SPL_BOOT_DEVICE_SPI +# default 2 if SPL_BOOT_DEVICE_MMC + +endmenu + +endif
board/gdsys/a38x/MAINTAINERS new file +7 -0
@@ -0,0 +1,7 @@ +A38X BOARD +M: Dirk Eibach <[email protected]> +M: Mario Six <[email protected]> +S: Maintained +F: board/gdsys/a38x/ +F: include/configs/controlcenterdc.h +F: configs/controlcenterdc_defconfig
board/gdsys/a38x/Makefile new file +44 -0
44 lines not on this page · raw message
board/gdsys/a38x/controlcenterdc.c new file +273 -0
273 lines not on this page · raw message
board/gdsys/a38x/dt_helpers.c new file +25 -0
@@ -0,0 +1,25 @@ +/* +* (C) Copyright 2016 +* Mario Six, Guntermann & Drunck GmbH, [email protected] +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <i2c.h> +#include <fdt_support.h> + +int fdt_disable_by_ofname (void *rw_fdt_blob,char *ofname) +{ +int offset =fdt_path_offset (rw_fdt_blob, ofname); + +return fdt_status_disabled (rw_fdt_blob, offset); +} + +bool dm_i2c_simple_probe (struct udevice *bus,uint chip_addr) +{ +struct udevice *dev; + +return !dm_i2c_probe (bus, chip_addr,DM_I2C_CHIP_RD_ADDRESS | +DM_I2C_CHIP_WR_ADDRESS , &dev); +}
board/gdsys/a38x/dt_helpers.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* (C) Copyright 2016 +* Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __DT_HELPERS_H +#define __DT_HELPERS_H + +int fdt_disable_by_ofname (void *rw_fdt_blob,char *ofname); +bool dm_i2c_simple_probe (struct udevice *bus,uint chip_addr); + +#endif /* __DT_HELPERS_H */
board/gdsys/a38x/hre.c new file +516 -0
516 lines not on this page · raw message
board/gdsys/a38x/hre.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* (C) Copyright 2013 +* Reinhard Pfau, Guntermann & Drunck GmbH, reinhard.pfau at gdsys.cc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __HRE_H +#define __HRE_H + +struct key_program { +uint32_t magic; +uint32_t code_crc; +uint32_t code_size; +uint8_t code[]; +}; + +struct h_reg { +bool valid; +uint8_t digest[20 ]; +}; + +/* CCDM specific contants */ +enum { +/* NV indices */ +NV_COMMON_DATA_INDEX =0x40000001 , +/* magics for key blob chains */ +MAGIC_KEY_PROGRAM =0x68726500 , +MAGIC_HMAC =0x68616300 , +MAGIC_END_OF_CHAIN =0x00000000 , +/* sizes */ +NV_COMMON_DATA_MIN_SIZE =3 *sizeof (uint64_t ) +2 *sizeof (uint16_t ), +}; + +int hre_verify_program (struct key_program *prg); +int hre_run_program (const uint8_t *code,size_t code_size); + +#endif /* __HRE_H */
board/gdsys/a38x/hydra.c new file +138 -0
138 lines not on this page · raw message
board/gdsys/a38x/hydra.h new file +14 -0
@@ -0,0 +1,14 @@ +struct ihs_fpga { +u32 reflection_low;/* 0x0000 */ +u32 versions;/* 0x0004 */ +u32 fpga_version;/* 0x0008 */ +u32 fpga_features;/* 0x000c */ +u32 reserved0[4 ];/* 0x0010 */ +u32 control;/* 0x0020 */ +u32 reserved1[375 ];/* 0x0024 */ +u32 qsgmii_port_state[80 ];/* 0x0600 */ +}; + +void print_hydra_version (uint index); +void hydra_initialize (void ); +struct ihs_fpga *get_fpga (void );
board/gdsys/a38x/ihs_phys.c new file +349 -0
349 lines not on this page · raw message
board/gdsys/a38x/ihs_phys.h new file +2 -0
@@ -0,0 +1,2 @@ +uint calculate_octo_phy_mask (void ); +int init_octo_phys (uint octo_phy_mask);
board/gdsys/a38x/keyprogram.c new file +158 -0
158 lines not on this page · raw message
board/gdsys/a38x/keyprogram.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* (C) Copyright 2016 +* Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __KEYPROGRAM_H +#define __KEYPROGRAM_H + +int load_and_run_keyprog (void ); +int flush_keys (void ); + +#endif /* __KEYPROGRAM_H */
board/gdsys/a38x/kwbimage.cfg.in new file +12 -0
@@ -0,0 +1,12 @@ +# +# Copyright (C) 2014 Stefan Roese <[email protected]> +# + +# Armada 38x uses version 1 image format +VERSION 1 + +# Boot Media configurations +#@BOOT_FROM + +# Binary Header (bin_hdr) with DDR3 training code +BINARY spl/u-boot-spl.bin 0000005b 00000068
board/gdsys/a38x/spl.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* (C) Copyright 2016 +* Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <config.h> +#include <asm/arch/cpu.h> + +void spl_board_init (void ) +{ +#if CONFIG_SPL_BOOT_DEVICE ==SPL_BOOT_SPI_NOR_FLASH +u32 *bootrom_save = (u32 *)CONFIG_SPL_BOOTROM_SAVE ; +u32 *regs = (u32 *)(*bootrom_save); + +printf ("Returning to BootROM (return address %08x)...\n" , regs[13 ]); +return_to_bootrom (); +#endif +}
configs/controlcenterdc_defconfig new file +57 -0
57 lines not on this page · raw message
include/configs/controlcenterdc.h new file +235 -0
235 lines not on this page · raw message
--
2.9.0
PATCH v2 17/18 arm: mvebu: Add gdsys ControlCenter-Compact board
Quoted 20 lines · Mario Six
From: Dirk Eibach <[email protected]>
The gdsys ControlCenter Digital board is based on a Marvell Armada 38x SOC.
It boots from SPI-Flash but can be configured to boot from SD-card for factory programming and testing.
On board peripherals include:
- 2 x GbE
- Xilinx Kintex-7 FPGA connected via PCIe
- mSATA
- USB3 host
- Atmel TPMSigned-off-by Dirk Eibach <[email protected]>Signed-off-by Mario Six <[email protected]>---
Changes in v2:
Quoted 12 lines
* Renamed DTS and board name to include armada-38x
* Renamed 38x directory to a38x
* Removed leftover dummy testKconfigvariable from board/gdsys/38x/Kconfig
* Removed unneeded check for build target in board/gdsys/38x/Makefile
* Removed duplicated board/gdsys/38x/README
* Switched MIIPHY to new GPIO API
* Removed checkboard function
* Fixed multi-line comment inboard/gdsys/controlcenterdc.c
* Switched to usage ofARRAY_SIZEinboard/gdsys/controlcenterdc.c
* Factored out hydra.{c,h} and ihs_phys.{c,h} fromboard/gdsys/controlcenterdc.cand removed ifdefs
* Removed unaddressed TODO from HRE
Thanks for working on this. A few comment still (I didn't look that closely in this patch as its still huge):
- Are the DT properties okay also for Linux integration? I assume that you plan to use Linux on these board, right?
- Is it perhaps possible to move some (most) of the crypto code (hre.c) into some common directory, or is this really board specific?
Thanks,
Stefan
PATCH v2 18/18 controlcenterdc: Make secure boot available
In reply to Mario SixMake secure booting available for the controlcenterdc board (disabled by default).
---
Changes in v2:
* Moved definition and interpretation of SECURED_MODE_IMAGE and SECURED_MODE_CSK_INDEX to previous patch
--- board/gdsys/a38x/kwbimage.cfg.in | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
board/gdsys/a38x/kwbimage.cfg.in +28 -0
@@ -1,5 +1,6 @@ # # Copyright (C) 2014 Stefan Roese <[email protected]> +# Copyright (C) 2015-2016 Reinhard Pfau <[email protected]> # # Armada 38x uses version 1 image format
@@ -10,3 +11,30 @@ VERSION 1 # Binary Header (bin_hdr) with DDR3 training code BINARY spl/u-boot-spl.bin 0000005b 00000068 + +# Name of KAK +KAK kwb_kak + +# Name of (active) CSK +CSK kwb_csk + +# BoxID +BOX_ID 0x1 + +# FlashID +FLASH_ID 0x1 + +# JTAG delay +JTAG_DELAY 5 + +# active CSK index +#@CSK_INDEX + +# whether to encode box ID and flash ID into image +#SEC_SPECIALIZED_IMG + +# secured mode boot device +#@SEC_BOOT_DEV + +# secured mode: dump fuse commands +#@SEC_FUSE_DUMP
--
2.9.0
PATCH v2 18/18 controlcenterdc: Make secure boot available
Quoted 5 lines · Mario Six
Make secure booting available for the controlcenterdc board (disabled by default).
Signed-off-by Reinhard Pfau <[email protected]>Signed-off-by Mario Six <[email protected]>
Quoted 8 lines
---
Changes in v2:* Moved definition and interpretation of
SECURED_MODE_IMAGEandSECURED_MODE_CSK_INDEXto previous patch--- board/gdsys/a38x/kwbimage.cfg.in | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Don't you need to change something in the defconfig to enable secure boot on this board?
Thanks,
Stefan