[PATCH 2/3] nvmem: ocotp: use tab for indention only

2024-02-12 Thread Marc Kleine-Budde
Replace space+tabs by tabs only for indention.

Fixes: 1c2d1d4e5985 ("ARM: i.MX8MP: enhance support for ocotp driver")
Signed-off-by: Marc Kleine-Budde 
---
 drivers/nvmem/ocotp.c | 50 ++-
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 28c121152e8b..16d2a6be9fce 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -53,12 +53,12 @@
 #define OCOTP_READ_CTRL0x30
 #define OCOTP_READ_FUSE_DATA   0x40
 
-#define MX7_OCOTP_DATA00x20
-#define MX7_OCOTP_DATA10x30
-#define MX7_OCOTP_DATA20x40
-#define MX7_OCOTP_DATA30x50
-#define MX7_OCOTP_READ_CTRL0x60
-#define MX7_OCOTP_READ_FUSE_DATA0  0x70
+#define MX7_OCOTP_DATA00x20
+#define MX7_OCOTP_DATA10x30
+#define MX7_OCOTP_DATA20x40
+#define MX7_OCOTP_DATA30x50
+#define MX7_OCOTP_READ_CTRL0x60
+#define MX7_OCOTP_READ_FUSE_DATA0  0x70
 #define MX7_OCOTP_READ_FUSE_DATA1  0x80
 #define MX7_OCOTP_READ_FUSE_DATA2  0x90
 #define MX7_OCOTP_READ_FUSE_DATA3  0xA0
@@ -67,27 +67,29 @@
 #define DEF_STROBE_PROG1   /* IPG clocks */
 
 /* OCOTP Registers bits and masks */
-#define OCOTP_CTRL_ADDR  GENMASK(7, 0)
-#define OCOTP_CTRL_BUSY  BIT(8)
-#define OCOTP_CTRL_ERROR BIT(9)
-#define OCOTP_CTRL_RELOAD_SHADOWS BIT(10)
-#define OCOTP_CTRL_WR_UNLOCK GENMASK(31, 16)
-#define OCOTP_CTRL_WR_UNLOCK_KEY  0x3E77
+#define OCOTP_CTRL_ADDRGENMASK(7, 0)
+#define OCOTP_CTRL_BUSYBIT(8)
+#define OCOTP_CTRL_ERROR   BIT(9)
+#define OCOTP_CTRL_RELOAD_SHADOWS  BIT(10)
+#define OCOTP_CTRL_WR_UNLOCK   GENMASK(31, 16)
+#define OCOTP_CTRL_WR_UNLOCK_KEY   0x3E77
 
-/* i.MX8MP OCOTP CTRL has a different layout. See RM Rev.1 06/2021 Section
-   * 6.3.5.1.2.4 */
-#define OCOTP_CTRL_ADDR_8MP  GENMASK(8, 0)
-#define OCOTP_CTRL_BUSY_8MP  BIT(9)
-#define OCOTP_CTRL_ERROR_8MP BIT(10)
-#define OCOTP_CTRL_RELOAD_SHADOWS_8MP BIT(11)
-#define OCOTP_CTRL_WR_UNLOCK_8MP  GENMASK(31, 16)
+/*
+ * i.MX8MP OCOTP CTRL has a different layout. See RM Rev.1 06/2021
+ * Section 6.3.5.1.2.4
+ */
+#define OCOTP_CTRL_ADDR_8MPGENMASK(8, 0)
+#define OCOTP_CTRL_BUSY_8MPBIT(9)
+#define OCOTP_CTRL_ERROR_8MP   BIT(10)
+#define OCOTP_CTRL_RELOAD_SHADOWS_8MP  BIT(11)
+#define OCOTP_CTRL_WR_UNLOCK_8MP   GENMASK(31, 16)
 
-#define OCOTP_TIMING_STROBE_READ GENMASK(21, 16)
-#define OCOTP_TIMING_RELAX  GENMASK(15, 12)
-#define OCOTP_TIMING_STROBE_PROG GENMASK(11, 0)
-#define OCOTP_TIMING_WAIT   GENMASK(27, 22)
+#define OCOTP_TIMING_STROBE_READ   GENMASK(21, 16)
+#define OCOTP_TIMING_RELAX GENMASK(15, 12)
+#define OCOTP_TIMING_STROBE_PROG   GENMASK(11, 0)
+#define OCOTP_TIMING_WAIT  GENMASK(27, 22)
 
-#define OCOTP_READ_CTRL_READ_FUSE BIT(1)
+#define OCOTP_READ_CTRL_READ_FUSE  BIT(1)
 
 #define OCOTP_OFFSET_TO_ADDR(o) (OCOTP_OFFSET_TO_INDEX(o) * 4)
 
-- 
2.43.0





[PATCH 3/3] nvmem: ocotp: mark data as const

2024-02-12 Thread Marc Kleine-Budde
Mark values obtained from "priv->data->ctrl" as const.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/nvmem/ocotp.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 16d2a6be9fce..c282efefa824 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -275,11 +275,11 @@ static int imx6_ocotp_prepare(struct ocotp_priv *priv)
 
 static int imx6_fuse_read_addr(struct ocotp_priv *priv, u32 addr, u32 *pdata)
 {
+   const u32 bm_ctrl_error = priv->data->ctrl->bm_error;
+   const u32 bm_ctrl_addr = priv->data->ctrl->bm_addr;
+   const u32 bm_ctrl_wr_unlock = priv->data->ctrl->bm_wr_unlock;
u32 ctrl_reg;
int ret;
-   u32 bm_ctrl_error = priv->data->ctrl->bm_error;
-   u32 bm_ctrl_addr = priv->data->ctrl->bm_addr;
-   u32 bm_ctrl_wr_unlock = priv->data->ctrl->bm_wr_unlock;
 
writel(bm_ctrl_error, priv->base + OCOTP_CTRL_CLR);
 
@@ -304,13 +304,13 @@ static int imx6_fuse_read_addr(struct ocotp_priv *priv, 
u32 addr, u32 *pdata)
 
 static int imx7_fuse_read_addr(struct ocotp_priv *priv, u32 index, u32 *pdata)
 {
+   const u32 bm_ctrl_error = priv->data->ctrl->bm_error;
+   const u32 bm_ctrl_addr = priv->data->ctrl->bm_addr;
+   const u32 bm_ctrl_wr_unlock = priv->data->ctrl->bm_wr_unlock;
u32 ctrl_reg;
u32 bank_addr;
u16 word;
int ret;
-   u32 bm_ctrl_error = priv->data->ctrl->bm_error;
-   u32 bm_ctrl_addr = priv->data->ctrl->bm_addr;
-   u32 bm_ctrl_wr_unlock = priv->data->ctrl->bm_wr_unlock;
 
word = index & 0x3;
bank_addr = index >> 2;
@@ -391,10 +391,10 @@ static int imx_ocotp_reg_read(void *ctx, unsigned int 
reg, unsigned int *val)
 
 static void imx_ocotp_clear_unlock(struct ocotp_priv *priv, u32 index)
 {
+   const u32 bm_ctrl_error = priv->data->ctrl->bm_error;
+   const u32 bm_ctrl_addr = priv->data->ctrl->bm_addr;
+   const u32 bm_ctrl_wr_unlock = priv->data->ctrl->bm_wr_unlock;
u32 ctrl_reg;
-   u32 bm_ctrl_error = priv->data->ctrl->bm_error;
-   u32 bm_ctrl_addr = priv->data->ctrl->bm_addr;
-   u32 bm_ctrl_wr_unlock = priv->data->ctrl->bm_wr_unlock;
 
writel(bm_ctrl_error, priv->base + OCOTP_CTRL_CLR);
 
@@ -408,8 +408,8 @@ static void imx_ocotp_clear_unlock(struct ocotp_priv *priv, 
u32 index)
 
 static int imx6_fuse_blow_addr(struct ocotp_priv *priv, u32 index, u32 value)
 {
+   const u32 bm_ctrl_error = priv->data->ctrl->bm_error;
int ret;
-   u32 bm_ctrl_error = priv->data->ctrl->bm_error;
 
imx_ocotp_clear_unlock(priv, index);
 
@@ -474,7 +474,7 @@ static int imx7_fuse_blow_addr(struct ocotp_priv *priv, u32 
index, u32 value)
 
 static int imx6_ocotp_reload_shadow(struct ocotp_priv *priv)
 {
-   u32 bm_ctrl_reload_shadows = priv->data->ctrl->bm_reload_shadows;
+   const u32 bm_ctrl_reload_shadows = priv->data->ctrl->bm_reload_shadows;
 
dev_info(&priv->dev, "reloading shadow registers...\n");
writel(bm_ctrl_reload_shadows, priv->base + OCOTP_CTRL_SET);
@@ -486,8 +486,8 @@ static int imx6_ocotp_reload_shadow(struct ocotp_priv *priv)
 static int imx6_ocotp_blow_one_u32(struct ocotp_priv *priv, u32 index, u32 
data,
u32 *pfused_value)
 {
+   const u32 bm_ctrl_error = priv->data->ctrl->bm_error;
int ret;
-   u32 bm_ctrl_error = priv->data->ctrl->bm_error;
 
ret = imx6_ocotp_prepare(priv);
if (ret) {
-- 
2.43.0





[PATCH 1/3] habv4: convert comments to common coding style

2024-02-12 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv4.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index c60a658b89af..6440ef7f5196 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -147,9 +147,11 @@ struct hab_header {
 typedef enum hab_status hab_loader_callback_fn(void **start, size_t *bytes, 
const void *boot_data);
 typedef void hab_image_entry_fn(void);
 
-/* This table is constructed from the NXP manual "High Assurance Boot Version 4
- * Application Programming Interface Reference Manual", section 4.5 ROM vector
- * table. Revision 1.4 */
+/*
+ * This table is constructed from the NXP manual "High Assurance Boot
+ * Version 4 Application Programming Interface Reference Manual",
+ * section 4.5 ROM vector table. Revision 1.4
+ */
 struct habv4_rvt {
struct hab_header header;
enum hab_status (*entry)(void);
@@ -169,9 +171,11 @@ struct habv4_rvt {
 
 #define FSL_SIP_HAB 0xC207
 
-/* These values correspondent to the jump table found in the upstream TF-A
- * version 2.10 `imx_hab_handler`, not all HAB rom functions are supported yet.
- * */
+/*
+ * These values correspondent to the jump table found in the upstream
+ * TF-A version 2.10 `imx_hab_handler`, not all HAB rom functions are
+ * supported yet.
+ */
 enum hab_sip_cmd {
FSL_SIP_HAB_AUTHENTICATE = 0x00,
FSL_SIP_HAB_ENTRY = 0x01,
-- 
2.43.0





[PATCH 0/3] habv4/ocotp: style fixes

2024-02-12 Thread Marc Kleine-Budde
Hello,

while rebasing an internal branch, I found some style fixes for the
habv4 and ocotp driver.

regards,
Marc





Re: [PATCH 1/2] habv4: correct habv4 rom vector table

2024-01-12 Thread Marc Kleine-Budde
On 11.01.2024 16:42:19, Stefan Kerkmann wrote:
> All function signatures have been taken from the NXP manual "High
> Assurance Boot Version 4 Application Programming Interface Reference
> Manual" revision 1.4 under section "4.5 ROM vector table". A copy can be
> obtained from the imx code signing tool (imx-cst).
> 
> Signed-off-by: Stefan Kerkmann 

What's the size of a size_t on imx6? We don't want to break the 32 bit
platforms.

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde  |
Embedded Linux   | https://www.pengutronix.de |
Vertretung Nürnberg  | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |


signature.asc
Description: PGP signature


[PATCH v4 3/3] ARM: i.MX8MM: add Phytec i.MX8MM SoM support

2023-08-09 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/boards/Makefile   |1 +
 arch/arm/boards/phytec-som-imx8mm/Makefile |4 +
 arch/arm/boards/phytec-som-imx8mm/board.c  |   40 +
 .../flash-header-imx8mm-phyboard-polis-rdk.imxcfg  |7 +
 arch/arm/boards/phytec-som-imx8mm/lowlevel.c   |  138 ++
 arch/arm/boards/phytec-som-imx8mm/lowlevel.h   |8 +
 arch/arm/boards/phytec-som-imx8mm/lpddr4-timing.c  | 1850 
 arch/arm/dts/Makefile  |1 +
 arch/arm/dts/imx8mm-phyboard-polis-rdk.dts |  131 ++
 arch/arm/mach-imx/Kconfig  |   13 +
 images/Makefile.imx|   20 +
 11 files changed, 2213 insertions(+)

diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index 382e649fce62..e587a8c14a49 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -95,6 +95,7 @@ obj-$(CONFIG_MACH_PHYTEC_SOM_AM335X)  += 
phytec-som-am335x/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX6) += phytec-som-imx6/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7) += phytec-phycore-imx7/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1) += phytec-phycore-stm32mp1/
+obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM)   += phytec-som-imx8mm/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ)   += phytec-som-imx8mq/
 obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3) += plathome-openblocks-ax3/
 obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_A6)  += plathome-openblocks-a6/
diff --git a/arch/arm/boards/phytec-som-imx8mm/Makefile 
b/arch/arm/boards/phytec-som-imx8mm/Makefile
new file mode 100644
index ..10abebc53921
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+lwl-y += lowlevel.o lpddr4-timing.o
+obj-y += board.o
diff --git a/arch/arm/boards/phytec-som-imx8mm/board.c 
b/arch/arm/boards/phytec-som-imx8mm/board.c
new file mode 100644
index ..52f821f5fa30
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/board.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: 2022 Ahmad Fatoum, Pengutronix
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int phyboard_polis_rdk_probe(struct device *dev)
+{
+   int emmc_bbu_flag = 0;
+   int sd_bbu_flag = 0;
+
+   if (bootsource_get() == BOOTSOURCE_MMC && bootsource_get_instance() == 
1) {
+   of_device_enable_path("/chosen/environment-sd");
+   sd_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+   } else {
+   of_device_enable_path("/chosen/environment-emmc");
+   emmc_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+   }
+
+   imx8m_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc2", 
emmc_bbu_flag);
+   imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", 
sd_bbu_flag);
+
+   return 0;
+}
+
+static const struct of_device_id phyboard_polis_rdk_of_match[] = {
+   { .compatible = "phytec,imx8mm-phyboard-polis-rdk" },
+   { /* sentinel */ },
+};
+BAREBOX_DEEP_PROBE_ENABLE(phyboard_polis_rdk_of_match);
+
+static struct driver phyboard_polis_rdkboard_driver = {
+   .name = "board-phyboard-polis-rdk",
+   .probe = phyboard_polis_rdk_probe,
+   .of_compatible = DRV_OF_COMPAT(phyboard_polis_rdk_of_match),
+};
+coredevice_platform_driver(phyboard_polis_rdkboard_driver);
diff --git 
a/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
 
b/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
new file mode 100644
index ..10606ce29c96
--- /dev/null
+++ 
b/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+soc imx8mm
+
+loadaddr 0x007e1000
+max_load_size 0x3f000
+ivtofs 0x400
diff --git a/arch/arm/boards/phytec-som-imx8mm/lowlevel.c 
b/arch/arm/boards/phytec-som-imx8mm/lowlevel.c
new file mode 100644
index ..26f0f4d3e12e
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/lowlevel.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lowlevel.h"
+
+extern char __dtb_z_imx8mm_phyboard_polis_rdk_start[];
+
+#define UART_PAD_CTRL MUX_PAD_CTRL(PAD_CTL_DSE_3P3V_45_OHM)
+
+static void setup_uart(void)
+{
+   void __iomem *uart = IOMEM(MX8M_UART3_BASE_ADDR);
+
+   imx8m_early_setup_uart_clock();
+
+   imx8mm_setup_pad(IMX8MM_PAD_UART3_TXD_UART3_TX | UART_PAD_CTRL);
+   imx8m_uart_setup(uart);
+
+   pbl_set_putc(imx_uart_putc, uart);
+   putc_ll('>');
+}
+
+#define EEPROM_ADDR 0x51
+#define EEPROM_ADDR_FALLBACK 0x59
+
+

[PATCH v4 0/3] ARM: i.MX8MM: add Phytec i.MX8 SoM support

2023-08-09 Thread Marc Kleine-Budde
This series adds support for the Phytec i.MX8 SoM. It comes with a
minimal i2c EEPROM read helper for the PBL and imports + adopts the
Phytec SOM detection from u-boot. The Phytec SOM detection reads and
parses the EEPROM on the SOM to figure out the size of the populated
RAM.

Signed-off-by: Marc Kleine-Budde 
---
Changes in v4:
- rebased to current next
- actually the same as v3, but send to barebox mailing list

Changes in v3:
- phyboard_polis_rdk_ddr_init():
  - introduce PHYTEC_IMX8M_DDR_* for different RAM sizes
  - get rid of CONFIG_PHYCORE_IMX8MM_RAM_SIZE_* and build always all
images
  - clean up printing of error messages
- lpddr4-timing: adopt to coding style
- Link to v2: 
https://lore.pengutronix.de/20230606-phytec-som-imx8mm-v2-0-8c9368c8b...@pengutronix.de

Changes in v2:
- make several pointers to "struct phytec_eeprom" const
- phytec_print_som_info(): use printf() instead of pr_cont()
- let phytec_imx8m_detect() return int instead of u8
- fix typo in phytec_get_imx8m_spi()'s comment
- rename struct phytec_api0_data::pad -> __pad
- move include/phytec-som-* to include/boards/phytec
- Link to v1: 
https://lore.barebox.org/20230606-phytec-som-imx8mm-v1-0-b9c2bf70b...@pengutronix.de

---
Marc Kleine-Budde (3):
  i2c: add  for PBL use
  common: board: phytec: import SoM detection for imx8m based SoM from 
u-boot
  ARM: i.MX8MM: add Phytec i.MX8MM SoM support

 arch/arm/boards/Makefile   |1 +
 arch/arm/boards/phytec-som-imx8mm/Makefile |4 +
 arch/arm/boards/phytec-som-imx8mm/board.c  |   40 +
 .../flash-header-imx8mm-phyboard-polis-rdk.imxcfg  |7 +
 arch/arm/boards/phytec-som-imx8mm/lowlevel.c   |  138 ++
 arch/arm/boards/phytec-som-imx8mm/lowlevel.h   |8 +
 arch/arm/boards/phytec-som-imx8mm/lpddr4-timing.c  | 1850 
 arch/arm/dts/Makefile  |1 +
 arch/arm/dts/imx8mm-phyboard-polis-rdk.dts |  131 ++
 arch/arm/mach-imx/Kconfig  |   13 +
 common/boards/Kconfig  |7 +
 common/boards/Makefile |1 +
 common/boards/phytec/Makefile  |5 +
 common/boards/phytec/phytec-som-detection.c|  209 +++
 common/boards/phytec/phytec-som-imx8m-detection.c  |  151 ++
 images/Makefile.imx|   20 +
 include/boards/phytec/phytec-som-detection.h   |   69 +
 include/boards/phytec/phytec-som-imx8m-detection.h |   26 +
 include/pbl/eeprom.h   |   34 +
 19 files changed, 2715 insertions(+)
---
base-commit: 824533a0027a626b43b5a7dacab4cf875cc019f4
change-id: 20230606-phytec-som-imx8mm-2c90276fb58c

Best regards,
-- 
Marc Kleine-Budde 





[PATCH v4 1/3] i2c: add for PBL use

2023-08-09 Thread Marc Kleine-Budde
Add a small helper to read a single page of EEPROM data.

Signed-off-by: Marc Kleine-Budde 
---
 include/pbl/eeprom.h | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/include/pbl/eeprom.h b/include/pbl/eeprom.h
new file mode 100644
index ..df868b1a37fb
--- /dev/null
+++ b/include/pbl/eeprom.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PBL_EEPROM_H_
+#define __PBL_EEPROM_H_
+
+#include 
+#include 
+
+static inline void eeprom_read(struct pbl_i2c *i2c, u16 client_addr, u32 addr, 
void *buf, u16 count)
+{
+   u8 msgbuf[2];
+   struct i2c_msg msg[] = {
+   {
+   .addr = client_addr,
+   .buf = msgbuf,
+   }, {
+   .addr = client_addr,
+   .flags = I2C_M_RD,
+   .buf = buf,
+   .len = count,
+   },
+   };
+   int ret, i = 0;
+
+   if (addr & I2C_ADDR_16_BIT)
+   msgbuf[i++] = addr >> 8;
+   msgbuf[i++] = addr;
+   msg[0].len = i;
+
+   ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
+   if (ret != ARRAY_SIZE(msg))
+   pr_err("Failed to read from eeprom@%x: %d\n", client_addr, ret);
+}
+
+#endif

-- 
2.40.1





[PATCH v4 2/3] common: board: phytec: import SoM detection for imx8m based SoM from u-boot

2023-08-09 Thread Marc Kleine-Budde
This patch imports and cleans up the SoM detection for imx8m based SoM
from u-boot.

Signed-off-by: Marc Kleine-Budde 
---
 common/boards/Kconfig  |   7 +
 common/boards/Makefile |   1 +
 common/boards/phytec/Makefile  |   5 +
 common/boards/phytec/phytec-som-detection.c| 209 +
 common/boards/phytec/phytec-som-imx8m-detection.c  | 151 +++
 include/boards/phytec/phytec-som-detection.h   |  69 +++
 include/boards/phytec/phytec-som-imx8m-detection.h |  26 +++
 7 files changed, 468 insertions(+)

diff --git a/common/boards/Kconfig b/common/boards/Kconfig
index 3ac3dcbe0406..a1d87c02158f 100644
--- a/common/boards/Kconfig
+++ b/common/boards/Kconfig
@@ -3,3 +3,10 @@
 config BOARD_QEMU_VIRT
bool
select OF_OVERLAY
+
+config BOARD_PHYTEC_SOM_DETECTION
+   bool
+
+config BOARD_PHYTEC_SOM_IMX8M_DETECTION
+   bool
+   select BOARD_PHYTEC_SOM_DETECTION
diff --git a/common/boards/Makefile b/common/boards/Makefile
index 5b4e429c13e9..c1e1b78df383 100644
--- a/common/boards/Makefile
+++ b/common/boards/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 obj-$(CONFIG_BOARD_QEMU_VIRT)  += qemu-virt/
+obj-$(CONFIG_BOARD_PHYTEC_SOM_DETECTION) += phytec/
diff --git a/common/boards/phytec/Makefile b/common/boards/phytec/Makefile
new file mode 100644
index ..fef6134a1609
--- /dev/null
+++ b/common/boards/phytec/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+lwl- += dummy.o
+lwl-$(CONFIG_BOARD_PHYTEC_SOM_DETECTION) += phytec-som-detection.o
+lwl-$(CONFIG_BOARD_PHYTEC_SOM_IMX8M_DETECTION) += phytec-som-imx8m-detection.o
diff --git a/common/boards/phytec/phytec-som-detection.c 
b/common/boards/phytec/phytec-som-detection.c
new file mode 100644
index ..e338639d03e9
--- /dev/null
+++ b/common/boards/phytec/phytec-som-detection.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 PHYTEC Messtechnik GmbH
+ * Author: Teresa Remmet 
+ */
+
+#include 
+#include 
+#include 
+
+struct phytec_eeprom_data eeprom_data;
+
+#define POLY (0x1070U << 3)
+
+static u8 _crc8(u16 data)
+{
+   int i;
+
+   for (i = 0; i < 8; i++) {
+   if (data & 0x8000)
+   data = data ^ POLY;
+   data = data << 1;
+   }
+
+   return data >> 8;
+}
+
+static unsigned int crc8(unsigned int crc, const u8 *vptr, int len)
+{
+   int i;
+
+   for (i = 0; i < len; i++)
+   crc = _crc8((crc ^ vptr[i]) << 8);
+
+   return crc;
+}
+
+const char *phytec_get_opt(const struct phytec_eeprom_data *data)
+{
+   const char *opt;
+
+   if (!data)
+   data = &eeprom_data;
+
+   switch (data->api_rev) {
+   case PHYTEC_API_REV0:
+   case PHYTEC_API_REV1:
+   opt = data->data.data_api0.opt;
+   break;
+   case PHYTEC_API_REV2:
+   opt = data->data.data_api2.opt;
+   break;
+   default:
+   opt = NULL;
+   break;
+   };
+
+   return opt;
+}
+
+static int phytec_eeprom_data_init(struct pbl_i2c *i2c,
+  struct phytec_eeprom_data *data,
+  int addr, u8 phytec_som_type)
+{
+   unsigned int crc;
+   const char *opt;
+   int *ptr;
+   int ret = -1, i;
+   u8 som;
+
+   if (!data)
+   data = &eeprom_data;
+
+   eeprom_read(i2c, addr, I2C_ADDR_16_BIT, data, sizeof(struct 
phytec_eeprom_data));
+
+   if (data->api_rev == 0xff) {
+   pr_err("%s: EEPROM is not flashed. Prototype?\n", __func__);
+   return -EINVAL;
+   }
+
+   for (i = 0, ptr = (int *)data;
+i < sizeof(struct phytec_eeprom_data);
+i += sizeof(ptr), ptr++)
+   if (*ptr != 0x0)
+   break;
+
+   if (i == sizeof(struct phytec_eeprom_data)) {
+   pr_err("%s: EEPROM data is all zero. Erased?\n", __func__);
+   return -EINVAL;
+   }
+
+   if (data->api_rev > PHYTEC_API_REV2) {
+   pr_err("%s: EEPROM API revision %u not supported\n",
+  __func__, data->api_rev);
+   return -EINVAL;
+   }
+
+   /* We are done here for early revisions */
+   if (data->api_rev <= PHYTEC_API_REV1)
+   return 0;
+
+   crc = crc8(0, (const unsigned char *)data,
+  sizeof(struct phytec_eeprom_data));
+   pr_debug("%s: crc: %x\n", __func__, crc);
+
+   if (crc) {
+   pr_err("%s: CRC mismatch. EEPROM data is not usable\n", 
__func__);
+   return -EINVAL;
+   }
+
+   som = data->data.data_api2.som_no;
+   pr_debug("%s: som id: %u\

[PATCH v2 3/3] ARM: i.MX8MM: add Phytec i.MX8 SoM support

2023-06-06 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/boards/Makefile   |1 +
 arch/arm/boards/phytec-som-imx8mm/Makefile |4 +
 arch/arm/boards/phytec-som-imx8mm/board.c  |   40 +
 .../flash-header-imx8mm-phyboard-polis-rdk.imxcfg  |7 +
 arch/arm/boards/phytec-som-imx8mm/lowlevel.c   |  130 ++
 arch/arm/boards/phytec-som-imx8mm/lowlevel.h   |8 +
 arch/arm/boards/phytec-som-imx8mm/lpddr4-timing.c  | 1852 
 arch/arm/dts/Makefile  |1 +
 arch/arm/dts/imx8mm-phyboard-polis-rdk.dts |   60 +
 arch/arm/mach-imx/Kconfig  |   48 +
 images/Makefile.imx|5 +
 11 files changed, 2156 insertions(+)

diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index 2877debad535..1222ef80feb1 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -95,6 +95,7 @@ obj-$(CONFIG_MACH_PHYTEC_SOM_AM335X)  += 
phytec-som-am335x/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX6) += phytec-som-imx6/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7) += phytec-phycore-imx7/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1) += phytec-phycore-stm32mp1/
+obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM)   += phytec-som-imx8mm/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ)   += phytec-som-imx8mq/
 obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3) += plathome-openblocks-ax3/
 obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_A6)  += plathome-openblocks-a6/
diff --git a/arch/arm/boards/phytec-som-imx8mm/Makefile 
b/arch/arm/boards/phytec-som-imx8mm/Makefile
new file mode 100644
index ..10abebc53921
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+lwl-y += lowlevel.o lpddr4-timing.o
+obj-y += board.o
diff --git a/arch/arm/boards/phytec-som-imx8mm/board.c 
b/arch/arm/boards/phytec-som-imx8mm/board.c
new file mode 100644
index ..52f821f5fa30
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/board.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: 2022 Ahmad Fatoum, Pengutronix
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int phyboard_polis_rdk_probe(struct device *dev)
+{
+   int emmc_bbu_flag = 0;
+   int sd_bbu_flag = 0;
+
+   if (bootsource_get() == BOOTSOURCE_MMC && bootsource_get_instance() == 
1) {
+   of_device_enable_path("/chosen/environment-sd");
+   sd_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+   } else {
+   of_device_enable_path("/chosen/environment-emmc");
+   emmc_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+   }
+
+   imx8m_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc2", 
emmc_bbu_flag);
+   imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", 
sd_bbu_flag);
+
+   return 0;
+}
+
+static const struct of_device_id phyboard_polis_rdk_of_match[] = {
+   { .compatible = "phytec,imx8mm-phyboard-polis-rdk" },
+   { /* sentinel */ },
+};
+BAREBOX_DEEP_PROBE_ENABLE(phyboard_polis_rdk_of_match);
+
+static struct driver phyboard_polis_rdkboard_driver = {
+   .name = "board-phyboard-polis-rdk",
+   .probe = phyboard_polis_rdk_probe,
+   .of_compatible = DRV_OF_COMPAT(phyboard_polis_rdk_of_match),
+};
+coredevice_platform_driver(phyboard_polis_rdkboard_driver);
diff --git 
a/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
 
b/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
new file mode 100644
index ..10606ce29c96
--- /dev/null
+++ 
b/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+soc imx8mm
+
+loadaddr 0x007e1000
+max_load_size 0x3f000
+ivtofs 0x400
diff --git a/arch/arm/boards/phytec-som-imx8mm/lowlevel.c 
b/arch/arm/boards/phytec-som-imx8mm/lowlevel.c
new file mode 100644
index ..d66f6f79f1c4
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/lowlevel.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lowlevel.h"
+
+extern char __dtb_z_imx8mm_phyboard_polis_rdk_start[];
+
+#define UART_PAD_CTRL MUX_PAD_CTRL(PAD_CTL_DSE_3P3V_45_OHM)
+
+static void setup_uart(void)
+{
+   void __iomem *uart = IOMEM(MX8M_UART3_BASE_ADDR);
+
+   imx8m_early_setup_uart_clock();
+
+   imx8mm_setup_pad(IMX8MM_PAD_UART3_TXD_UART3_TX | UART_PAD_CTRL);
+   imx8m_uart_setup(uart);
+
+   pbl_set_putc(imx_uart_putc, uart);
+   putc_ll('>');
+}
+
+#define EEPROM_ADDR 0x51
+#define EEPROM_ADDR_FALLBACK 0x59
+
+static

[PATCH v2 2/3] common: board: phytec: import SoM detection for imx8m based SoM from u-boot

2023-06-06 Thread Marc Kleine-Budde
This patch imports and cleans up the SoM detection for imx8m based SoM
from u-boot.

Signed-off-by: Marc Kleine-Budde 
---
 common/boards/Kconfig  |   7 +
 common/boards/Makefile |   1 +
 common/boards/phytec/Makefile  |   4 +
 common/boards/phytec/phytec-som-detection.c| 209 +
 common/boards/phytec/phytec-som-imx8m-detection.c  | 151 +++
 include/boards/phytec/phytec-som-detection.h   |  69 +++
 include/boards/phytec/phytec-som-imx8m-detection.h |  19 ++
 7 files changed, 460 insertions(+)

diff --git a/common/boards/Kconfig b/common/boards/Kconfig
index e27273b7671d..b240548b484d 100644
--- a/common/boards/Kconfig
+++ b/common/boards/Kconfig
@@ -2,3 +2,10 @@
 
 config BOARD_QEMU_VIRT
bool
+
+config BOARD_PHYTEC_SOM_DETECTION
+   bool
+
+config BOARD_PHYTEC_SOM_IMX8M_DETECTION
+   bool
+   select BOARD_PHYTEC_SOM_DETECTION
diff --git a/common/boards/Makefile b/common/boards/Makefile
index 5b4e429c13e9..2a96ce6aec5c 100644
--- a/common/boards/Makefile
+++ b/common/boards/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 obj-$(CONFIG_BOARD_QEMU_VIRT)  += qemu-virt/
+obj-y += phytec/
diff --git a/common/boards/phytec/Makefile b/common/boards/phytec/Makefile
new file mode 100644
index ..741a0e2eb704
--- /dev/null
+++ b/common/boards/phytec/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+lwl-$(CONFIG_BOARD_PHYTEC_SOM_DETECTION) += phytec-som-detection.o
+lwl-$(CONFIG_BOARD_PHYTEC_SOM_IMX8M_DETECTION) += phytec-som-imx8m-detection.o
diff --git a/common/boards/phytec/phytec-som-detection.c 
b/common/boards/phytec/phytec-som-detection.c
new file mode 100644
index ..e338639d03e9
--- /dev/null
+++ b/common/boards/phytec/phytec-som-detection.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 PHYTEC Messtechnik GmbH
+ * Author: Teresa Remmet 
+ */
+
+#include 
+#include 
+#include 
+
+struct phytec_eeprom_data eeprom_data;
+
+#define POLY (0x1070U << 3)
+
+static u8 _crc8(u16 data)
+{
+   int i;
+
+   for (i = 0; i < 8; i++) {
+   if (data & 0x8000)
+   data = data ^ POLY;
+   data = data << 1;
+   }
+
+   return data >> 8;
+}
+
+static unsigned int crc8(unsigned int crc, const u8 *vptr, int len)
+{
+   int i;
+
+   for (i = 0; i < len; i++)
+   crc = _crc8((crc ^ vptr[i]) << 8);
+
+   return crc;
+}
+
+const char *phytec_get_opt(const struct phytec_eeprom_data *data)
+{
+   const char *opt;
+
+   if (!data)
+   data = &eeprom_data;
+
+   switch (data->api_rev) {
+   case PHYTEC_API_REV0:
+   case PHYTEC_API_REV1:
+   opt = data->data.data_api0.opt;
+   break;
+   case PHYTEC_API_REV2:
+   opt = data->data.data_api2.opt;
+   break;
+   default:
+   opt = NULL;
+   break;
+   };
+
+   return opt;
+}
+
+static int phytec_eeprom_data_init(struct pbl_i2c *i2c,
+  struct phytec_eeprom_data *data,
+  int addr, u8 phytec_som_type)
+{
+   unsigned int crc;
+   const char *opt;
+   int *ptr;
+   int ret = -1, i;
+   u8 som;
+
+   if (!data)
+   data = &eeprom_data;
+
+   eeprom_read(i2c, addr, I2C_ADDR_16_BIT, data, sizeof(struct 
phytec_eeprom_data));
+
+   if (data->api_rev == 0xff) {
+   pr_err("%s: EEPROM is not flashed. Prototype?\n", __func__);
+   return -EINVAL;
+   }
+
+   for (i = 0, ptr = (int *)data;
+i < sizeof(struct phytec_eeprom_data);
+i += sizeof(ptr), ptr++)
+   if (*ptr != 0x0)
+   break;
+
+   if (i == sizeof(struct phytec_eeprom_data)) {
+   pr_err("%s: EEPROM data is all zero. Erased?\n", __func__);
+   return -EINVAL;
+   }
+
+   if (data->api_rev > PHYTEC_API_REV2) {
+   pr_err("%s: EEPROM API revision %u not supported\n",
+  __func__, data->api_rev);
+   return -EINVAL;
+   }
+
+   /* We are done here for early revisions */
+   if (data->api_rev <= PHYTEC_API_REV1)
+   return 0;
+
+   crc = crc8(0, (const unsigned char *)data,
+  sizeof(struct phytec_eeprom_data));
+   pr_debug("%s: crc: %x\n", __func__, crc);
+
+   if (crc) {
+   pr_err("%s: CRC mismatch. EEPROM data is not usable\n", 
__func__);
+   return -EINVAL;
+   }
+
+   som = data->data.data_api2.som_no;
+   pr_debug("%s: som id: %u\n", __func__, som);
+   opt = phytec_get_opt(data);
+   if (!opt)
+

[PATCH v2 0/3] ARM: i.MX8MM: add Phytec i.MX8 SoM support

2023-06-06 Thread Marc Kleine-Budde
This series adds support for the Phytec i.MX8 SoM. It a minimal i2c
EEPROM read helper for the PBL and import + adopts the Phytec SOM
detection from u-boot. The Phytec SOM detection reads and parses the
EEPROM on the SOM to figure out the size of the populated RAM.

Signed-off-by: Marc Kleine-Budde 
---
Changes in v2:
- make several pointers to "struct phytec_eeprom" const
- phytec_print_som_info(): use printf() instead of pr_cont()
- let phytec_imx8m_detect() return int instead of u8
- fix typo in phytec_get_imx8m_spi()'s comment
- rename struct phytec_api0_data::pad -> __pad
- move include/phytec-som-* to include/boards/phytec
- Link to v1: 
https://lore.barebox.org/20230606-phytec-som-imx8mm-v1-0-b9c2bf70b...@pengutronix.de

---
Marc Kleine-Budde (3):
  i2c: add  for PBL use
  common: board: phytec: import SoM detection for imx8m based SoM from 
u-boot
  ARM: i.MX8MM: add Phytec i.MX8 SoM support

 arch/arm/boards/Makefile   |1 +
 arch/arm/boards/phytec-som-imx8mm/Makefile |4 +
 arch/arm/boards/phytec-som-imx8mm/board.c  |   40 +
 .../flash-header-imx8mm-phyboard-polis-rdk.imxcfg  |7 +
 arch/arm/boards/phytec-som-imx8mm/lowlevel.c   |  130 ++
 arch/arm/boards/phytec-som-imx8mm/lowlevel.h   |8 +
 arch/arm/boards/phytec-som-imx8mm/lpddr4-timing.c  | 1852 
 arch/arm/dts/Makefile  |1 +
 arch/arm/dts/imx8mm-phyboard-polis-rdk.dts |   60 +
 arch/arm/mach-imx/Kconfig  |   48 +
 common/boards/Kconfig  |7 +
 common/boards/Makefile |1 +
 common/boards/phytec/Makefile  |4 +
 common/boards/phytec/phytec-som-detection.c|  209 +++
 common/boards/phytec/phytec-som-imx8m-detection.c  |  151 ++
 images/Makefile.imx|5 +
 include/boards/phytec/phytec-som-detection.h   |   69 +
 include/boards/phytec/phytec-som-imx8m-detection.h |   19 +
 include/pbl/eeprom.h   |   34 +
 19 files changed, 2650 insertions(+)
---
base-commit: d95b1da1ac49476565382e40bbeb56cd5ad29f4d
change-id: 20230606-phytec-som-imx8mm-2c90276fb58c

Best regards,
-- 
Marc Kleine-Budde 





[PATCH v2 1/3] i2c: add for PBL use

2023-06-06 Thread Marc Kleine-Budde
Add a small helper to read a single page of EEPROM data.

Signed-off-by: Marc Kleine-Budde 
---
 include/pbl/eeprom.h | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/include/pbl/eeprom.h b/include/pbl/eeprom.h
new file mode 100644
index ..df868b1a37fb
--- /dev/null
+++ b/include/pbl/eeprom.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PBL_EEPROM_H_
+#define __PBL_EEPROM_H_
+
+#include 
+#include 
+
+static inline void eeprom_read(struct pbl_i2c *i2c, u16 client_addr, u32 addr, 
void *buf, u16 count)
+{
+   u8 msgbuf[2];
+   struct i2c_msg msg[] = {
+   {
+   .addr = client_addr,
+   .buf = msgbuf,
+   }, {
+   .addr = client_addr,
+   .flags = I2C_M_RD,
+   .buf = buf,
+   .len = count,
+   },
+   };
+   int ret, i = 0;
+
+   if (addr & I2C_ADDR_16_BIT)
+   msgbuf[i++] = addr >> 8;
+   msgbuf[i++] = addr;
+   msg[0].len = i;
+
+   ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
+   if (ret != ARRAY_SIZE(msg))
+   pr_err("Failed to read from eeprom@%x: %d\n", client_addr, ret);
+}
+
+#endif

-- 
2.39.2





Re: [PATCH 2/3] common: board: phytec: import SoM detection for imx8m based SoM from u-boot

2023-06-06 Thread Marc Kleine-Budde
On 06.06.2023 14:51:05, Ahmad Fatoum wrote:
> On 06.06.23 12:50, Marc Kleine-Budde wrote:
> > This patch imports and cleans up the SoM detection for imx8n based SoM
> > from u-boot.
> > 
> > Signed-off-by: Marc Kleine-Budde 
> > ---
> >  common/boards/Kconfig |   7 +
> >  common/boards/Makefile|   1 +
> >  common/boards/phytec/Makefile |   4 +
> >  common/boards/phytec/phytec-som-detection.c   | 209 
> > ++
> >  common/boards/phytec/phytec-som-imx8m-detection.c | 151 
> >  include/phytec-som-detection.h|  69 +++
> >  include/phytec-som-imx8m-detection.h  |  19 ++
> >  7 files changed, 460 insertions(+)
> > 
> > diff --git a/common/boards/Kconfig b/common/boards/Kconfig
> > index e27273b7671d..b240548b484d 100644
> > --- a/common/boards/Kconfig
> > +++ b/common/boards/Kconfig
> > @@ -2,3 +2,10 @@
> >  
> >  config BOARD_QEMU_VIRT
> > bool
> > +
> > +config BOARD_PHYTEC_SOM_DETECTION
> > +   bool
> > +
> > +config BOARD_PHYTEC_SOM_IMX8M_DETECTION
> > +   bool
> > +   select BOARD_PHYTEC_SOM_DETECTION
> > diff --git a/common/boards/Makefile b/common/boards/Makefile
> > index 5b4e429c13e9..2a96ce6aec5c 100644
> > --- a/common/boards/Makefile
> > +++ b/common/boards/Makefile
> > @@ -1,3 +1,4 @@
> >  # SPDX-License-Identifier: GPL-2.0-only
> >  
> >  obj-$(CONFIG_BOARD_QEMU_VIRT)  += qemu-virt/
> > +obj-y += phytec/
> > diff --git a/common/boards/phytec/Makefile b/common/boards/phytec/Makefile
> > new file mode 100644
> > index ..741a0e2eb704
> > --- /dev/null
> > +++ b/common/boards/phytec/Makefile
> > @@ -0,0 +1,4 @@
> > +# SPDX-License-Identifier: GPL-2.0-only
> > +
> > +lwl-$(CONFIG_BOARD_PHYTEC_SOM_DETECTION) += phytec-som-detection.o
> > +lwl-$(CONFIG_BOARD_PHYTEC_SOM_IMX8M_DETECTION) += 
> > phytec-som-imx8m-detection.o
> > diff --git a/common/boards/phytec/phytec-som-detection.c 
> > b/common/boards/phytec/phytec-som-detection.c
> > new file mode 100644
> > index ..d9479f8ced69
> > --- /dev/null
> > +++ b/common/boards/phytec/phytec-som-detection.c
> > @@ -0,0 +1,209 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2020 PHYTEC Messtechnik GmbH
> > + * Author: Teresa Remmet 
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +struct phytec_eeprom_data eeprom_data;
> > +
> > +#define POLY (0x1070U << 3)
> > +
> > +static u8 _crc8(u16 data)
> > +{
> > +   int i;
> > +
> > +   for (i = 0; i < 8; i++) {
> > +   if (data & 0x8000)
> > +   data = data ^ POLY;
> > +   data = data << 1;
> > +   }
> > +
> > +   return data >> 8;
> > +}
> > +
> > +static unsigned int crc8(unsigned int crc, const u8 *vptr, int len)
> > +{
> > +   int i;
> > +
> > +   for (i = 0; i < len; i++)
> > +   crc = _crc8((crc ^ vptr[i]) << 8);
> > +
> > +   return crc;
> > +}
> 
> There's already a crc8 implementation. Why can't you reuse it?

It's a lookup table based approach and not pbl ready.

> > +
> > +char *phytec_get_opt(struct phytec_eeprom_data *data)
> 
> const return and const argument?

fixed

> > +{
> > +   char *opt;
> > +
> > +   if (!data)
> > +   data = &eeprom_data;
> > +
> > +   switch (data->api_rev) {
> > +   case PHYTEC_API_REV0:
> > +   case PHYTEC_API_REV1:
> > +   opt = data->data.data_api0.opt;
> > +   break;
> > +   case PHYTEC_API_REV2:
> > +   opt = data->data.data_api2.opt;
> > +   break;
> > +   default:
> > +   opt = NULL;
> > +   break;
> > +   };
> > +
> > +   return opt;
> > +}
> > +
> > +static int phytec_eeprom_data_init(struct pbl_i2c *i2c,
> > +  struct phytec_eeprom_data *data,
> > +  int addr, u8 phytec_som_type)
> > +{
> > +   unsigned int crc;
> > +   char *opt;
> > +   int *ptr;
> > +   int ret = -1, i;
> > +   u8 som;
> > +
> > +   if (!data)
> > +   data = &eeprom_data;
> > +
> > +   eeprom_read(i2c, addr, I2C_ADDR_16_BIT, data, sizeof(struct 
> > ph

Re: [PATCH 1/3] i2c: add for PBL use

2023-06-06 Thread Marc Kleine-Budde
On 06.06.2023 13:21:48, Sascha Hauer wrote:
> On Tue, Jun 06, 2023 at 12:50:02PM +0200, Marc Kleine-Budde wrote:
> > Add a small helper to read a single page of EEPROM data.
> > 
> > Signed-off-by: Marc Kleine-Budde 
> > ---
> >  include/pbl/eeprom.h | 34 ++
> >  1 file changed, 34 insertions(+)
> > 
> > diff --git a/include/pbl/eeprom.h b/include/pbl/eeprom.h
> > new file mode 100644
> > index ..b713cf154c99
> > --- /dev/null
> > +++ b/include/pbl/eeprom.h
> > @@ -0,0 +1,34 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef __PBL_EEPROM_H_
> > +#define __PBL_EEPROM_H_
> > +
> > +#include 
> > +#include 
> > +
> > +static inline void eeprom_read(struct pbl_i2c *i2c, u16 client_addr, u32 
> > addr, void *buf, u16 count)
> > +{
> > +   u8 msgbuf[2];
> > +   struct i2c_msg msg[] = {
> > +   {
> > +   .addr = client_addr,
> > +   .buf = msgbuf,
> > +   }, {
> > +   .addr = client_addr,
> > +   .flags = I2C_M_RD,
> > +   .buf = buf,
> > +   .len = count,
> > +   },
> > +   };
> > +   int ret, i = 0;
> > +
> > +   if (addr & I2C_ADDR_16_BIT)
> > +   msgbuf[i++] = addr >> 8;
> > +   msgbuf[i++] = addr;
> > +   msg->len = i;
> 
> I wasn't aware that an array can be accessed as a pointer.

It's C, that's all just syntactic sugar :)

> I would prefer msg[0].len = i here.

That's copied from i2c_read_reg(), will change, though.

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde  |
Embedded Linux   | https://www.pengutronix.de |
Vertretung Nürnberg  | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |


signature.asc
Description: PGP signature


[PATCH 3/3] ARM: i.MX8MM: add Phytec i.MX8 SoM support

2023-06-06 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/boards/Makefile   |1 +
 arch/arm/boards/phytec-som-imx8mm/Makefile |4 +
 arch/arm/boards/phytec-som-imx8mm/board.c  |   40 +
 .../flash-header-imx8mm-phyboard-polis-rdk.imxcfg  |7 +
 arch/arm/boards/phytec-som-imx8mm/lowlevel.c   |  130 ++
 arch/arm/boards/phytec-som-imx8mm/lowlevel.h   |8 +
 arch/arm/boards/phytec-som-imx8mm/lpddr4-timing.c  | 1852 
 arch/arm/dts/Makefile  |1 +
 arch/arm/dts/imx8mm-phyboard-polis-rdk.dts |   60 +
 arch/arm/mach-imx/Kconfig  |   48 +
 images/Makefile.imx|5 +
 11 files changed, 2156 insertions(+)

diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index 2877debad535..1222ef80feb1 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -95,6 +95,7 @@ obj-$(CONFIG_MACH_PHYTEC_SOM_AM335X)  += 
phytec-som-am335x/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX6) += phytec-som-imx6/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7) += phytec-phycore-imx7/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1) += phytec-phycore-stm32mp1/
+obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM)   += phytec-som-imx8mm/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ)   += phytec-som-imx8mq/
 obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3) += plathome-openblocks-ax3/
 obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_A6)  += plathome-openblocks-a6/
diff --git a/arch/arm/boards/phytec-som-imx8mm/Makefile 
b/arch/arm/boards/phytec-som-imx8mm/Makefile
new file mode 100644
index ..10abebc53921
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+lwl-y += lowlevel.o lpddr4-timing.o
+obj-y += board.o
diff --git a/arch/arm/boards/phytec-som-imx8mm/board.c 
b/arch/arm/boards/phytec-som-imx8mm/board.c
new file mode 100644
index ..52f821f5fa30
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/board.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: 2022 Ahmad Fatoum, Pengutronix
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int phyboard_polis_rdk_probe(struct device *dev)
+{
+   int emmc_bbu_flag = 0;
+   int sd_bbu_flag = 0;
+
+   if (bootsource_get() == BOOTSOURCE_MMC && bootsource_get_instance() == 
1) {
+   of_device_enable_path("/chosen/environment-sd");
+   sd_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+   } else {
+   of_device_enable_path("/chosen/environment-emmc");
+   emmc_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
+   }
+
+   imx8m_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc2", 
emmc_bbu_flag);
+   imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", 
sd_bbu_flag);
+
+   return 0;
+}
+
+static const struct of_device_id phyboard_polis_rdk_of_match[] = {
+   { .compatible = "phytec,imx8mm-phyboard-polis-rdk" },
+   { /* sentinel */ },
+};
+BAREBOX_DEEP_PROBE_ENABLE(phyboard_polis_rdk_of_match);
+
+static struct driver phyboard_polis_rdkboard_driver = {
+   .name = "board-phyboard-polis-rdk",
+   .probe = phyboard_polis_rdk_probe,
+   .of_compatible = DRV_OF_COMPAT(phyboard_polis_rdk_of_match),
+};
+coredevice_platform_driver(phyboard_polis_rdkboard_driver);
diff --git 
a/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
 
b/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
new file mode 100644
index ..10606ce29c96
--- /dev/null
+++ 
b/arch/arm/boards/phytec-som-imx8mm/flash-header-imx8mm-phyboard-polis-rdk.imxcfg
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+soc imx8mm
+
+loadaddr 0x007e1000
+max_load_size 0x3f000
+ivtofs 0x400
diff --git a/arch/arm/boards/phytec-som-imx8mm/lowlevel.c 
b/arch/arm/boards/phytec-som-imx8mm/lowlevel.c
new file mode 100644
index ..def49fd49493
--- /dev/null
+++ b/arch/arm/boards/phytec-som-imx8mm/lowlevel.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lowlevel.h"
+
+extern char __dtb_z_imx8mm_phyboard_polis_rdk_start[];
+
+#define UART_PAD_CTRL MUX_PAD_CTRL(PAD_CTL_DSE_3P3V_45_OHM)
+
+static void setup_uart(void)
+{
+   void __iomem *uart = IOMEM(MX8M_UART3_BASE_ADDR);
+
+   imx8m_early_setup_uart_clock();
+
+   imx8mm_setup_pad(IMX8MM_PAD_UART3_TXD_UART3_TX | UART_PAD_CTRL);
+   imx8m_uart_setup(uart);
+
+   pbl_set_putc(imx_uart_putc, uart);
+   putc_ll('>');
+}
+
+#define EEPROM_ADDR 0x51
+#define EEPROM_ADDR_FALLBACK 0x59
+
+static

[PATCH 2/3] common: board: phytec: import SoM detection for imx8m based SoM from u-boot

2023-06-06 Thread Marc Kleine-Budde
This patch imports and cleans up the SoM detection for imx8n based SoM
from u-boot.

Signed-off-by: Marc Kleine-Budde 
---
 common/boards/Kconfig |   7 +
 common/boards/Makefile|   1 +
 common/boards/phytec/Makefile |   4 +
 common/boards/phytec/phytec-som-detection.c   | 209 ++
 common/boards/phytec/phytec-som-imx8m-detection.c | 151 
 include/phytec-som-detection.h|  69 +++
 include/phytec-som-imx8m-detection.h  |  19 ++
 7 files changed, 460 insertions(+)

diff --git a/common/boards/Kconfig b/common/boards/Kconfig
index e27273b7671d..b240548b484d 100644
--- a/common/boards/Kconfig
+++ b/common/boards/Kconfig
@@ -2,3 +2,10 @@
 
 config BOARD_QEMU_VIRT
bool
+
+config BOARD_PHYTEC_SOM_DETECTION
+   bool
+
+config BOARD_PHYTEC_SOM_IMX8M_DETECTION
+   bool
+   select BOARD_PHYTEC_SOM_DETECTION
diff --git a/common/boards/Makefile b/common/boards/Makefile
index 5b4e429c13e9..2a96ce6aec5c 100644
--- a/common/boards/Makefile
+++ b/common/boards/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 obj-$(CONFIG_BOARD_QEMU_VIRT)  += qemu-virt/
+obj-y += phytec/
diff --git a/common/boards/phytec/Makefile b/common/boards/phytec/Makefile
new file mode 100644
index ..741a0e2eb704
--- /dev/null
+++ b/common/boards/phytec/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+lwl-$(CONFIG_BOARD_PHYTEC_SOM_DETECTION) += phytec-som-detection.o
+lwl-$(CONFIG_BOARD_PHYTEC_SOM_IMX8M_DETECTION) += phytec-som-imx8m-detection.o
diff --git a/common/boards/phytec/phytec-som-detection.c 
b/common/boards/phytec/phytec-som-detection.c
new file mode 100644
index ..d9479f8ced69
--- /dev/null
+++ b/common/boards/phytec/phytec-som-detection.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 PHYTEC Messtechnik GmbH
+ * Author: Teresa Remmet 
+ */
+
+#include 
+#include 
+#include 
+
+struct phytec_eeprom_data eeprom_data;
+
+#define POLY (0x1070U << 3)
+
+static u8 _crc8(u16 data)
+{
+   int i;
+
+   for (i = 0; i < 8; i++) {
+   if (data & 0x8000)
+   data = data ^ POLY;
+   data = data << 1;
+   }
+
+   return data >> 8;
+}
+
+static unsigned int crc8(unsigned int crc, const u8 *vptr, int len)
+{
+   int i;
+
+   for (i = 0; i < len; i++)
+   crc = _crc8((crc ^ vptr[i]) << 8);
+
+   return crc;
+}
+
+char *phytec_get_opt(struct phytec_eeprom_data *data)
+{
+   char *opt;
+
+   if (!data)
+   data = &eeprom_data;
+
+   switch (data->api_rev) {
+   case PHYTEC_API_REV0:
+   case PHYTEC_API_REV1:
+   opt = data->data.data_api0.opt;
+   break;
+   case PHYTEC_API_REV2:
+   opt = data->data.data_api2.opt;
+   break;
+   default:
+   opt = NULL;
+   break;
+   };
+
+   return opt;
+}
+
+static int phytec_eeprom_data_init(struct pbl_i2c *i2c,
+  struct phytec_eeprom_data *data,
+  int addr, u8 phytec_som_type)
+{
+   unsigned int crc;
+   char *opt;
+   int *ptr;
+   int ret = -1, i;
+   u8 som;
+
+   if (!data)
+   data = &eeprom_data;
+
+   eeprom_read(i2c, addr, I2C_ADDR_16_BIT, data, sizeof(struct 
phytec_eeprom_data));
+
+   if (data->api_rev == 0xff) {
+   pr_err("%s: EEPROM is not flashed. Prototype?\n", __func__);
+   return -EINVAL;
+   }
+
+   for (i = 0, ptr = (int *)data;
+i < sizeof(struct phytec_eeprom_data);
+i += sizeof(ptr), ptr++)
+   if (*ptr != 0x0)
+   break;
+
+   if (i == sizeof(struct phytec_eeprom_data)) {
+   pr_err("%s: EEPROM data is all zero. Erased?\n", __func__);
+   return -EINVAL;
+   }
+
+   if (data->api_rev > PHYTEC_API_REV2) {
+   pr_err("%s: EEPROM API revision %u not supported\n",
+  __func__, data->api_rev);
+   return -EINVAL;
+   }
+
+   /* We are done here for early revisions */
+   if (data->api_rev <= PHYTEC_API_REV1)
+   return 0;
+
+   crc = crc8(0, (const unsigned char *)data,
+  sizeof(struct phytec_eeprom_data));
+   pr_debug("%s: crc: %x\n", __func__, crc);
+
+   if (crc) {
+   pr_err("%s: CRC mismatch. EEPROM data is not usable\n", 
__func__);
+   return -EINVAL;
+   }
+
+   som = data->data.data_api2.som_no;
+   pr_debug("%s: som id: %u\n", __func__, som);
+   opt = phytec_get_opt(data);
+   if (!opt)
+   return -EINVAL;

[PATCH 1/3] i2c: add for PBL use

2023-06-06 Thread Marc Kleine-Budde
Add a small helper to read a single page of EEPROM data.

Signed-off-by: Marc Kleine-Budde 
---
 include/pbl/eeprom.h | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/include/pbl/eeprom.h b/include/pbl/eeprom.h
new file mode 100644
index ..b713cf154c99
--- /dev/null
+++ b/include/pbl/eeprom.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PBL_EEPROM_H_
+#define __PBL_EEPROM_H_
+
+#include 
+#include 
+
+static inline void eeprom_read(struct pbl_i2c *i2c, u16 client_addr, u32 addr, 
void *buf, u16 count)
+{
+   u8 msgbuf[2];
+   struct i2c_msg msg[] = {
+   {
+   .addr = client_addr,
+   .buf = msgbuf,
+   }, {
+   .addr = client_addr,
+   .flags = I2C_M_RD,
+   .buf = buf,
+   .len = count,
+   },
+   };
+   int ret, i = 0;
+
+   if (addr & I2C_ADDR_16_BIT)
+   msgbuf[i++] = addr >> 8;
+   msgbuf[i++] = addr;
+   msg->len = i;
+
+   ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
+   if (ret != ARRAY_SIZE(msg))
+   pr_err("Failed to read from eeprom@%x: %d\n", client_addr, ret);
+}
+
+#endif

-- 
2.39.2





[PATCH 0/3] ARM: i.MX8MM: add Phytec i.MX8 SoM support

2023-06-06 Thread Marc Kleine-Budde
This series adds support for the Phytec i.MX8 SoM. It a minimal i2c
EEPROM read helper for the PBL and import + adopts the Phytec SOM
detection from u-boot. The Phytec SOM detection reads and parses the
EEPROM on the SOM to figure out the size of the populated RAM.

Signed-off-by: Marc Kleine-Budde 
---
Marc Kleine-Budde (3):
  i2c: add  for PBL use
  common: board: phytec: import SoM detection for imx8m based SoM from 
u-boot
  ARM: i.MX8MM: add Phytec i.MX8 SoM support

 arch/arm/boards/Makefile   |1 +
 arch/arm/boards/phytec-som-imx8mm/Makefile |4 +
 arch/arm/boards/phytec-som-imx8mm/board.c  |   40 +
 .../flash-header-imx8mm-phyboard-polis-rdk.imxcfg  |7 +
 arch/arm/boards/phytec-som-imx8mm/lowlevel.c   |  130 ++
 arch/arm/boards/phytec-som-imx8mm/lowlevel.h   |8 +
 arch/arm/boards/phytec-som-imx8mm/lpddr4-timing.c  | 1852 
 arch/arm/dts/Makefile  |1 +
 arch/arm/dts/imx8mm-phyboard-polis-rdk.dts |   60 +
 arch/arm/mach-imx/Kconfig  |   48 +
 common/boards/Kconfig  |7 +
 common/boards/Makefile |1 +
 common/boards/phytec/Makefile  |4 +
 common/boards/phytec/phytec-som-detection.c|  209 +++
 common/boards/phytec/phytec-som-imx8m-detection.c  |  151 ++
 images/Makefile.imx|5 +
 include/pbl/eeprom.h   |   34 +
 include/phytec-som-detection.h |   69 +
 include/phytec-som-imx8m-detection.h   |   19 +
 19 files changed, 2650 insertions(+)
---
base-commit: e7a35fb8e6f74d03fc8bed997c025d0eee2b88e0
change-id: 20230606-phytec-som-imx8mm-2c90276fb58c

Best regards,
-- 
Marc Kleine-Budde 





[PATCH] ARM: dts: InnoComm: fix node address of environment partitions

2023-06-02 Thread Marc Kleine-Budde
Fixes: e190e932b918 ("ARM: i.MX8MM: add InnoComm WB15 support")
Cc: Ahmad Fatoum 
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/dts/imx8mm-innocomm-wb15-evk.dts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/imx8mm-innocomm-wb15-evk.dts 
b/arch/arm/dts/imx8mm-innocomm-wb15-evk.dts
index 8808441b6094..907d9c96baa6 100644
--- a/arch/arm/dts/imx8mm-innocomm-wb15-evk.dts
+++ b/arch/arm/dts/imx8mm-innocomm-wb15-evk.dts
@@ -34,7 +34,7 @@ partition@0 {
reg = <0x0 0x0 0x0 0x10>;
};
 
-   env_sd1: partition@e {
+   env_sd1: partition@10 {
label = "barebox-environment";
reg = <0x0 0x10 0x0 0x10>;
};
@@ -52,7 +52,7 @@ partition@0 {
reg = <0x0 0x0 0x0 0x10>;
};
 
-   env_sd2: partition@e {
+   env_sd2: partition@10 {
label = "barebox-environment";
reg = <0x0 0x10 0x0 0x10>;
};
-- 
2.39.2





[PATCH 0/3] non-critical fixes

2023-05-23 Thread Marc Kleine-Budde
Hello,

here are some non critical fixes on top of v2023.05.0.

regards,
Marc





[PATCH 1/3] ARM: i.MX8MM: InnoComm: fix base address for I2C1

2023-05-23 Thread Marc Kleine-Budde
Replace i.MX8MQ with i.MX8MM define.

Cc: Ahmad Fatoum 
Fixes: e190e932b918 ("ARM: i.MX8MM: add InnoComm WB15 support")
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c 
b/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c
index 2f6061f0e263..8fd367047c7d 100644
--- a/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c
+++ b/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c
@@ -67,7 +67,7 @@ void innocomm_wb15_power_init_board(void)
imx8mm_early_clock_init();
imx8m_ccgr_clock_enable(IMX8M_CCM_CCGR_I2C1);
 
-   i2c = imx8m_i2c_early_init(IOMEM(MX8MQ_I2C1_BASE_ADDR));
+   i2c = imx8m_i2c_early_init(IOMEM(MX8MM_I2C1_BASE_ADDR));
 
pmic_configure(i2c, 0x4b, bd71837_cfg, ARRAY_SIZE(bd71837_cfg));
 }
-- 
2.39.2




[PATCH 3/3] I2C: i.MX: fix guard macro comment

2023-05-23 Thread Marc Kleine-Budde
Cc: Ahmad Fatoum 
Fixes: dbbe6037f5ca ("pbl: generalize fsl i2c_early API into pbl_i2c")
Signed-off-by: Marc Kleine-Budde 
---
 include/pbl/i2c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/pbl/i2c.h b/include/pbl/i2c.h
index 32e456d46b6d..ea2ae447a39f 100644
--- a/include/pbl/i2c.h
+++ b/include/pbl/i2c.h
@@ -35,4 +35,4 @@ static inline int i2c_dev_probe(struct pbl_i2c *i2c, int 
addr, bool onebyte)
 }
 
 
-#endif /* __I2C_EARLY_H */
+#endif /* __PBL_I2C_H */
-- 
2.39.2




[PATCH 2/3] ddr: imx: fix indention of debug message

2023-05-23 Thread Marc Kleine-Budde
Fixes: 2ccc6a0946d7 ("ddr: imx: Cleanup debug messages")
Signed-off-by: Marc Kleine-Budde 
---
 drivers/ddr/imx8m/ddr_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ddr/imx8m/ddr_init.c b/drivers/ddr/imx8m/ddr_init.c
index 164536800615..944cc3873e0c 100644
--- a/drivers/ddr/imx8m/ddr_init.c
+++ b/drivers/ddr/imx8m/ddr_init.c
@@ -204,7 +204,7 @@ int imx8m_ddr_init(struct dram_timing_info *dram_timing,
 
/* enable port 0 */
reg32_write(DDRC_PCTRL_0(0), 0x0001);
-   pr_debug(" ddrmix config done\n");
+   pr_debug("ddrmix config done\n");
 
/* save the dram timing config into memory */
dram_config_save(dram_timing, IMX8M_SAVED_DRAM_TIMING_BASE);
-- 
2.39.2




Re: [PATCH] arch: arm: mach-imx: document field return in CSF template

2022-02-25 Thread Marc Kleine-Budde
On 25.02.2022 11:46:04, Bastian Krause wrote:
> On 2/25/22 11:25, Marc Kleine-Budde wrote:
> > On 25.02.2022 11:03:44, Bastian Krause wrote:
> > > Activating the field return configuration returns a locked-down board
> > > (nearly) to its open state. In order to burn the FIELD_RETURN fuse, the
> > > CSF must contain a specific unlock command with the device's UID.
> > > 
> > > Signed-off-by: Bastian Krause 
> > > ---
> > >   .../include/mach/habv4-imx6-gencsf-template.h| 12 
> > >   1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h 
> > > b/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h
> > > index a60b485292..45da2981cb 100644
> > > --- a/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h
> > > +++ b/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h
> > > @@ -39,6 +39,18 @@ hab Engine = SETUP_HABV4_ENGINE
> > >   hab Features = SETUP_HABV4_FEATURES
> > >   #endif
> > > +/*
> > > +// allow fusing FIELD_RETURN
> > > +// # ocotp0.permanent_write_enable=1
> > > +// # mw -l -d /dev/imx-ocotp 0xb8 0x1
> > > +hab [Unlock]
> > > +hab Engine = OCOTP
> > > +hab Features = FIELD RETURN
> > > +// device-specific UID:
> > > +// $ dd if=/sys/bus/nvmem/devices/imx-ocotp0/nvmem bs=4 skip=1 count=2 
> > > status=none | hexdump -ve '1/1 "0x%.2x, "' | sed 's/, $//'
> > > +hab UID = 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
> > 
> > You probably want to comment this all out in the template...
> 
> I don't get it, that's all inside the /* commented section */.

Doh!

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |


signature.asc
Description: PGP signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] arch: arm: mach-imx: document field return in CSF template

2022-02-25 Thread Marc Kleine-Budde
On 25.02.2022 11:03:44, Bastian Krause wrote:
> Activating the field return configuration returns a locked-down board
> (nearly) to its open state. In order to burn the FIELD_RETURN fuse, the
> CSF must contain a specific unlock command with the device's UID.
> 
> Signed-off-by: Bastian Krause 
> ---
>  .../include/mach/habv4-imx6-gencsf-template.h| 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h 
> b/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h
> index a60b485292..45da2981cb 100644
> --- a/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h
> +++ b/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf-template.h
> @@ -39,6 +39,18 @@ hab Engine = SETUP_HABV4_ENGINE
>  hab Features = SETUP_HABV4_FEATURES
>  #endif
>  
> +/*
> +// allow fusing FIELD_RETURN
> +// # ocotp0.permanent_write_enable=1
> +// # mw -l -d /dev/imx-ocotp 0xb8 0x1
> +hab [Unlock]
> +hab Engine = OCOTP
> +hab Features = FIELD RETURN
> +// device-specific UID:
> +// $ dd if=/sys/bus/nvmem/devices/imx-ocotp0/nvmem bs=4 skip=1 count=2 
> status=none | hexdump -ve '1/1 "0x%.2x, "' | sed 's/, $//'
> +hab UID = 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08

You probably want to comment this all out in the template...

> +*/
> +
>  hab [Install Key]
>  /* verification key index in key store (0, 2...4) */
>  hab Verification index = 0
> -- 
> 2.30.2
> 
>

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |


signature.asc
Description: PGP signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] habv4: habv4_get_status(): do not print HAB error event in case of known RNG self test failure

2021-07-16 Thread Marc Kleine-Budde
In commit

| 655e085e3a22 ("crypto: caam - Always do rng selftest")

the kconfig option CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_SELF_TEST was
removed, which resulted in the pr_debug() never being executed. Remove
the IS_ENABLED() to restore the original behavior, i.e. to not print
the HAB error Event if it is the known RNG self-test failure.

Fixes: 655e085e3a22 ("crypto: caam - Always do rng selftest")
Reported-by: Roland Hieber 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index c2acb81369d8..d58768fa5481 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -553,8 +553,7 @@ static int habv4_get_status(const struct habv4_rvt *rvt)
break;
 
/* suppress RNG self-test fail events if they can be handled in 
software */
-   if (IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_SELF_TEST) &&
-   is_known_rng_fail_event(data, len)) {
+   if (is_known_rng_fail_event(data, len)) {
pr_debug("RNG self-test failure detected, will run 
software self-test\n");
} else {
pr_err(" HAB Event %d \n", i);
-- 
2.30.2



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 5/7] scripts/rsatoc: relicense to allow distribution of binary linked with OpenSSL

2020-09-16 Thread Marc Kleine-Budde
On 9/15/20 10:54 PM, Uwe Kleine-König wrote:
> The GPL (both, versions 2 and 3) are incompatible with the OpenSSL license.
> According to the Free Software Foundation the copyright holders of GPL
> software have to provide an exception to allow this linkage.
> 
> This is effectively a license change and so needs confirmation by all
> copyright holders.
> 
> Cc: Sascha Hauer 
> Signed-off-by: Uwe Kleine-König 

Acked-by: Marc Kleine-Budde 

> ---
>  scripts/rsatoc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/rsatoc.c b/scripts/rsatoc.c
> index 8f2eb8fdedc9..142d71b89f9a 100644
> --- a/scripts/rsatoc.c
> +++ b/scripts/rsatoc.c
> @@ -1,4 +1,4 @@
> -// SPDX-License-Identifier: GPL-2.0+
> +// SPDX-License-Identifier: GPL-2.0+ WITH OpenSSL-exception
>  /*
>   * rsatoc - utility to convert an RSA key to a C struct
>   *
> 

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 6/7] scripts/imx-image: relicense to allow distribution of binary linked with OpenSSL

2020-09-16 Thread Marc Kleine-Budde
On 9/15/20 10:54 PM, Uwe Kleine-König wrote:
> The GPL (both, versions 2 and 3) are incompatible with the OpenSSL license.
> According to the Free Software Foundation the copyright holders of GPL
> software have to provide an exception to allow this linkage.
> 
> This is effectively a license change and so needs confirmation by all
> copyright holders.
> 
> Cc: Ahmad Fatoum 
> Cc: Alexander Kurz 
> Cc: Andrey Smirnov 
> Cc: Bastian Krause 
> Cc: Eric Bénard 
> Cc: Lucas Stach 
> Cc: Marcin Niestroj 
> Cc: Marc Kleine-Budde 

Acked-by: Marc Kleine-Budde 

> Cc: Rouven Czerwinski 
> Cc: Sascha Hauer 
> Signed-off-by: Uwe Kleine-König 
> ---
>  scripts/imx/imx-image.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
> index f5e89d07a6ee..34bbfc8d8308 100644
> --- a/scripts/imx/imx-image.c
> +++ b/scripts/imx/imx-image.c
> @@ -1,4 +1,4 @@
> -// SPDX-License-Identifier: GPL-2.0-or-later
> +// SPDX-License-Identifier: GPL-2.0-or-later WITH OpenSSL-exception
>  // SPDX-FileCopyrightText: 2013 Sascha Hauer, Pengutronix
>  
>  #define _GNU_SOURCE
> 

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] scripts/rsatoc: fix printing of error message, if environment variable doen't contain a path

2020-07-29 Thread Marc Kleine-Budde
Fixes: 128ad3cbe043 ("scripts: Add rsatoc tool")
Signed-off-by: Marc Kleine-Budde 
---
 scripts/rsatoc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/rsatoc.c b/scripts/rsatoc.c
index 647380214092..9410f33a654f 100644
--- a/scripts/rsatoc.c
+++ b/scripts/rsatoc.c
@@ -471,10 +471,12 @@ int main(int argc, char *argv[])
path++;
 
if (!strncmp(path, "__ENV__", 7)) {
-   path = getenv(path + 7);
+   const char *orig_path = path;
+   
+   path = getenv(orig_path + 7);
if (!path) {
fprintf(stderr, "%s doesn't contain a path\n",
-   path + 7);
+   orig_path + 7);
exit(1);
}
}
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/3] watchdog: Select CONFIG_PARAMETER

2020-01-23 Thread Marc Kleine-Budde
On 1/22/20 8:54 PM, Sascha Hauer wrote:
> On Wed, Jan 22, 2020 at 10:39:07AM +0100, Christian Eggers wrote:
>> Hi Sascha,
>>
>> Am Mittwoch, 22. Januar 2020, 09:21:15 CET schrieb Sascha Hauer:
>>> Hi Christian,
>>>
>>>> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
>>>> index 45dd41a2a..34b7fea39 100644
>>>> --- a/drivers/watchdog/Kconfig
>>>> +++ b/drivers/watchdog/Kconfig
>>>> @@ -4,6 +4,7 @@ config WATCHDOG_IMX_RESET_SOURCE
>>>>
>>>>  menuconfig WATCHDOG
>>>>
>>>> bool "Watchdog support"
>>>>
>>>> +   select PARAMETER
>>>
>>> I think this goes into the wrong direction. With CONFIG_PARAMETER
>>> enabled we get support for adjusting device parameters from the shell.
>>> In environments without shell support parameter support is not needed.
>>> For example the watchdog C API doesn't need parameter support and is
>>> still usable.
>>>
>>> The static inline wrappers for dev_add_param_* should return NULL
>>> instead of returning ERR_PTR(-ENOSYS).
>>
>> initially I came to the same result. But previous commits to param.h went in
>> the opposite direction:
>>
>>> 03b59bdb64 ("paramter: The dev_add_param_*() return ERR_PTR(), change
>>> no-ops") to return ERR_PTR(-ENOSYS) instead of NULL
> 
> Shouldn't have merged this one as it lacks an explanation why this has
> been done. Marc, do you have an idea what the motivation for this patch
> was?

Sorry, I don't remember

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] HABv4: remove useless error message

2019-12-03 Thread Marc Kleine-Budde
On 12/3/19 3:36 PM, Sascha Hauer wrote:
>> I think there is just one warning in the buffer:
>>
>>> HABv4: Status: Operation completed with warning (0x69)
>>> HABv4: Config: Secure IC (0xcc)
>>> HABv4: State: Trusted state (0x99)
>>> HABv4: ERROR: Recompile with larger event data buffer (at least 36 bytes)
>>
>> The barebox producing that output is missing both patches:
>>
>> 81e2b508e785 i.MX habv4: habv4_get_status(): display warning events, too
>> e7c33540d0c0 i.MX: HABv4: Reset index variable after error type
>>
>> The question is, do we know why we see this error message? I don't have
>> good feeling when we remove it, because it's annoying and we don't
>> understand why we see it.
> 
> The message is wrong because the code is wrong. Let's see:
> 
> /* Check reason for stopping */
> len = sizeof(data);
> index = 0;
> if (rvt->report_event(HAB_STATUS_ANY, index, NULL, &len) == 
> HAB_STATUS_SUCCESS)
> pr_err("ERROR: Recompile with larger event data buffer (at 
> least %d bytes)\n\n", len);
> 
> report_event() like called above will give you the first message of any
> type (HAB_STATUS_ANY) with index 0. It will do so successfully, so it
> returns HAB_STATUS_SUCCESS.
> 
> &len on entry means the length of the buffer (here sizeof(data), large
> enough). &len on exit is the length of the actual message returned. If
> &len is smaller than on entry it means the message buffer was big
> enough. If it's bigger, then we must increase the buffer size and call
> again.
> 
> The message buffer is big enough, so report_event copies the buffer
> and returns 36 bytes were copied, but we answer with "Error: Recompile
> with a larger event data buffer".

I see, this means since:

| e7c33540d0c0 i.MX: HABv4: Reset index variable after error type

the check is even more broken and fires every time we have at least one
warning and/or error.

So we can either remove the check/message with a proper commit log or
change the code to semething like:

> diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
> index e3c1de1a4dbe..013cdea1bc43 100644
> --- a/drivers/hab/habv4.c
> +++ b/drivers/hab/habv4.c
> @@ -507,7 +507,7 @@ static int habv4_get_status(const struct habv4_rvt *rvt)
>  {
> uint8_t data[256];
> uint32_t len;
> -   uint32_t index = 0;
> +   uint32_t index = 0, done = 0;
> enum hab_status status;
> enum hab_config config = 0x0;
> enum hab_state state = 0x0;
> @@ -542,6 +542,7 @@ static int habv4_get_status(const struct habv4_rvt *rvt)
>  
> len = sizeof(data);
> index++;
> +   done++;
> }
>  
> len = sizeof(data);
> @@ -553,13 +554,13 @@ static int habv4_get_status(const struct habv4_rvt *rvt)
> habv4_display_event(data, len);
> len = sizeof(data);
> index++;
> +   done++;
> }
>  
> -   /* Check reason for stopping */
> +   /* Check if we've handled every event */
> len = sizeof(data);
> -   index = 0;
> -   if (rvt->report_event(HAB_STATUS_ANY, index, NULL, &len) == 
> HAB_STATUS_SUCCESS)
> -   pr_err("ERROR: Recompile with larger event data buffer (at 
> least %d bytes)\n\n", len);
> +   if (rvt->report_event(HAB_STATUS_ANY, done, NULL, &len) == 
> HAB_STATUS_SUCCESS)
> +   pr_err("ERROR: unhandled HAB event!\n\n", len);
>  
> return -EPERM;
>  }

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] HABv4: remove useless error message

2019-12-03 Thread Marc Kleine-Budde
On 12/2/19 3:30 PM, Juergen Borleis wrote:
> Am Montag, den 02.12.2019, 14:24 +0100 schrieb Marc Kleine-Budde:
>> On 12/2/19 2:07 PM, Roland Hieber wrote:
>>> On Mon, Dec 02, 2019 at 11:24:48AM +0100, Juergen Borleis wrote:
>>>> This change removes the stupid error message at the end of the generated
>>>
>>> I think there was some reason behind that code, so it is probably not
>>> stupid, and you've run into an edge case that never happened before (at
>>> least I've never seen this on any of my boards when using HABv4).
>>
>> The last time, I've seen this messages was before implementing:
>>
>> 81e2b508e785 i.MX habv4: habv4_get_status(): display warning events, too
>>
>> So Roland is probably right, you've hit a corner case, that's not
>> correctly handled.
> 
> Hmmm:
> 
> […]
> barebox 2019.11.0-20191121-3 #1 Thu Nov 21 14:28:21 UTC 2019
> 
> Board: 
> detected i.MX6 UltraLite revision 1.2
> i.MX reset reason WDG (SRSR: 0x0010)
> i.MX6 UltraLite unique ID: 
> HABv4: Status: Operation failed (0x33)
> HABv4: Config: Non-secure IC (0xf0)
> HABv4: State: Non-secure state (0x66)
> HABv4:  HAB failure Event 0 
> HABv4: event data:
> HABv4:  db 00 08 42  33 22 0a 00
> HABv4: Status: Operation failed (0x33)
> HABv4: Reason: Invalid address: access denied (0x22)
> HABv4: Context: Logged in hab_rvt.authenticate_image() (0x0a)
> HABv4: Engine: Select first compatible engine (0x00)
> HABv4:  HAB failure Event 1 
> HABv4: event data:
> HABv4:  db 00 14 42  33 0c a0 00
> HABv4:  00 00 00 00  80 00 04 00
> HABv4:  00 00 00 20
> HABv4: Status: Operation failed (0x33)
> HABv4: Reason: Invalid assertion (0x0c)
> HABv4: Context: Event logged in hab_rvt.assert() (0xa0)
> HABv4: Engine: Select first compatible engine (0x00)
> HABv4:  HAB failure Event 2 
> HABv4: event data:
> HABv4:  db 00 14 42  33 0c a0 00
> HABv4:  00 00 00 00  80 00 04 20
> HABv4:  00 00 00 01
> HABv4: Status: Operation failed (0x33)
> HABv4: Reason: Invalid assertion (0x0c)
> HABv4: Context: Event logged in hab_rvt.assert() (0xa0)
> HABv4: Engine: Select first compatible engine (0x00)
> HABv4:  HAB failure Event 3 
> HABv4: event data:
> HABv4:  db 00 14 42  33 0c a0 00
> HABv4:  00 00 00 00  80 00 10 00
> HABv4:  00 00 00 04
> HABv4: Status: Operation failed (0x33)
> HABv4: Reason: Invalid assertion (0x0c)
> HABv4: Context: Event logged in hab_rvt.assert() (0xa0)
> HABv4: Engine: Select first compatible engine (0x00)
> HABv4: ERROR: Recompile with larger event data buffer (at least 8 bytes)
> […]
> 
> barebox 2019.11.0-20191126-1 #1 Wed Nov 27 10:19:22 UTC 2019
> 
> Board: 
> detected i.MX6 UltraLite revision 1.2
> i.MX reset reason POR (SRSR: 0x0001)
> i.MX6 UltraLite unique ID: 
> HABv4: Status: Operation failed (0x33)
> HABv4: Config: Secure IC (0xcc)
> HABv4: State: Trusted state (0x99)
> HABv4:  HAB failure Event 0 
> HABv4: event data:
> HABv4:  db 00 14 42  33 22 33 00
> HABv4:  00 00 00 55  02 1d 01 08
> HABv4:  00 00 00 04
> HABv4: Status: Operation failed (0x33)
> HABv4: Reason: Invalid address: access denied (0x22)
> HABv4: Context: Event logged in hab_rvt.check_target() (0x33)
> HABv4: Engine: Select first compatible engine (0x00)
> HABv4: ERROR: Recompile with larger event data buffer (at least 20 bytes)
> […]
> 
>>> The code goes back until the first incarnaction of HABv4 in commit
>>> 29abc10d44c2 - Marc, do you still know more details why it was done this
>>> way?
>>
>> This was part of the patches I picked up from fsl, see commit message
>> for more details:
>>
>> 29abc10d44c2 habv4: add High Assurance Boot v4
>>
>> Albeit giving an incorrect error message, it showed that there were
>> warnings events on the new mx6 silicon revisions that were not handled
>> before 81e2b508e785.
> 
> Hmm, 81e2b508e785 does not match the documented API and breaks the report. It
> was fixed by e7c33540d0c092c28b227d4b7602cef8ab203ef3 later on.
> 
> But also with e7c33540d0c092c28b227d4b7602cef8ab203ef3 the query related to 
> this
> error message was changed to index 0 as well. And now, if at least one event 
> is
> in the  buffer, this error message will always be printed. Before
> e7c33540d0c092c28b227d4b7602cef8ab203ef3 it was (most of the time) never be
> printed, because it tries once again to query an index which was already the
> cause to leave the loop before.
> And let me guess: you saw the error message, because your event buffer 
> contained
> one failure and t

Re: [PATCH 1/2] HABv4: remove useless error message

2019-12-02 Thread Marc Kleine-Budde
On 12/2/19 2:33 PM, Roland Hieber wrote:
> On Mon, Dec 02, 2019 at 02:24:54PM +0100, Marc Kleine-Budde wrote:
>> On 12/2/19 2:07 PM, Roland Hieber wrote:
>>> On Mon, Dec 02, 2019 at 11:24:48AM +0100, Juergen Borleis wrote:
>>>> This change removes the stupid error message at the end of the generated
>>>
>>> I think there was some reason behind that code, so it is probably not
>>> stupid, and you've run into an edge case that never happened before (at
>>> least I've never seen this on any of my boards when using HABv4).
>>
>> The last time, I've seen this messages was before implementing:
>>
>> 81e2b508e785 i.MX habv4: habv4_get_status(): display warning events, too
>>
>> So Roland is probably right, you've hit a corner case, that's not
>> correctly handled.
>>
>>> The code goes back until the first incarnaction of HABv4 in commit
>>> 29abc10d44c2 - Marc, do you still know more details why it was done this
>>> way?
>>
>> This was part of the patches I picked up from fsl, see commit message
>> for more details:
>>
>> 29abc10d44c2 habv4: add High Assurance Boot v4
>>
>> Albeit giving an incorrect error message, it showed that there were
>> warnings events on the new mx6 silicon revisions that were not handled
>> before 81e2b508e785.
> 
> So that means the code is no longer needed now, and Jürgens patch does
> the right thing?

If Jürgen sees this not totally correct error message, it means there's
something wrong and/or we don't understand the HAB ROM code completely.

If Jürgen doesn't see this error message, then we don't trigger an
unhandled corner case and the error message should be changed that
something went wrong.

Marc

-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] HABv4: remove useless error message

2019-12-02 Thread Marc Kleine-Budde
On 12/2/19 2:07 PM, Roland Hieber wrote:
> On Mon, Dec 02, 2019 at 11:24:48AM +0100, Juergen Borleis wrote:
>> This change removes the stupid error message at the end of the generated
> 
> I think there was some reason behind that code, so it is probably not
> stupid, and you've run into an edge case that never happened before (at
> least I've never seen this on any of my boards when using HABv4).

The last time, I've seen this messages was before implementing:

81e2b508e785 i.MX habv4: habv4_get_status(): display warning events, too

So Roland is probably right, you've hit a corner case, that's not
correctly handled.

> The code goes back until the first incarnaction of HABv4 in commit
> 29abc10d44c2 - Marc, do you still know more details why it was done this
> way?

This was part of the patches I picked up from fsl, see commit message
for more details:

29abc10d44c2 habv4: add High Assurance Boot v4

Albeit giving an incorrect error message, it showed that there were
warnings events on the new mx6 silicon revisions that were not handled
before 81e2b508e785.

Marc
-- 
Pengutronix e.K. | Marc Kleine-Budde   |
Embedded Linux   | https://www.pengutronix.de  |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917- |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] ARM: i.MX: When SRSR shows wdog then lookup reset source in wdog

2018-11-16 Thread Marc Kleine-Budde
On 11/15/18 3:15 PM, Sascha Hauer wrote:
> On i.MX6 when the watchdog has resetted the system then the SRSR
> register correctly shows that the watchdog has resetted the system.
> This is not the desired result though, a "reset" in barebox or "reboot"
> in Linux should result in "RST" as reset source. So instead of making
> the SRSR register value overwrite the reset source read from the
> watchdog registers, interpret the SRSR value corresponding to watchdog
> reset as "lookup details in the watchdog registers".
> 
> Signed-off-by: Sascha Hauer 
> Cc: Andrey Smirnov 
> ---
>  arch/arm/mach-imx/imx.c  |  6 +++---
>  drivers/watchdog/imxwd.c | 10 +++---
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
> index ad227663dd..f87dd76c75 100644
> --- a/arch/arm/mach-imx/imx.c
> +++ b/arch/arm/mach-imx/imx.c
> @@ -204,9 +204,9 @@ void imx_set_reset_reason(void __iomem *srsr,
>* sure we'll always override info from watchdog driver.
>*/

With this change, the above comment doesn't describe the reality anymore.

>   reset_source_set_priority(type,
> -   RESET_SOURCE_DEFAULT_PRIORITY + 1);
> +   RESET_SOURCE_DEFAULT_PRIORITY);
>   reset_source_set_instance(type, instance);
>  
> - pr_info("i.MX reset reason %s (SRSR: 0x%08x)\n",
> - reset_source_name(), reg);
> + pr_debug("i.MX reset reason %s (SRSR: 0x%08x)\n",
> +  reset_source_name(), reg);
>  }
> diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
> index a66fae400c..8dba662392 100644
> --- a/drivers/watchdog/imxwd.c
> +++ b/drivers/watchdog/imxwd.c
> @@ -162,19 +162,23 @@ static void __noreturn imxwd_force_soc_reset(struct 
> restart_handler *rst)
>  static void imx_watchdog_detect_reset_source(struct imx_wd *priv)
>  {
>   u16 val = readw(priv->base + IMX21_WDOG_WSTR);
> + int priority = RESET_SOURCE_DEFAULT_PRIORITY;
> +
> + if (reset_source_get() == RESET_WDG)
> + priority++;
>  
>   if (val & WSTR_COLDSTART) {
> - reset_source_set(RESET_POR);
> + reset_source_set_priority(RESET_POR, priority);
>   return;
>   }
>  
>   if (val & (WSTR_HARDRESET | WSTR_WARMSTART)) {
> - reset_source_set(RESET_RST);
> + reset_source_set_priority(RESET_RST, priority);
>   return;
>   }
>  
>   if (val & WSTR_WDOG) {
> - reset_source_set(RESET_WDG);
> + reset_source_set_priority(RESET_WDG, priority);
>   return;
>   }
>  
> 

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] mtd: nand: fix nand_lock/unlock() function

2018-11-15 Thread Marc Kleine-Budde
On 11/15/18 9:02 AM, Sascha Hauer wrote:
> On Wed, Nov 14, 2018 at 12:04:27PM +0100, Marc Kleine-Budde wrote:
>> From: White Ding 
>>
>> Do nand reset before write protect check.
>>
>> If we want to check the WP# low or high through STATUS READ and check bit 7,
>> we must reset the device, other operation (eg.erase/program a locked block) 
>> can
>> also clear the bit 7 of status register.
>>
>> As we know the status register can be refreshed, if we do some operation to 
>> trigger it,
>> for example if we do erase/program operation to one block that is locked, 
>> then READ STATUS,
>> the bit 7 of READ STATUS will be 0 indicate the device in write protect, 
>> then if we do
>> erase/program operation to another block that is unlocked, the bit 7 of READ 
>> STATUS will
>> be 1 indicate the device is not write protect.
>> Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low 
>> (write protect),
>> but in this case the WP# maybe high if we do erase/program operation to a 
>> locked block,
>> so we must reset the device if we want to check the WP# low or high through 
>> STATUS READ and
>> check bit 7.
> 
> Have you observed a failure this patch fixes or what is your motivation
> to send this patch?

A $CUSTOMER send me in private a fix needed for the micron NAND chip
found his Phytec board or a board they derived from it. I noticed that
the fix is in mainline Linux, too and I decided to cherry pick it into
barebox.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] mtd: nand: fix nand_lock/unlock() function

2018-11-14 Thread Marc Kleine-Budde
From: White Ding 

Do nand reset before write protect check.

If we want to check the WP# low or high through STATUS READ and check bit 7,
we must reset the device, other operation (eg.erase/program a locked block) can
also clear the bit 7 of status register.

As we know the status register can be refreshed, if we do some operation to 
trigger it,
for example if we do erase/program operation to one block that is locked, then 
READ STATUS,
the bit 7 of READ STATUS will be 0 indicate the device in write protect, then 
if we do
erase/program operation to another block that is unlocked, the bit 7 of READ 
STATUS will
be 1 indicate the device is not write protect.
Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low 
(write protect),
but in this case the WP# maybe high if we do erase/program operation to a 
locked block,
so we must reset the device if we want to check the WP# low or high through 
STATUS READ and
check bit 7.

Signed-off-by: White Ding 
Signed-off-by: Brian Norris 
[Cherry-picked from linux: 57d3a9a89a06 mtd: nand: fix nand_lock/unlock() 
function]
Signed-off-by: Marc Kleine-Budde 
---
 drivers/mtd/nand/nand_base.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ccf96150429a..128802fa5c20 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -852,6 +852,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t 
len)
 
chip->select_chip(mtd, chipnr);
 
+   /*
+* Reset the chip.
+* If we want to check the WP through READ STATUS and check the bit 7
+* we must reset the chip
+* some operation can also clear the bit 7 of status register
+* eg. erase/program a locked block
+*/
+   chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+
/* Check, if it is write protected */
if (nand_check_wp(mtd)) {
pr_debug("%s: device is write protected!\n",
@@ -902,6 +911,15 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t 
len)
 
chip->select_chip(mtd, chipnr);
 
+   /*
+* Reset the chip.
+* If we want to check the WP through READ STATUS and check the bit 7
+* we must reset the chip
+* some operation can also clear the bit 7 of status register
+* eg. erase/program a locked block
+*/
+   chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+
/* Check, if it is write protected */
if (nand_check_wp(mtd)) {
pr_debug("%s: device is write protected!\n",
-- 
2.19.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] scripts: imx-usb-loader: list_imx_device_types(): move variable declaration out of for() loop

2018-10-26 Thread Marc Kleine-Budde
On older compilers this causes the following error:
| scripts/imx/imx-usb-loader.c: In function 'list_imx_device_types':
| scripts/imx/imx-usb-loader.c:252:2: error: 'for' loop initial declarations 
are only allowed in C99 mode
|   for (int i = 0; i < ARRAY_SIZE(imx_ids); i++) {
|   ^
| scripts/imx/imx-usb-loader.c:252:2: note: use option -std=c99 or -std=gnu99 
to compile your code

Fixes: bcc2df673cdb ("scripts: imx-usb-loader: allow use of unknown USB IDs")
Reported-by: Niklas Reisser 
Signed-off-by: Marc Kleine-Budde 
---
 scripts/imx/imx-usb-loader.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 4336bc8d532d..d4fba0ce54e8 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -249,7 +249,9 @@ static const struct mach_id *imx_device_by_type(const char 
*name)
 
 static void list_imx_device_types(void)
 {
-   for (int i = 0; i < ARRAY_SIZE(imx_ids); i++) {
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(imx_ids); i++) {
printf("%s\n", imx_ids[i].name);
}
 }
-- 
2.19.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2] hab: Print events on info command.

2018-10-15 Thread Marc Kleine-Budde
On 10/15/2018 10:41 AM, Denis OSTERLAND wrote:
>> The faulting zero page problem doesn't occur on mx25 and mx28 as the HAB
>> ROM doesn't live at 0x0:
>>
>> #define HABV4_RVT_IMX28 0x8af8
>>
>> int imx25_hab_get_status(void)
>> {
>> return imx_habv3_get_status(readl(IOMEM(0x780018d4)));
>> }
>>  
>> Marc
>>
> 
> Thanks for the info.
> This becomes a problem when MMU is enabled again.

I think we have a 1-to-1 mapping by default, modulo the zero page.

> I think this will require explicit mapping.
> I am not sure if it is possible to access the ABI through mapped addresses.

Probably not, I assume the code is not position independent.

> Is it possible to force mapping at exact this addresses?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2] hab: Print events on info command.

2018-10-11 Thread Marc Kleine-Budde
On 10/10/2018 09:51 AM, Sascha Hauer wrote:
>> +static inline int hab_get_status(void)
>> +{
>> +if (IS_ENABLED(CONFIG_MMU))
>> +return -EIO;
> 
> This restriction makes this patch rather unhandy to use. Internally we
> use imx*_hab_get_status() indeed with MMU enabled and it works fine, but
> we call it before mmu_init is called. In this state the MMU is enabled
> already, but the zero page is not yet set to faulting. So I think the
> problem is not the MMU as such, but instead the faulting zero page.

BTW:

The faulting zero page problem doesn't occur on mx25 and mx28 as the HAB
ROM doesn't live at 0x0:

#define HABV4_RVT_IMX28 0x8af8

int imx25_hab_get_status(void)
{
return imx_habv3_get_status(readl(IOMEM(0x780018d4)));
}

> It would be great if we could overcome this issue. One way to do this
> would be to add a function pair mmu_zero_page_map() and
> mmu_zero_page_set_faulting() to be called in hab_get_status().
> 
> I don't know if you are willing to add that, but I don't want to
> motivate people to disable the MMU, so the patch is not acceptable as
> is.
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2] scripts imx-image: add support for newer versions of "cst"

2018-09-03 Thread Marc Kleine-Budde
Older versions of "cst" want to read the CSF from STDIN, while newer versions
want to read the CSF from a file. Sadly, the "-i" option doesn't understand
"-i -" to read from STDIN, so we give it "/dev/stdin" instead.

Signed-off-by: Marc Kleine-Budde 
---
 scripts/imx/imx-image.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index b241e8c4b68e..ffde8149650f 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -546,7 +546,28 @@ static int hab_sign(struct config_data *data)
}
}
 
-   ret = asprintf(&command, "%s -o %s", cst, csffile);
+   /*
+* Older versions of "cst" want to read the CSF from STDIN,
+* while newer versions want to read the CSF from a
+* file. Sadly, the "-i" option doesn't understand "-i -" to
+* read from STDIN, so we give it "/dev/stdin" instead.
+*/
+   ret = asprintf(&command,
+  "%s | grep 'Input CSF text filename'",
+  cst);
+   if (ret < 0)
+   return -ENOMEM;
+
+   ret = system(command);
+   free(command);
+   if (ret == -1)
+   return -EINVAL;
+   else if (ret == 0)
+   ret = asprintf(&command, "%s -o %s -i /dev/stdin",
+  cst, csffile);
+   else
+   ret = asprintf(&command, "%s -o %s;",
+  cst, csffile);
if (ret < 0)
return -ENOMEM;
 
-- 
2.18.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 5/5] scripts imx-image: add support for newer versions of "cst"

2018-08-29 Thread Marc Kleine-Budde
On 08/29/2018 09:15 AM, Sascha Hauer wrote:
> On Mon, Aug 27, 2018 at 05:14:28PM +0200, Marc Kleine-Budde wrote:
>> Older versions of "cst" want to read the CSF frm STDIN, while newer versions
>> want to read the CSF from a file. Sadly, the "-i" option doesn't understand
>> "-i -" to read from STDIN, so we give it "/dev/stdin" instead.
>>
>> Signed-off-by: Marc Kleine-Budde 
>> ---
>>  scripts/imx/imx-image.c | 16 +++-
>>  1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
>> index 452a544bc3eb..17d504586967 100644
>> --- a/scripts/imx/imx-image.c
>> +++ b/scripts/imx/imx-image.c
>> @@ -558,7 +558,21 @@ static int hab_sign(struct config_data *data)
>>  }
>>  }
>>  
>> -ret = asprintf(&command, "%s -o %s", cst, csffile);
>> +/*
>> + * Older versions of "cst" want to read the CSF frm STDIN,
>> + * while newer versions want to read the CSF from a
>> + * file. Sadly, the "-i" option doesn't understand "-i -" to
>> + * read from STDIN, so we give it "/dev/stdin" instead.
>> + */
>> +ret = asprintf(&command,
>> +   "if %s | grep 'Input CSF text filename'; then"
>> +   "%s -o %s -i /dev/stdin;"
>> +   "else"
>> +   "%s -o %s;"
>> +   "fi",
>> +   cst,
>> +   cst, csffile,
>> +   cst, csffile);
> 
> Could you separate the cst calling convention detection from the actual
> call, so effectively do the if/else in C rather than shell? That would
> give us a place to add a debug printf and say which way we actually call
> the cst tool and it will be slightly less magical when something goes
> wrong.

Makes sense. Do the "cst | grep" in one shell and evaluate the return
value, do the if else in C and then do the proper shell call?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/5] i.MX habv4: convert habv4_get_status() and habv4_display_event() from printf to pr_err()

2018-08-27 Thread Marc Kleine-Budde
This way the events will be printed into the dmesg buffer,

Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv4.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 9ccec7847d9f..4d2d377d084a 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -163,17 +163,17 @@ static void habv4_display_event(uint8_t *data, uint32_t 
len)
 
if (data && len) {
for (i = 0; i < len; i++) {
-   if (i == 0)
-   printf(" %02x", data[i]);
-   else if ((i % 8) == 0)
-   printf("\n %02x", data[i]);
+   if ((i % 8) == 0)
+   pr_err(" %02x", data[i]);
else if ((i % 4) == 0)
-   printf("  %02x", data[i]);
+   pr_cont("  %02x", data[i]);
+   else if ((i % 8) == 7)
+   pr_cont(" %02x\n", data[i]);
else
-   printf(" %02x", data[i]);
+   pr_cont(" %02x", data[i]);
}
+   pr_cont("\n");
}
-   printf("\n\n");
 }
 
 static int habv4_get_status(const struct habv4_rvt *rvt)
@@ -201,8 +201,8 @@ static int habv4_get_status(const struct habv4_rvt *rvt)
}
 
while (rvt->report_event(HAB_STATUS_FAILURE, index, data, &len) == 
HAB_STATUS_SUCCESS) {
-   printf(" HAB Event %d \n"
-  "event data:\n", index);
+   pr_err(" HAB Event %d \n", index);
+   pr_err("event data:\n");
 
habv4_display_event(data, len);
len = sizeof(data);
-- 
2.18.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 5/5] scripts imx-image: add support for newer versions of "cst"

2018-08-27 Thread Marc Kleine-Budde
Older versions of "cst" want to read the CSF frm STDIN, while newer versions
want to read the CSF from a file. Sadly, the "-i" option doesn't understand
"-i -" to read from STDIN, so we give it "/dev/stdin" instead.

Signed-off-by: Marc Kleine-Budde 
---
 scripts/imx/imx-image.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 452a544bc3eb..17d504586967 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -558,7 +558,21 @@ static int hab_sign(struct config_data *data)
}
}
 
-   ret = asprintf(&command, "%s -o %s", cst, csffile);
+   /*
+* Older versions of "cst" want to read the CSF frm STDIN,
+* while newer versions want to read the CSF from a
+* file. Sadly, the "-i" option doesn't understand "-i -" to
+* read from STDIN, so we give it "/dev/stdin" instead.
+*/
+   ret = asprintf(&command,
+  "if %s | grep 'Input CSF text filename'; then"
+  "%s -o %s -i /dev/stdin;"
+  "else"
+  "%s -o %s;"
+  "fi",
+  cst,
+  cst, csffile,
+  cst, csffile);
if (ret < 0)
return -ENOMEM;
 
-- 
2.18.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 0/5] i.MX habv4: decode error/warning events and support new CST version

2018-08-27 Thread Marc Kleine-Budde
Hello,

this patch series add support to device error and warning events generated by
the ROM code during HAB. It further adds support newer versions of the CST
tools.

regards,
Marc



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/5] i.MX habv4: properly indent defines and enums

2018-08-27 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index ae43bdf0e36b..9ccec7847d9f 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -27,13 +27,13 @@
 #define HABV4_RVT_IMX28 0x8af8
 #define HABV4_RVT_IMX6_OLD 0x0094
 #define HABV4_RVT_IMX6_NEW 0x0098
-#define HABV4_RVT_IMX6UL   0x0100
+#define HABV4_RVT_IMX6UL 0x0100
 
 enum hab_tag {
HAB_TAG_IVT = 0xd1, /* Image Vector Table */
HAB_TAG_DCD = 0xd2, /* Device Configuration Data */
HAB_TAG_CSF = 0xd4, /* Command Sequence File */
-   HAB_TAG_CRT = 0xd7, /* Certificate */
+   HAB_TAG_CRT = 0xd7, /* Certificate */
HAB_TAG_SIG = 0xd8, /* Signature */
HAB_TAG_EVT = 0xdb, /* Event */
HAB_TAG_RVT = 0xdd, /* ROM Vector Table */
-- 
2.18.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 4/5] i.MX habv4: habv4_display_event_record(): Add function to decode event record

2018-08-27 Thread Marc Kleine-Budde
The code was leveraged from u-boot commit:

29067abfaf39 iMX: adding parsing to hab_status command

by: Ulises Cardenas 

Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv4.c | 211 
 1 file changed, 211 insertions(+)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 74b5af2229c3..28fd42ecd7a8 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -29,6 +29,21 @@
 #define HABV4_RVT_IMX6_NEW 0x0098
 #define HABV4_RVT_IMX6UL 0x0100
 
+struct __packed hab_hdr {
+   uint8_t tag;/* Tag field */
+   __be16 len; /* Length field in bytes (big-endian) */
+   uint8_t par;/* Parameters field */
+};
+
+struct __packed hab_event_record {
+   struct hab_hdr hdr;
+   uint8_t status; /* Status -> enum hab_status*/
+   uint8_t reason; /* Reason -> enum hab_reason */
+   uint8_t context;/* Context -> enum hab_context */
+   uint8_t engine; /* Engine -> enum hab_engine */
+   uint8_t data[0];/* Record Data */
+};
+
 enum hab_tag {
HAB_TAG_IVT = 0xd1, /* Image Vector Table */
HAB_TAG_DCD = 0xd2, /* Device Configuration Data */
@@ -69,6 +84,66 @@ enum hab_state {
HAB_STATE_NONE = 0xf0,  /* No security state machine */
 };
 
+enum hab_reason {
+   HAB_REASON_RSN_ANY = 0x00,  /* Match any reason */
+   HAB_REASON_UNS_COMMAND = 0x03,  /* Unsupported command */
+   HAB_REASON_INV_IVT = 0x05,  /* Invalid ivt */
+   HAB_REASON_INV_COMMAND = 0x06,  /* Invalid command: command 
malformed */
+   HAB_REASON_UNS_STATE = 0x09,/* Unsuitable state */
+   HAB_REASON_UNS_ENGINE = 0x0a,   /* Unsupported engine */
+   HAB_REASON_INV_ASSERTION = 0x0c,/* Invalid assertion */
+   HAB_REASON_INV_INDEX = 0x0f,/* Invalid index: access denied 
*/
+   HAB_REASON_INV_CSF = 0x11,  /* Invalid csf */
+   HAB_REASON_UNS_ALGORITHM = 0x12,/* Unsupported algorithm */
+   HAB_REASON_UNS_PROTOCOL = 0x14, /* Unsupported protocol */
+   HAB_REASON_INV_SIZE = 0x17, /* Invalid data size */
+   HAB_REASON_INV_SIGNATURE = 0x18,/* Invalid signature */
+   HAB_REASON_UNS_KEY = 0x1b,  /* Unsupported key 
type/parameters */
+   HAB_REASON_INV_KEY = 0x1d,  /* Invalid key */
+   HAB_REASON_INV_RETURN = 0x1e,   /* Failed callback function */
+   HAB_REASON_INV_CERTIFICATE = 0x21,  /* Invalid certificate */
+   HAB_REASON_INV_ADDRESS = 0x22,  /* Invalid address: access 
denied */
+   HAB_REASON_UNS_ITEM = 0x24, /* Unsupported configuration 
item */
+   HAB_REASON_INV_DCD = 0x27,  /* Invalid dcd */
+   HAB_REASON_INV_CALL = 0x28, /* Function called out of 
sequence */
+   HAB_REASON_OVR_COUNT = 0x2b,/* Expired poll count */
+   HAB_REASON_OVR_STORAGE = 0x2d,  /* Exhausted storage region */
+   HAB_REASON_MEM_FAIL = 0x2e, /* Memory failure */
+   HAB_REASON_ENG_FAIL = 0x30, /* Engine failure */
+};
+
+enum hab_context {
+   HAB_CONTEXT_ANY = 0x00, /* Match any context */
+   HAB_CONTEXT_AUTHENTICATE = 0x0a,/* Logged in 
hab_rvt.authenticate_image() */
+   HAB_CONTEXT_TARGET = 0x33,  /* Event logged in 
hab_rvt.check_target() */
+   HAB_CONTEXT_ASSERT = 0xa0,  /* Event logged in 
hab_rvt.assert() */
+   HAB_CONTEXT_COMMAND = 0xc0, /* Event logged executing 
csf/dcd command */
+   HAB_CONTEXT_CSF = 0xcf, /* Event logged in 
hab_rvt.run_csf() */
+   HAB_CONTEXT_AUT_DAT = 0xdb, /* Authenticated data block */
+   HAB_CONTEXT_DCD = 0xdd, /* Event logged in 
hab_rvt.run_dcd() */
+   HAB_CONTEXT_ENTRY = 0xe1,   /* Event logged in 
hab_rvt.entry() */
+   HAB_CONTEXT_EXIT = 0xee,/* Event logged in 
hab_rvt.exit() */
+   HAB_CONTEXT_FAB = 0xff, /* Event logged in 
hab_fab_test() */
+};
+
+enum hab_engine {
+   HAB_ENGINE_ANY = 0x00,  /* Select first compatible engine */
+   HAB_ENGINE_SCC = 0x03,  /* Security controller */
+   HAB_ENGINE_RTIC = 0x05, /* Run-time integrity checker */
+   HAB_ENGINE_SAHARA = 0x06,   /* Crypto accelerator */
+   HAB_ENGINE_CSU = 0x0a,  /* Central Security Unit */
+   HAB_ENGINE_SRTC = 0x0c, /* Secure clock */
+   HAB_ENGINE_DCP = 0x1b,  /* Data Co-Processor */
+   HAB_ENGINE_CAAM = 0x1d, /* CAAM */
+   HAB_ENGINE_SNVS = 0x1e, /* Secure Non-Volatile Storage */
+   HAB_ENGINE_OCOTP = 0x21,   

[PATCH 3/5] i.MX habv4: habv4_get_status(): display warning events, too

2018-08-27 Thread Marc Kleine-Budde
The current code only retrieves the HAB errors from the ROM. If there are HAB
warnings during startup, the code throws this wrong error message.

> HABv4: ERROR: Recompile with larger event data buffer (at least 36 bytes)

The correct solution is to retrieve the warnings from the ROM, too.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv4.c | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 4d2d377d084a..74b5af2229c3 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -179,7 +179,7 @@ static void habv4_display_event(uint8_t *data, uint32_t len)
 static int habv4_get_status(const struct habv4_rvt *rvt)
 {
uint8_t data[256];
-   uint32_t len = sizeof(data);
+   uint32_t len;
uint32_t index = 0;
enum hab_status status;
enum hab_config config = 0x0;
@@ -200,8 +200,19 @@ static int habv4_get_status(const struct habv4_rvt *rvt)
return 0;
}
 
+   len = sizeof(data);
+   while (rvt->report_event(HAB_STATUS_WARNING, index, data, &len) == 
HAB_STATUS_SUCCESS) {
+   pr_err(" HAB warning Event %d \n", index);
+   pr_err("event data:\n");
+
+   habv4_display_event(data, len);
+   len = sizeof(data);
+   index++;
+   }
+
+   len = sizeof(data);
while (rvt->report_event(HAB_STATUS_FAILURE, index, data, &len) == 
HAB_STATUS_SUCCESS) {
-   pr_err(" HAB Event %d \n", index);
+   pr_err(" HAB failure Event %d \n", index);
pr_err("event data:\n");
 
habv4_display_event(data, len);
@@ -210,6 +221,7 @@ static int habv4_get_status(const struct habv4_rvt *rvt)
}
 
/* Check reason for stopping */
+   len = sizeof(data);
if (rvt->report_event(HAB_STATUS_ANY, index, NULL, &len) == 
HAB_STATUS_SUCCESS)
pr_err("ERROR: Recompile with larger event data buffer (at 
least %d bytes)\n\n", len);
 
-- 
2.18.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] Makefile.lib: imx hab: fix hab files with embedded variables

2018-02-09 Thread Marc Kleine-Budde
On 02/09/2018 10:45 AM, Sascha Hauer wrote:
> From: Marc Kleine-Budde 
> 
> When passing variables this way, all embedded variables are expanded, so that
> the path in the .config file can be kept relative.
> 
> Signed-off-by: Marc Kleine-Budde 
S-o-b: sha?

Marc

-- 
Pengutronix e.K.      | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] bootm: fit: add option to add DT snipped that contains fit public key

2018-02-09 Thread Marc Kleine-Budde
On 02/09/2018 11:01 AM, Sascha Hauer wrote:
> From: Marc Kleine-Budde 
> 
> This makes it easier for build systems to include a configurable dts
> snippet which holds the public keys for FIT images.
> 
> Usage:
> 
> Add to your dts:
> 
>  #ifdef CONFIG_BOOTM_FITIMAGE_PUBKEY
>  #include CONFIG_BOOTM_FITIMAGE_PUBKEY
>  #endif
> 
> Signed-off-by: Marc Kleine-Budde 
> Signed-off-by: Sascha Hauer 
> ---
>  common/Kconfig   | 7 +++
>  scripts/Makefile.lib | 6 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index 93b1d89274..33e15490e9 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -632,6 +632,13 @@ config BOOTM_FITIMAGE_SIGNATURE
> Additionally the barebox device tree needs a /signature node with the
> public key with which the image has been signed.
>  
> +config BOOTM_FITIMAGE_PUBKEY
> + string "Path to dtsi containing pubkey"
> + default "../fit/pubkey.dtsi"
> + depends on BOOTM_FITIMAGE_SIGNATURE
> + help
> +   FIXME

Set Path to a dts snippet which holds the public keys for FIT images.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] UBI: attach: add missing newline at end of pr_err()

2017-10-15 Thread Marc Kleine-Budde
This patch adds the missing newline at the end of the pr_err()
statement.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/mtd/ubi/attach.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index b49842be3948..ff4b4e7acb76 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -782,7 +782,7 @@ static int check_corruption(struct ubi_device *ubi, struct 
ubi_vid_hdr *vid_hdr,
pnum);
ubi_err(ubi, "this may be a non-UBI PEB or a severe VID header 
corruption which requires manual inspection");
ubi_dump_vid_hdr(vid_hdr);
-   pr_err("hexdump of PEB %d offset %d, length %d",
+   pr_err("hexdump of PEB %d offset %d, length %d\n",
   pnum, ubi->leb_start, ubi->leb_size);
ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
   ubi->peb_buf, ubi->leb_size, 1);
-- 
2.14.2


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] imx-bbu-nand-fcb: read_firmware_all(): Spell "Secondary firmware" with a capital "S"

2017-09-22 Thread Marc Kleine-Budde
"Primary firmware" is writte with a capital "P" so adjust "Secondary firmware"
to use a capital "S".

Signed-off-by: Marc Kleine-Budde 
---
 common/imx-bbu-nand-fcb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 7218c5e1ccda..89b404884ae8 100644
--- a/common/imx-bbu-nand-fcb.c
+++ b/common/imx-bbu-nand-fcb.c
@@ -1126,7 +1126,7 @@ static void read_firmware_all(struct mtd_info *mtd, 
struct fcb_block *fcb, void
fcb->Firmware1_startingPage + fcb->PagesInFirmware1, primary ? 
"" : "in",
primary_refresh ? "needs cleanup" : "clean");
 
-   pr_info("secondary firmware is on pages %d-%d, %svalid, %s\n", 
fcb->Firmware2_startingPage,
+   pr_info("Secondary firmware is on pages %d-%d, %svalid, %s\n", 
fcb->Firmware2_startingPage,
fcb->Firmware2_startingPage + fcb->PagesInFirmware2, secondary 
? "" : "in",
secondary_refresh ? "needs cleanup" : "clean");
 
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] bootm: bootm_open_initrd_uimage(): propagate error if initrd verification fails

2017-09-19 Thread Marc Kleine-Budde
If the verification of an initrd inside of an uImage fails an error message is
printed but the error is not propagated. Although this is not security
relevant, as the verification is currently only a CRC32 check, the error should
be returned. This patch fixes the problem.

Signed-off-by: Marc Kleine-Budde 
---
 common/bootm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/bootm.c b/common/bootm.c
index 81625d9157cc..eebaa799f548 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -173,6 +173,7 @@ static int bootm_open_initrd_uimage(struct image_data *data)
if (ret) {
printf("Checking data crc failed with %s\n",
strerror(-ret));
+   return ret;
}
}
uimage_print_contents(data->initrd);
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


bootm_open_initrd_uimage: result of uimage_verify() is ignored

2017-09-18 Thread Marc Kleine-Budde
Hello,

the bootm_open_initrd_uimage() function will check the CRC of the inird,
if bootm_get_verify_mode is set appropriately, but the error value is
not propagated.

> static int bootm_open_initrd_uimage(struct image_data *data)
> {
>   int ret;
> 
>   if (strcmp(data->os_file, data->initrd_file)) {
>   data->initrd = uimage_open(data->initrd_file);
>   if (!data->initrd)
>   return -EINVAL;
> 
>   if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
>   ret = uimage_verify(data->initrd);
>   if (ret) {
>   printf("Checking data crc failed with %s\n",
>   strerror(-ret));
>   }
>   }
>   uimage_print_contents(data->initrd);
>   } else {
>   data->initrd = data->os;
>   }
> 
>   return 0;
> }

Is this intentional?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] ARM: i.MX: HAB: update documentation of command sequence files (CSF)

2017-05-08 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/mach-imx/include/mach/habv3-imx25-gencsf.h | 11 ---
 arch/arm/mach-imx/include/mach/habv4-imx6-gencsf.h  |  9 +
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/habv3-imx25-gencsf.h 
b/arch/arm/mach-imx/include/mach/habv3-imx25-gencsf.h
index f4804fe63f19..60f730f8eca9 100644
--- a/arch/arm/mach-imx/include/mach/habv3-imx25-gencsf.h
+++ b/arch/arm/mach-imx/include/mach/habv3-imx25-gencsf.h
@@ -4,8 +4,8 @@
  * are expected in these config variables:
  *
  * CONFIG_HABV3_SRK_PEM
- * CONFIG_HABV3_SRK_PEM
- * CONFIG_HABV3_IMG_CRT_PEM
+ * CONFIG_HABV3_CSF_CRT_DER
+ * CONFIG_HABV3_IMG_CRT_DER
  */
 super_root_key CONFIG_HABV3_SRK_PEM
 
@@ -23,21 +23,26 @@ hab [Install SRK]
 hab File = "not-used"
 
 hab [Install CSFK]
+/* target key index in keystore 1 */
 hab File = CONFIG_HABV3_CSF_CRT_DER
 
 hab [Authenticate CSF]
-/* below is the command that unlock the access to the DryIce registers */
 
+/* unlock the access to the DryIce registers */
 hab [Write Data]
 hab Width = 4
 hab Address Data = 0x53FFC03C 0xCA693569
 
 hab [Install Key]
+/* verification key index in key store (1...4) */
+/* in contrast to documentation 0 seems to be valid, too */
 hab Verification index = 1
+/* target key index in key store (1...4) */
 hab Target index = 2
 hab File = CONFIG_HABV3_IMG_CRT_DER
 
 hab [Authenticate Data]
+/* verification key index in key store (2...4) */
 hab Verification index = 2
 
 hab_blocks
diff --git a/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf.h 
b/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf.h
index 1a143a8b1870..0649caa0cb88 100644
--- a/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf.h
+++ b/arch/arm/mach-imx/include/mach/habv4-imx6-gencsf.h
@@ -22,6 +22,7 @@ hab # SRK index within SRK-Table 0..3
 hab Source index = 0
 
 hab [Install CSFK]
+/* target key index in keystore 1 */
 hab File = CONFIG_HABV4_CSF_CRT_PEM
 
 hab [Authenticate CSF]
@@ -31,14 +32,14 @@ hab Engine = CAAM
 hab Features = RNG
 
 hab [Install Key]
-/* verification key index in key store (0, 2...5) */
+/* verification key index in key store (0, 2...4) */
 hab Verification index = 0
-/* target key index in key store (2...5) */
+/* target key index in key store (2...4) */
 hab Target index = 2
 hab File = CONFIG_HABV4_IMG_CRT_PEM
 
 hab [Authenticate Data]
-/* verification key index in key store (2...5) */
+/* verification key index in key store (2...4) */
 hab Verification index = 2
 
-hab_blocks
\ No newline at end of file
+hab_blocks
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 2/3] console_countdown: add possibility to abort countdown by external commands

2017-03-09 Thread Marc Kleine-Budde
On 03/09/2017 06:58 PM, Oleksij Rempel wrote:
> From: Marc Kleine-Budde 
> 
> This patch makes it possible to abort a console countdown by an external
> command, for example when fastboot is used. This requires additional
> modifications in the external commands, a call to "console_countdown_abort()"
> has to be inserted.
> 
> Signed-off-by: Marc Kleine-Budde 
> Signed-off-by: Oleksij Rempel 
> ---
>  commands/timeout.c  |  8 ++--
>  common/console_countdown.c  | 15 +++
>  include/console_countdown.h |  2 ++
>  3 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/commands/timeout.c b/commands/timeout.c
> index ef1a037c1..d197cedd8 100644
> --- a/commands/timeout.c
> +++ b/commands/timeout.c
> @@ -32,7 +32,7 @@ static int do_timeout(int argc, char *argv[])
>   char str[2] = { };
>   const char *varname = NULL;
>  
> - while((opt = getopt(argc, argv, "crsav:")) > 0) {
> + while ((opt = getopt(argc, argv, "crsav:e")) > 0) {
>   switch(opt) {
>   case 'r':
>   flags |= CONSOLE_COUNTDOWN_RETURN;
> @@ -46,6 +46,9 @@ static int do_timeout(int argc, char *argv[])
>   case 's':
>   flags |= CONSOLE_COUNTDOWN_SILENT;
>   break;
> + case 'e':
> + flags |= CONSOLE_COUNTDOWN_EXTERN;
> + break;
>   case 'v':
>   varname = optarg;
>   break;
> @@ -73,6 +76,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
>  BAREBOX_CMD_HELP_OPT("-a", "interrupt on any key")
>  BAREBOX_CMD_HELP_OPT("-c", "interrupt on Ctrl-C")
>  BAREBOX_CMD_HELP_OPT("-r", "interrupt on RETURN")
> +BAREBOX_CMD_HELP_OPT("-e", "interrupt on external commands (i.e. fastboot")
>  BAREBOX_CMD_HELP_OPT("-s", "silent mode")
>  BAREBOX_CMD_HELP_OPT("-v ", "export pressed key to environment")
>  BAREBOX_CMD_HELP_END
> @@ -80,7 +84,7 @@ BAREBOX_CMD_HELP_END
>  BAREBOX_CMD_START(timeout)
>   .cmd= do_timeout,
>   BAREBOX_CMD_DESC("wait for a specified timeout")
> - BAREBOX_CMD_OPTS("[-acrsv] SECONDS")
> + BAREBOX_CMD_OPTS("[-acrsev] SECONDS")
>   BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
>   BAREBOX_CMD_HELP(cmd_timeout_help)
>  BAREBOX_CMD_END
> diff --git a/common/console_countdown.c b/common/console_countdown.c
> index b2eec72b2..594d3d879 100644
> --- a/common/console_countdown.c
> +++ b/common/console_countdown.c
> @@ -23,6 +23,13 @@
>  #include 
>  #include 
>  
> +static int console_countdown_timeout_abort;

static bool

> +
> +void console_countdown_abort(void)
> +{
> + console_countdown_timeout_abort = true;
> +}
> +
>  int console_countdown(int timeout_s, unsigned flags, char *out_key)
>  {
>   uint64_t start, second;
> @@ -48,6 +55,9 @@ int console_countdown(int timeout_s, unsigned flags, char 
> *out_key)
>   goto out;
>   key = 0;
>   }
> + if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
> + console_countdown_timeout_abort)
> + goto out;
>   if (!(flags & CONSOLE_COUNTDOWN_SILENT) &&
>   is_timeout(second, SECOND)) {
>   printf("\b\b\b\b%4d", countdown--);
> @@ -55,6 +65,10 @@ int console_countdown(int timeout_s, unsigned flags, char 
> *out_key)
>   }
>   } while (!is_timeout(start, timeout_s * SECOND));
>  
> + if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
> + console_countdown_timeout_abort)
> + goto out;
> +
>   ret = 0;
>  
>   out:
> @@ -62,6 +76,7 @@ int console_countdown(int timeout_s, unsigned flags, char 
> *out_key)
>   printf("\n");
>   if (key && out_key)
>   *out_key = key;
> + console_countdown_timeout_abort = false;
>  
>   return ret;
>  }
> diff --git a/include/console_countdown.h b/include/console_countdown.h
> index cb46964bc..c6c2d5c00 100644
> --- a/include/console_countdown.h
> +++ b/include/console_countdown.h
> @@ -5,7 +5,9 @@
>  #define CONSOLE_COUNTDOWN_ANYKEY (1 << 1)
>  #define CONSOLE_COUNTDOWN_RETURN (1 << 3)
>  #define CONSOLE_COUNTDOWN_CTRLC (1 << 4)
> +#define CONSOLE_COUNTDOWN_EXTERN (1 << 5)
>  
>  int console_countdown(int timeout_s, unsigned flags, char *out_key);
> +void console_countdown_abort(void);
>  
>  #endif /* __CONSOLE_COUNTDOWN_H */
> 

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: barebox-state (dt-utils): dump-shell broken for state@0

2016-04-06 Thread Marc Kleine-Budde
On 04/05/2016 08:49 AM, Sascha Hauer wrote:
> +Cc mkl who wrote 6d58ca4
> 
> On Mon, Apr 04, 2016 at 11:44:51PM +0200, Andreas Pretzsch wrote:
>> On Mi, 2015-06-17 at 11:06 +0200, Sascha Hauer wrote:
>>> On Wed, Jun 17, 2015 at 08:42:50AM +0200, Jan Remmet wrote:
>>>> Hello,
>>>> I'm working with barebox states and wonder if there is already a tool to 
>>>> access
>>>> states in eeprom from linux?
>>>> The states from a dtb backend should be easy to read. For raw there must be
>>>> looked under /proc/devicetree or a state kernel driver.
>>>
>>> Yes, there is such a tool here:
>>>
>>> git://git.pengutronix.de/git/tools/dt-utils.git
>>>
>>> The binary you'll need is barebox-state.
>>
>> barebox-state provides a command "--dump-shell" to dump the state
>> suitable for shell sourcing.
>> Essentially, it prints out variable=value pairs.
>> So typical use would be a
>>  eval `barebox-state --dump-shell`
>> somewhere in a shell script (incl. simple ones like busybox ash).
>>
>> Unfortunately, this breaks with indices in the state name, as @ is not
>> escaped.
>> Tested with dt-utils v2015.10.0, but according to code this is the case
>> from v2015.05.0 up until master.
>>
>> As of commit 6d58ca4 "barebox-state: fix export of shell variables:",
>> the fixed prefix "STATE_" was replaced by the supplied state name.
>> Also in there, all '.' are replaced by '_' in the variable name. Not in
>> the state name itself.
>>
>> The same would be necessary for (at least) '@', because it is invalid
>> also inside a shell variable name. As probably other chars, just I'm not
>> sure which might show up from the dts. So no premature patch from my
>> side.
>> Not only for the variable name, but also the state name itself.

I think the "@" is removed from the state name, isn't it? See
"state_convert_node_variable()":

> /* strip trailing @ */
> short_name = xstrdup(node->name);
> indexs = strchr(short_name, '@');
> if (indexs)
> *indexs = 0;

>>
>> For clarification of the setup and behaviour, see below.
>>
>>
>> Now, question would be how to fix this.
>> Also replacing '@' by '_' might break existing users (e.g. when parsing
>> from stdin or similar, instead of using shells eval command).
>> On the other hand, status quo breaks the "described" use of dump
>> _shell_ ...
>>
>> Talking about this, it might be also some idea to resurrect the old
>> behaviour of always printing 'STATE_' as prefix instead of the state
>> name from dts. Not sure if it's the best idea, or how to call such an
>> extra option, didn't think it through by now.
>> Just saying, as I will go this way here (as a hotfix) for my setup...
>>
>> Ideas, opinions ?
> 
> I'm in favor for resurrecting the old 'STATE_' behaviour, but I don't
> know why Marc changed it. Maybe he has some more input.

We make use of more than one state partition in one shell script.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/2] i.MX habv3: add some more status codes

2016-02-08 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv3.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/hab/habv3.c b/drivers/hab/habv3.c
index 204b9095b393..82ae245f8a03 100644
--- a/drivers/hab/habv3.c
+++ b/drivers/hab/habv3.c
@@ -20,6 +20,7 @@ struct hab_status {
 };
 
 static struct hab_status hab_status[] = {
+   { 0x12, "Download code can't be executed, please check the HAB type" },
{ 0x17, "SCC unexpectedly not in secure state" },
{ 0x1b, "secureRAM self test failure" },
{ 0x1d, "secureRAM initialization failure" },
@@ -31,11 +32,14 @@ static struct hab_status hab_status[] = {
{ 0x33, "certificate parsing failed or the certificate contained an 
unsupported key" },
{ 0x35, "signature verification failed" },
{ 0x36, "hash verification failed" },
+   { 0x39, "Failure not matching any other description" },
{ 0x3a, "CSF customer/product code does not match processor 
customer/product code" },
+   { 0x47, "installation or comparison of SRKs failed" },
{ 0x4b, "CSF command sequence contains unsupported command identifier" 
},
{ 0x4d, "CSF length is unsupported" },
{ 0x4e, "absence of expected CSF header" },
{ 0x55, "error during assert verification" },
+   { 0x56, "Download code can't be executed, please check the HAB type" },
{ 0x63, "DCD invalid" },
{ 0x66, "write operation to register failed" },
{ 0x67, "INT_BOOT fuse is blown but BOOT pins are set for external 
boot" },
-- 
2.7.0.rc3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/2] i.MX habv3: sort hab status codes numerically

2016-02-08 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 drivers/hab/habv3.c | 44 ++--
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/hab/habv3.c b/drivers/hab/habv3.c
index 70f31a3c4d98..204b9095b393 100644
--- a/drivers/hab/habv3.c
+++ b/drivers/hab/habv3.c
@@ -20,35 +20,35 @@ struct hab_status {
 };
 
 static struct hab_status hab_status[] = {
-   { 0x8d, "data specified is out of bounds" },
-   { 0x55, "error during assert verification" },
-   { 0x36, "hash verification failed" },
-   { 0x33, "certificate parsing failed or the certificate contained an 
unsupported key" },
-   { 0x35, "signature verification failed" },
-   { 0x4B, "CSF command sequence contains unsupported command identifier" 
},
-   { 0x4e, "absence of expected CSF header" },
-   { 0x4d, "CSF length is unsupported" },
-   { 0x2e, "CSF TYPE does not match processor TYPE" },
-   { 0x2d, "CSF UID does not match either processor UID or generic UID" },
-   { 0x3a, "CSF customer/product code does not match processor 
customer/product code" },
-   { 0x87, "key indexis either unsupported, or an attempt is made to 
overwrite the SRK from a CSF command" },
{ 0x17, "SCC unexpectedly not in secure state" },
-   { 0x1e, "secureRAM secret key invalid" },
-   { 0x1d, "secureRAM initialization failure" },
{ 0x1b, "secureRAM self test failure" },
-   { 0x2b, "secureRAM internal failure" },
+   { 0x1d, "secureRAM initialization failure" },
+   { 0x1e, "secureRAM secret key invalid" },
{ 0x27, "secureRAM secrect key unexpectedly in use" },
-   { 0x8b, "an attempt is made to read a key from the list of subordinate 
public keys at a location "
-   "where no key is installed" },
-   { 0x8e, "algorithm type is either invalid or ortherwise unsupported" },
-   { 0x66, "write operation to register failed" },
+   { 0x2b, "secureRAM internal failure" },
+   { 0x2d, "CSF UID does not match either processor UID or generic UID" },
+   { 0x2e, "CSF TYPE does not match processor TYPE" },
+   { 0x33, "certificate parsing failed or the certificate contained an 
unsupported key" },
+   { 0x35, "signature verification failed" },
+   { 0x36, "hash verification failed" },
+   { 0x3a, "CSF customer/product code does not match processor 
customer/product code" },
+   { 0x4b, "CSF command sequence contains unsupported command identifier" 
},
+   { 0x4d, "CSF length is unsupported" },
+   { 0x4e, "absence of expected CSF header" },
+   { 0x55, "error during assert verification" },
{ 0x63, "DCD invalid" },
-   { 0x6f, "RAM application pointer is NULL or ERASED_FLASH" },
+   { 0x66, "write operation to register failed" },
+   { 0x67, "INT_BOOT fuse is blown but BOOT pins are set for external 
boot" },
{ 0x69, "CSF missing when HAB TYPE is not HAB-disabled" },
{ 0x6a, "NANDFC boot buffer load failed" },
{ 0x6c, "Exception has occured" },
-   { 0x67, "INT_BOOT fuse is blown but BOOT pins are set for external 
boot" },
+   { 0x6f, "RAM application pointer is NULL or ERASED_FLASH" },
+   { 0x87, "key indexis either unsupported, or an attempt is made to 
overwrite the SRK from a CSF command" },
{ 0x88, "Successful download completion" },
+   { 0x8b, "an attempt is made to read a key from the list of subordinate 
public keys at a location "
+ "where no key is installed" },
+   { 0x8d, "data specified is out of bounds" },
+   { 0x8e, "algorithm type is either invalid or ortherwise unsupported" },
 };
 
 int imx_habv3_get_status(uint32_t status)
@@ -75,4 +75,4 @@ int imx_habv3_get_status(uint32_t status)
 int imx25_hab_get_status(void)
 {
return imx_habv3_get_status(readl(IOMEM(0x780018d4)));
-}
\ No newline at end of file
+}
-- 
2.7.0.rc3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] docs: fix typos

2016-02-04 Thread Marc Kleine-Budde
On 02/04/2016 08:25 AM, Ulrich Ölmann wrote:
> Signed-off-by: Ulrich Ölmann 
> ---
>  Documentation/devicetree/bindings/barebox/barebox,state.rst | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst 
> b/Documentation/devicetree/bindings/barebox/barebox,state.rst
> index d1b0627..5643edc 100644
> --- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
> +++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
> @@ -43,7 +43,7 @@ Variable nodes
>  
>  These are subnodes of a state node each describing a single
>  variable. The node name may end with ``@``, but the suffix is
> -sripped from the variable name.
> +ripped from the variable name.

It should read "stripped"

>  
>  State variables have a type. Currenty supported types are: ``uint8``,
>  ``uint32``, ``enum32``, ``mac`` address or ``string``. Variable length
> 

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] fixup! input: gpio-keys: convert to input framework

2016-01-16 Thread Marc Kleine-Budde
This patch adds the missing select to the input framework.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/input/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 7cc98f2d5c2e..1f89ae3892dc 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -15,6 +15,7 @@ config KEYBOARD_GPIO
bool "GPIO Buttons"
depends on GENERIC_GPIO
select POLLER
+   select INPUT
help
  This driver implements support for buttons connected
  to GPIO pins of various CPUs (and some other chips).
-- 
2.6.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: Verified boot support with FIT

2016-01-14 Thread Marc Kleine-Budde
On 01/14/2016 08:30 PM, Simon Glass wrote:
> Someone pointed me to this support that is being added in Barebox. I see
> that it still has the copyright but does not attribute U-Boot. I'm just
> checking if that is that an oversight?

I've Cc'ed Jan, who has written the code. Quoting from his first patch
to the barebox mailinglist:

> this is the current work-in-progress state of my FIT support patches.
> The FIT loading code has basically been rewritten from scratch, as the
> original U-Boot code uses libfdt and barebox's DT support works on an
> in-memory tree.

regards,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] state: hmac: fix error message that algo is displayed

2016-01-14 Thread Marc Kleine-Budde
This patch moves the error message about missing crypto support so that the
used crypto algo is printed. Without this patch the algo is always shown as a
NULL pointer.

Signed-off-by: Marc Kleine-Budde 
---
 common/state.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/state.c b/common/state.c
index d1fa47ffa34e..3e95efd91168 100644
--- a/common/state.c
+++ b/common/state.c
@@ -1583,6 +1583,10 @@ static int state_backend_raw_file_init_digest(struct 
state *state, struct state_
if (!p) /* does not exist */
return 0;
 
+   ret = of_property_read_string(state->root, "algo", &algo);
+   if (ret)
+   return ret;
+
if (!IS_ENABLED(CONFIG_STATE_CRYPTO)) {
dev_err(&state->dev,
"algo %s specified, but crypto support for state 
framework (CONFIG_STATE_CRYPTO) not enabled.\n",
@@ -1590,10 +1594,6 @@ static int state_backend_raw_file_init_digest(struct 
state *state, struct state_
return -EINVAL;
}
 
-   ret = of_property_read_string(state->root, "algo", &algo);
-   if (ret)
-   return ret;
-
ret = keystore_get_secret(state->name, &key, &key_len);
if (ret == -ENOENT) /* -ENOENT == does not exist */
return -EPROBE_DEFER;
-- 
2.6.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] FIT: make RSA signature verification configurable

2016-01-10 Thread Marc Kleine-Budde
On 01/08/2016 05:43 PM, Yegor Yefremov wrote:
> On Fri, Jan 8, 2016 at 5:11 PM, Marc Kleine-Budde  wrote:
>> On 01/08/2016 02:24 PM, yegorsli...@googlemail.com wrote:
>>> From: Yegor Yefremov 
>>>
>>> Signed-off-by: Yegor Yefremov 

[...]

>>> diff --git a/common/image-fit.c b/common/image-fit.c
>>> index 296285b..96cc3e2 100644
>>> --- a/common/image-fit.c
>>> +++ b/common/image-fit.c
>>> @@ -40,6 +40,7 @@
>>>  #define CHECK_LEVEL_SIG 2
>>>  #define CHECK_LEVEL_MAX 3
>>>
>>> +#ifdef CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE
>>>  static uint32_t dt_struct_advance(struct fdt_header *f, uint32_t dt, int 
>>> size)
>>
>> remove the ifdef.
> 
> What about compile warnings, i.e. function defined, but not used?

add __maybe_unused if needed.

> 
>>>  {
>>>   dt += size;
>>> @@ -342,6 +343,7 @@ static int fit_verify_signature(struct device_node 
>>> *sig_node, void *fit)
>>>   out:
>>>   return ret;
>>>  }
>>> +#endif
>>>
>>>  static int fit_verify_hash(struct device_node *hash, const void *data, int 
>>> data_len)
>>>  {
>>> @@ -453,10 +455,13 @@ static int fit_open_image(struct fit_handle *handle, 
>>> const char* unit)
>>>
>>>  static int fit_open_configuration(struct fit_handle *handle, int num)
>>>  {
>>> - struct device_node *conf_node = NULL, *sig_node;
>>> + struct device_node *conf_node = NULL;
>>>   char unit_name[10];
>>>   const char *unit, *desc;
>>> - int ret, level;
>>> + int level;
>>> +#ifdef CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE
>>> + struct device_node *sig_node;
>>> +#endif
>>
>> please remove the ifdef
>>
>>>
>>>   conf_node = of_get_child_by_name(handle->root, "configurations");
>>>   if (!conf_node)
>>> @@ -482,7 +487,10 @@ static int fit_open_configuration(struct fit_handle 
>>> *handle, int num)
>>>   }
>>>
>>>   level = CHECK_LEVEL_MAX;
>>> +
>>> +#ifdef CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE
>>
>> please replace the ifdef by
>>
>> if (IS_ENABLED(CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE))
>>
>>>   for_each_child_of_node(conf_node, sig_node) {
>>> + int ret;
>>>   if (handle->verbose)
>>>   of_print_nodes(sig_node, 0);
>>>   ret = fit_verify_signature(sig_node, handle->fit);
>>> @@ -495,6 +503,9 @@ static int fit_open_configuration(struct fit_handle 
>>> *handle, int num)
>>>
>>>   if (level != CHECK_LEVEL_SIG)
>>>   return -EINVAL;
>>> +#else
>>> + level = CHECK_LEVEL_SIG;
>>> +#endif
>>>
>>>   if (of_property_read_string(conf_node, "kernel", &unit) == 0)
>>>   level = min(level, fit_open_image(handle, unit));
>>>
> 
> Will you include my patch in your patch series, if you'll send v3 or
> are you just going to squash my patch into your FIT patch?

I'll take your patch as a separate patch in my series.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] FIT: make RSA signature verification configurable

2016-01-08 Thread Marc Kleine-Budde
On 01/08/2016 02:24 PM, yegorsli...@googlemail.com wrote:
> From: Yegor Yefremov 
> 
> Signed-off-by: Yegor Yefremov 
> ---
>  commands/Kconfig   | 10 ++
>  common/image-fit.c | 15 +--
>  2 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 3e4a32a..2fe37b9 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -428,6 +428,16 @@ config CMD_BOOTM_FITIMAGE
> tree in the "doc/uImage.FIT" folder for more information:
> http://git.denx.de/?p=u-boot.git;a=tree;f=doc/uImage.FIT
>  
> +config CMD_BOOTM_FITIMAGE_SIGNATURE
> + bool
> + prompt "Enable signature verification of FIT images"

Make signature verification mandatory.

> + depends on CMD_BOOTM_FITIMAGE
> + help
> +   This option enables signature verification of FIT uImages,
> +   using a hash signed and verified using RSA. If
> +   CONFIG_SHA_PROG_HW_ACCEL is defined, i.e support for progressive
> +   hashing is available using hardware, RSA library will use it.
> +
>  config CMD_BOOTU
>   tristate
>   default y
> diff --git a/common/image-fit.c b/common/image-fit.c
> index 296285b..96cc3e2 100644
> --- a/common/image-fit.c
> +++ b/common/image-fit.c
> @@ -40,6 +40,7 @@
>  #define CHECK_LEVEL_SIG 2
>  #define CHECK_LEVEL_MAX 3
>  
> +#ifdef CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE
>  static uint32_t dt_struct_advance(struct fdt_header *f, uint32_t dt, int 
> size)

remove the ifdef.

>  {
>   dt += size;
> @@ -342,6 +343,7 @@ static int fit_verify_signature(struct device_node 
> *sig_node, void *fit)
>   out:
>   return ret;
>  }
> +#endif
>  
>  static int fit_verify_hash(struct device_node *hash, const void *data, int 
> data_len)
>  {
> @@ -453,10 +455,13 @@ static int fit_open_image(struct fit_handle *handle, 
> const char* unit)
>  
>  static int fit_open_configuration(struct fit_handle *handle, int num)
>  {
> - struct device_node *conf_node = NULL, *sig_node;
> + struct device_node *conf_node = NULL;
>   char unit_name[10];
>   const char *unit, *desc;
> - int ret, level;
> + int level;
> +#ifdef CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE
> + struct device_node *sig_node;
> +#endif

please remove the ifdef

>  
>   conf_node = of_get_child_by_name(handle->root, "configurations");
>   if (!conf_node)
> @@ -482,7 +487,10 @@ static int fit_open_configuration(struct fit_handle 
> *handle, int num)
>   }
>  
>   level = CHECK_LEVEL_MAX;
> +
> +#ifdef CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE

please replace the ifdef by

if (IS_ENABLED(CONFIG_CMD_BOOTM_FITIMAGE_SIGNATURE))

>   for_each_child_of_node(conf_node, sig_node) {
> + int ret;
>   if (handle->verbose)
>   of_print_nodes(sig_node, 0);
>   ret = fit_verify_signature(sig_node, handle->fit);
> @@ -495,6 +503,9 @@ static int fit_open_configuration(struct fit_handle 
> *handle, int num)
>  
>   if (level != CHECK_LEVEL_SIG)
>   return -EINVAL;
> +#else
> + level = CHECK_LEVEL_SIG;
> +#endif
>  
>   if (of_property_read_string(conf_node, "kernel", &unit) == 0)
>   level = min(level, fit_open_image(handle, unit));
> 

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 2/3] crypto: add RSA support

2016-01-06 Thread Marc Kleine-Budde
From: Sascha Hauer 

Signed-off-by: Sascha Hauer 
Signed-off-by: Marc Kleine-Budde 
---
 crypto/Kconfig  |   3 +
 crypto/Makefile |   1 +
 crypto/rsa.c| 420 
 include/asm-generic/errno.h |   5 +
 include/rsa.h   |  54 ++
 5 files changed, 483 insertions(+)
 create mode 100644 crypto/rsa.c
 create mode 100644 include/rsa.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 41145a312d8e..ca6f03a1edd1 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -87,6 +87,9 @@ config CRYPTO_PBKDF2
select DIGEST_SHA1_GENERIC
bool
 
+config CRYPTO_RSA
+   bool
+
 config CRYPTO_KEYSTORE
bool "Keystore"
help
diff --git a/crypto/Makefile b/crypto/Makefile
index c6d17787ca4e..b4fb3d8da01f 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -11,4 +11,5 @@ obj-$(CONFIG_DIGEST_SHA384_GENERIC)   += sha4.o
 obj-$(CONFIG_DIGEST_SHA512_GENERIC)+= sha4.o
 
 obj-$(CONFIG_CRYPTO_PBKDF2)+= pbkdf2.o
+obj-$(CONFIG_CRYPTO_RSA)   += rsa.o
 obj-$(CONFIG_CRYPTO_KEYSTORE)  += keystore.o
diff --git a/crypto/rsa.c b/crypto/rsa.c
new file mode 100644
index ..3caee3ce7525
--- /dev/null
+++ b/crypto/rsa.c
@@ -0,0 +1,420 @@
+/*
+ * Copyright (c) 2013, Google Inc.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define UINT64_MULT32(v, multby)  (((uint64_t)(v)) * ((uint32_t)(multby)))
+
+#define get_unaligned_be32(a) fdt32_to_cpu(*(uint32_t *)a)
+#define put_unaligned_be32(a, b) (*(uint32_t *)(b) = cpu_to_fdt32(a))
+
+/* Default public exponent for backward compatibility */
+#define RSA_DEFAULT_PUBEXP 65537
+
+/* This is the minimum/maximum key size we support, in bits */
+#define RSA_MIN_KEY_BITS   1024
+#define RSA_MAX_KEY_BITS   4096
+
+/**
+ * subtract_modulus() - subtract modulus from the given value
+ *
+ * @key:   Key containing modulus to subtract
+ * @num:   Number to subtract modulus from, as little endian word array
+ */
+static void subtract_modulus(const struct rsa_public_key *key, uint32_t num[])
+{
+   int64_t acc = 0;
+   uint i;
+
+   for (i = 0; i < key->len; i++) {
+   acc += (uint64_t)num[i] - key->modulus[i];
+   num[i] = (uint32_t)acc;
+   acc >>= 32;
+   }
+}
+
+/**
+ * greater_equal_modulus() - check if a value is >= modulus
+ *
+ * @key:   Key containing modulus to check
+ * @num:   Number to check against modulus, as little endian word array
+ * @return 0 if num < modulus, 1 if num >= modulus
+ */
+static int greater_equal_modulus(const struct rsa_public_key *key,
+uint32_t num[])
+{
+   int i;
+
+   for (i = (int)key->len - 1; i >= 0; i--) {
+   if (num[i] < key->modulus[i])
+   return 0;
+   if (num[i] > key->modulus[i])
+   return 1;
+   }
+
+   return 1;  /* equal */
+}
+
+/**
+ * montgomery_mul_add_step() - Perform montgomery multiply-add step
+ *
+ * Operation: montgomery result[] += a * b[] / n0inv % modulus
+ *
+ * @key:   RSA key
+ * @result:Place to put result, as little endian word array
+ * @a: Multiplier
+ * @b: Multiplicand, as little endian word array
+ */
+static void montgomery_mul_add_step(const struct rsa_public_key *key,
+   uint32_t result[], const uint32_t a, const uint32_t b[])
+{
+   uint64_t acc_a, acc_b;
+   uint32_t d0;
+   uint i;
+
+   acc_a = (uint64_t)a * b[0] + result[0];
+   d0 = (uint32_t)acc_a * key->n0inv;
+   acc_b = (uint64_t)d0 * key->modulus[0] + (uint32_t)acc_a;
+   for (i = 1; i < key->len; i++) {
+   acc_a = (acc_a >> 32) + (uint64_t)a * b[i] + result[i];
+   acc_b = (acc_b >> 32) + (uint64_t)d0 * key->modulus[i] +
+   (uint32_t)acc_a;
+   result[i - 1] = (uint32_t)acc_b;
+   }
+
+   acc_a = (acc_a >> 32) + (acc_b >> 32);
+
+   result[i - 1] = (uint32_t)acc_a;
+
+   if (acc_a >> 32)
+   subtract_modulus(key, result);
+}
+
+/**
+ * montgomery_mul() - Perform montgomery mutitply
+ *
+ * Operation: montgomery result[] = a[] * b[] / n0inv % modulus
+ *
+ * @key:   RSA key
+ * @result:Place to put result, as little endian word array
+ * @a: Multiplier, as little endian word array
+ * @b: Multiplicand, as little endian word array
+ */
+static void montgomery_mul(const struct rsa_public_key *key,
+   uint32_t result[], uint32_t a[], const uint32_t b[])
+{
+   uint i;
+
+   for (i = 0; i < key->len; ++i)
+   result[i] = 0;
+   for (i = 0; i < key->len; ++i)
+   montgomery_mul_add_step(key,

[PATCH v2 3/3] bootm: add initial FIT support

2016-01-06 Thread Marc Kleine-Budde
From: Jan Luebbe 

This implementation is inspired by U-Boot's FIT support. Instead of
using libfdt (which does not exist in barebox), configuration signatures
are verified by using a simplified DT parser based on barebox's own
code.

Currently, only signed configurations with hashed images are supported,
as the other variants are less useful for verified boot. Compatible FIT
images can be created using U-Boot's mkimage tool.

Signed-off-by: Jan Luebbe 
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/lib/bootm.c |  73 +++
 commands/Kconfig |  10 +
 common/Kconfig   |   6 +
 common/Makefile  |   1 +
 common/image-fit.c   | 585 +++
 include/image-fit.h  |  42 
 6 files changed, 717 insertions(+)
 create mode 100644 common/image-fit.c
 create mode 100644 include/image-fit.h

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 7bb9b436560c..9a78ee85e9be 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -553,6 +553,77 @@ BAREBOX_MAGICVAR(aimage_noverwrite_bootargs, "Disable 
overwrite of the bootargs
 BAREBOX_MAGICVAR(aimage_noverwrite_tags, "Disable overwrite of the tags addr 
with the one present in aimage");
 #endif
 
+#include 
+
+static int do_bootm_arm_fit(struct image_data *data)
+{
+   struct fit_handle *handle;
+   int ret;
+   unsigned long mem_free;
+   unsigned long mem_start, mem_size;
+
+   handle = fit_open(data->os_file, data->os_num, data->verbose);
+   if (!handle)
+   return -EINVAL;
+
+   ret = sdram_start_and_size(&mem_start, &mem_size);
+   if (ret)
+   return ret;
+
+   /* no support for custom load address */
+   data->os_address = mem_start + PAGE_ALIGN(handle->kernel_size * 4);
+   data->os_res = request_sdram_region("fit-kernel", data->os_address, 
handle->kernel_size);
+   if (!data->os_res) {
+   pr_err("Cannot request region 0x%08lx - 0x%08lx\n",
+   data->os_address, handle->kernel_size);
+   ret = -ENOMEM;
+   goto err_out;
+   }
+   memcpy((void *)data->os_res->start, handle->kernel, 
handle->kernel_size);
+
+   /*
+* Put oftree/initrd close behind compressed kernel image to avoid
+* placing it outside of the kernels lowmem.
+*/
+   if (handle->initrd_size) {
+   data->initrd_address = PAGE_ALIGN(data->os_res->end + SZ_1M);
+   data->initrd_res = request_sdram_region("fit-initrd", 
data->initrd_address, handle->initrd_size);
+   if (!data->initrd_res) {
+   ret = -ENOMEM;
+   goto err_out;
+   }
+   memcpy((void *)data->initrd_res->start, handle->initrd, 
handle->initrd_size);
+   }
+
+   data->of_root_node = of_unflatten_dtb(handle->oftree);
+   if (!data->of_root_node) {
+   pr_err("unable to unflatten devicetree\n");
+   ret = -EINVAL;
+   goto err_out;
+   }
+
+   /*
+* Put devicetree right after initrd if present or after the kernel
+* if not.
+*/
+   if (data->initrd_res)
+   mem_free = PAGE_ALIGN(data->initrd_res->end);
+   else
+   mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);
+
+   return __do_bootm_linux(data, mem_free, 0);
+
+err_out:
+   fit_close(handle);
+   return ret;
+}
+
+static struct image_handler arm_fit_handler = {
+.name = "FIT image",
+.bootm = do_bootm_arm_fit,
+.filetype = filetype_oftree,
+};
+
 static struct binfmt_hook binfmt_aimage_hook = {
.type = filetype_aimage,
.exec = "bootm",
@@ -578,6 +649,8 @@ static int armlinux_register_image_handler(void)
register_image_handler(&aimage_handler);
binfmt_register(&binfmt_aimage_hook);
}
+   if (IS_BUILTIN(CONFIG_CMD_BOOTM_FITIMAGE))
+   register_image_handler(&arm_fit_handler);
binfmt_register(&binfmt_arm_zimage_hook);
binfmt_register(&binfmt_barebox_hook);
 
diff --git a/commands/Kconfig b/commands/Kconfig
index 1743670ed33c..3e4a32a416c7 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -418,6 +418,16 @@ config CMD_BOOTM_AIMAGE
help
  Support using Android Images.
 
+config CMD_BOOTM_FITIMAGE
+   bool
+   prompt "FIT image support"
+   select FITIMAGE
+   depends on CMD_BOOTM && ARM
+   help
+ Support using FIT Images. Have a look at the u-boot source
+ tree in the "doc/uImage.FIT" folder for more information:
+ http://git.denx.de/?p=u-boot.git;a=tree;f=doc/uImage.FIT
+
 config CMD_BO

[PATCH v2 0/3] FIT Support

2016-01-06 Thread Marc Kleine-Budde
Hello,

taking over Jan's work. This is the current state of the FIT support patches,
which are used in production on a custom mx6 board. The FIT loading code has
basically been rewritten from scratch, as the original U-Boot code uses libfdt
and barebox's DT support works on an in-memory tree.

These patches apply on origin/next.
The two patches from Sascha are required for the basic RSA support.
The third patch adds FIT support.

Changes since v1:
- do_bootm_arm_fit(): remove NULL check in cleanup path
- Kconfig: add pointer to u-boot documentation
- fit_verify_signature(): make pr_info message more descriptive
- fit_verify_hash(): streamlined return values
- fit_open_image(): simplified description printing

regards,
Marc



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 1/3] crypto: add digest_alloc_by_algo()

2016-01-06 Thread Marc Kleine-Budde
From: Sascha Hauer 

In barebox the function digest_alloc() allocates a digest based on a string.
When a subsystem already uses an integer value to identify a digest it makes no
sense to create a string and pass it to digest_alloc(), where it is parsed
again. This patch adds the possibility to get a digest by an enum.

Signed-off-by: Sascha Hauer 
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/crypto/sha1_glue.c   |  1 +
 arch/arm/crypto/sha256_glue.c |  2 ++
 crypto/digest.c   | 43 ++-
 crypto/md5.c  |  1 +
 crypto/sha1.c |  1 +
 crypto/sha2.c |  2 ++
 crypto/sha4.c |  2 ++
 include/digest.h  | 23 +++
 8 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/arch/arm/crypto/sha1_glue.c b/arch/arm/crypto/sha1_glue.c
index 176aa9ec69e0..57cd9d101458 100644
--- a/arch/arm/crypto/sha1_glue.c
+++ b/arch/arm/crypto/sha1_glue.c
@@ -119,6 +119,7 @@ static struct digest_algo m = {
.name   =   "sha1",
.driver_name=   "sha1-asm",
.priority   =   150,
+   .algo   =   HASH_ALGO_SHA1,
},
 
.init   =   sha1_init,
diff --git a/arch/arm/crypto/sha256_glue.c b/arch/arm/crypto/sha256_glue.c
index f8086f6ac7f7..e649609a8eef 100644
--- a/arch/arm/crypto/sha256_glue.c
+++ b/arch/arm/crypto/sha256_glue.c
@@ -173,6 +173,7 @@ static struct digest_algo sha224 = {
.name   =   "sha224",
.driver_name=   "sha224-asm",
.priority   =   150,
+   .algo   =   HASH_ALGO_SHA224,
},
 
.length =   SHA224_DIGEST_SIZE,
@@ -195,6 +196,7 @@ static struct digest_algo sha256 = {
.name   =   "sha256",
.driver_name=   "sha256-asm",
.priority   =   150,
+   .algo   =   HASH_ALGO_SHA256,
},
 
.length =   SHA256_DIGEST_SIZE,
diff --git a/crypto/digest.c b/crypto/digest.c
index a90e4ff79f89..46600f246ece 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -116,7 +116,27 @@ static struct digest_algo *digest_algo_get_by_name(const 
char *name)
list_for_each_entry(tmp, &digests, list) {
if (strcmp(tmp->base.name, name) != 0)
continue;
-   
+
+   if (tmp->base.priority <= priority)
+   continue;
+
+   d = tmp;
+   priority = tmp->base.priority;
+   }
+
+   return d;
+}
+
+static struct digest_algo *digest_algo_get_by_algo(enum hash_algo algo)
+{
+   struct digest_algo *d = NULL;
+   struct digest_algo *tmp;
+   int priority = -1;
+
+   list_for_each_entry(tmp, &digests, list) {
+   if (tmp->base.algo != algo)
+   continue;
+
if (tmp->base.priority <= priority)
continue;
 
@@ -160,6 +180,27 @@ struct digest *digest_alloc(const char *name)
 }
 EXPORT_SYMBOL_GPL(digest_alloc);
 
+struct digest *digest_alloc_by_algo(enum hash_algo hash_algo)
+{
+   struct digest *d;
+   struct digest_algo *algo;
+
+   algo = digest_algo_get_by_algo(hash_algo);
+   if (!algo)
+   return NULL;
+
+   d = xzalloc(sizeof(*d));
+   d->algo = algo;
+   d->ctx = xzalloc(algo->ctx_length);
+   if (d->algo->alloc(d)) {
+   digest_free(d);
+   return NULL;
+   }
+
+   return d;
+}
+EXPORT_SYMBOL_GPL(digest_alloc_by_algo);
+
 void digest_free(struct digest *d)
 {
if (!d)
diff --git a/crypto/md5.c b/crypto/md5.c
index 23892babce6c..f8f52bf4a505 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -293,6 +293,7 @@ static struct digest_algo md5 = {
.name   = "md5",
.driver_name= "md5-generic",
.priority   = 0,
+   .algo   = HASH_ALGO_MD5,
},
.init = digest_md5_init,
.update = digest_md5_update,
diff --git a/crypto/sha1.c b/crypto/sha1.c
index a3de2719d8fc..cbde4d28e475 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -287,6 +287,7 @@ static struct digest_algo m = {
.name   =   "sha1",
.driver_name=   "sha1-generic",
.priority   =   0,
+   .algo   =   HASH_ALGO_SHA1,
},
 
.init   = sha1_init,
diff --git a/crypto/sha2.c b/crypto/sha2.c
index 6ac552702807..df566c8a4b3b 100644
--- a/crypto/sha2.c
+++ b/crypto/sha2.c
@@ -327,6 +327,7 @@ static struct digest_algo m224 = {
.name   =   "sha224",
   

Re: [PATCH 3/3] bootm: add initial FIT support

2016-01-06 Thread Marc Kleine-Budde
On 01/05/2016 09:28 PM, Trent Piepho wrote:

Thanks for the review. Comments inline.

> On Tue, 2016-01-05 at 09:11 +0100, Marc Kleine-Budde wrote:
>> +static int do_bootm_arm_fit(struct image_data *data)
>> +{
>> +struct fit_handle *handle;
>> +int ret;
>> +unsigned long mem_free;
>> +unsigned long mem_start, mem_size;
>> +
>> +handle = fit_open(data->os_file, data->os_num, data->verbose);
>> +if (!handle)
>> +return -EINVAL;
>> +
>> +ret = sdram_start_and_size(&mem_start, &mem_size);
>> +if (ret)
>> +return ret;
>> +
>> +/* no support for custom load address */
>> +data->os_address = mem_start + PAGE_ALIGN(handle->kernel_size * 4);
>> +data->os_res = request_sdram_region("fit-kernel", data->os_address, 
>> handle->kernel_size);
>> +if (!data->os_res) {
>> +pr_err("Cannot request region 0x%08lx - 0x%08lx\n",
>> +data->os_address, handle->kernel_size);
>> +ret = -ENOMEM;
>> +goto err_out;
>> +}
>> +memcpy((void *)data->os_res->start, handle->kernel, 
>> handle->kernel_size);
>> +
>> +/*
>> + * Put oftree/initrd close behind compressed kernel image to avoid
>> + * placing it outside of the kernels lowmem.
>> + */
>> +if (handle->initrd_size) {
>> +data->initrd_address = PAGE_ALIGN(data->os_res->end + SZ_1M);
>> +data->initrd_res = request_sdram_region("fit-initrd", 
>> data->initrd_address, handle->initrd_size);
>> +if (!data->initrd_res) {
>> +ret = -ENOMEM;
>> +goto err_out;
>> +}
>> +memcpy((void *)data->initrd_res->start, handle->initrd, 
>> handle->initrd_size);
>> +}
>> +
>> +data->of_root_node = of_unflatten_dtb(handle->oftree);
>> +if (!data->of_root_node) {
>> +pr_err("unable to unflatten devicetree\n");
>> +ret = -EINVAL;
>> +goto err_out;
>> +}
>> +
>> +/*
>> + * Put devicetree right after initrd if present or after the kernel
>> + * if not.
>> + */
>> +if (data->initrd_res)
>> +mem_free = PAGE_ALIGN(data->initrd_res->end);
>> +else
>> +mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);
> Why the extra 1M?

Let's see if Jan remembers, he has coded this.

>> +
>> +return __do_bootm_linux(data, mem_free, 0);
>> +
>> +err_out:
>> +if (handle)
>> +fit_close(handle);
> 
> handle can't be NULL, it's been dereferenced in every path that gets
> there.

correct. tnx.

> 
>> +return ret;
>> +}
>> +
>> +static struct image_handler arm_fit_handler = {
> 
> Can this be const?

No, because it has a struct list_head embedded.

>> +.name = "FIT image",
>> +.bootm = do_bootm_arm_fit,
>> +.filetype = filetype_oftree,
>> +};
>> +
>>  static struct binfmt_hook binfmt_aimage_hook = {
>>  .type = filetype_aimage,
>>  .exec = "bootm",
>> @@ -578,6 +650,8 @@ static int armlinux_register_image_handler(void)
>>  register_image_handler(&aimage_handler);
>>  binfmt_register(&binfmt_aimage_hook);
>>  }
>> +if (IS_BUILTIN(CONFIG_CMD_BOOTM_FITIMAGE))
>> +register_image_handler(&arm_fit_handler);
>>  binfmt_register(&binfmt_arm_zimage_hook);
>>  binfmt_register(&binfmt_barebox_hook);
>>  
>> diff --git a/commands/Kconfig b/commands/Kconfig
>> index 1743670ed33c..b89627209f5a 100644
>> --- a/commands/Kconfig
>> +++ b/commands/Kconfig
>> @@ -418,6 +418,14 @@ config CMD_BOOTM_AIMAGE
>>  help
>>Support using Android Images.
>>  
>> +config CMD_BOOTM_FITIMAGE
>> +bool
>> +prompt "FIT image support"
>> +select FITIMAGE
>> +depends on CMD_BOOTM && ARM
>> +help
>> +  Support using FIT Images.
> 
> Perhaps a link about FIT images or a pointer to a file in Documentation
> could go here?

OK.

>> +/*
>> + * The consistency of the FTD structure was already checked by 
>> of_unflatten_dtb()
>> + */
>> +static int fit_verify_signature(struct device_node *

Re: [PATCH 1/3] crypto: add enum

2016-01-06 Thread Marc Kleine-Budde
On 01/05/2016 05:54 PM, Sam Ravnborg wrote:
> On Tue, Jan 05, 2016 at 09:11:01AM +0100, Marc Kleine-Budde wrote:
>> From: Sascha Hauer 
>>
>> Signed-off-by: Sascha Hauer 
>> Signed-off-by: Marc Kleine-Budde 
> 
> The subject and the patch description could use some
> more love and care.

Good idea.

>> diff --git a/crypto/digest.c b/crypto/digest.c
>> index a90e4ff79f89..46600f246ece 100644
>> --- a/crypto/digest.c
>> +++ b/crypto/digest.c
>> @@ -116,7 +116,27 @@ static struct digest_algo 
>> *digest_algo_get_by_name(const char *name)
>>  list_for_each_entry(tmp, &digests, list) {
>>  if (strcmp(tmp->base.name, name) != 0)
>>  continue;
>> -
>> +
>> +if (tmp->base.priority <= priority)
>> +continue;
>> +
>> +d = tmp;
>> +priority = tmp->base.priority;
>> +}
>> +
>> +return d;
>> +}
>> +
>> +static struct digest_algo *digest_algo_get_by_algo(enum hash_algo algo)
>> +{
>> +struct digest_algo *d = NULL;
>> +struct digest_algo *tmp;
>> +int priority = -1;
>> +
>> +list_for_each_entry(tmp, &digests, list) {
>> +if (tmp->base.algo != algo)
>> +continue;
>> +
>>  if (tmp->base.priority <= priority)
>>  continue;
>>  
>> @@ -160,6 +180,27 @@ struct digest *digest_alloc(const char *name)
>>  }
>>  EXPORT_SYMBOL_GPL(digest_alloc);
>>  
>> +struct digest *digest_alloc_by_algo(enum hash_algo hash_algo)
>> +{
>> +struct digest *d;
>> +struct digest_algo *algo;
>> +
>> +algo = digest_algo_get_by_algo(hash_algo);
>> +if (!algo)
>> +return NULL;
>> +
>> +d = xzalloc(sizeof(*d));
>> +d->algo = algo;
>> +d->ctx = xzalloc(algo->ctx_length);
> 
> Neither allocations are checked for failure.

If xzalloc fails barebox will go into OOM and throw a backtrace.

Marc
-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 3/3] bootm: add initial FIT support

2016-01-05 Thread Marc Kleine-Budde
On 01/05/2016 02:05 PM, Yegor Yefremov wrote:
>>>>> What about unsigned images?
>>>>
>>>> That's not our use case. We use plain zImages instead.
>>>
>>> The solution would be to introduce an option like in U-Boot?
>>>
>>> CONFIG_FIT_SIGNATURE:
>>>
>>> This option enables signature verification of FIT uImages,
>>> using a hash signed and verified using RSA. If
>>> CONFIG_SHA_PROG_HW_ACCEL is defined, i.e support for progressive
>>> hashing is available using hardware, RSA library will use it.
>>> See doc/uImage.FIT/signature.txt for more details.
>>
>> Technically possible, but I'm not sure what are the benefits of using
>> fit images, if you don't need signatures. barebox implements
>> freedesktop.org's bootspec and this is IMHO the way to go.
> 
> For me FIT is just a way to have a kernel and a bunch of device tree
> blobs in one file. Signed or not signed is an option for me. Just like
> U-Boot implements it. This is user responsibility.

Send patches. :D

> In my use case I just read device ID from EEPROM, load my
> kernel-fit.itb and select needed DTB via this ID. This way I have only
> one SD card image, that can be run on more, than 10 different devices
> using the same core module.

>>>>> I also get: unsupported algo crc32
>>>>> Is it intended to be supported?
>>>>
>>>> Not for our usecase - feel free to add crc32 support.
>>>
>>> OK.
>>>
>>> But what about FIT configuration selection syntax?
>>
>> What's this?
> 
> Have you seen my comments to this patch regarding
> fit_open_configuration() routine?

sorry - I've missed that. Too many quoted lines. :D

>> > +static int fit_open_configuration(struct fit_handle *handle, int num)
>> > +{
>> > +   struct device_node *conf_node = NULL, *sig_node;
>> > +   char unit_name[10];
>> > +   const char *unit, *desc;
>> > +   int ret, level;
>> > +
>> > +   conf_node = of_get_child_by_name(handle->root, "configurations");
>> > +   if (!conf_node)
>> > +   return -ENOENT;
>> > +
>> > +   if (num) {
>> > +   snprintf(unit_name, sizeof(unit_name), "conf@%d", num);
> 
> This is not working for my *.its file:
> https://github.com/visionsystemsgmbh/onrisc_br_bsp/blob/master/board/vscom/baltos/kernel-fit.its
> U-Boot is working with bootm ${loadaddr}#conf${board_name}
> 
> For Barebox I've changed this line to
> 
> snprintf(unit_name, sizeof(unit_name), "conf%d@1", num)
> 
> This is how I start Linux: bootm /boot/kernel-fit.itb@$global.board.id
> 
> What is the standard for providing FIT configuration?

Don't know. Is there a spec in the u-boot sources, otherwise use the code.

Marc
-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 3/3] bootm: add initial FIT support

2016-01-05 Thread Marc Kleine-Budde
On 01/05/2016 11:40 AM, Yegor Yefremov wrote:
> On Tue, Jan 5, 2016 at 11:32 AM, Marc Kleine-Budde  
> wrote:
>> On 01/05/2016 11:28 AM, Yegor Yefremov wrote:
>>> Hi Marc,
>>>
>>> thanks for reposting the patches.
>>>
>>> On Tue, Jan 5, 2016 at 9:11 AM, Marc Kleine-Budde  
>>> wrote:
>>>> From: Jan Luebbe 
>>>>
>>>> This implementation is inspired by U-Boot's FIT support. Instead of
>>>> using libfdt (which does not exist in barebox), configuration signatures
>>>> are verified by using a simplified DT parser based on barebox's own
>>>> code.
>>>>
>>>> Currently, only signed configurations with hashed images are supported,
>>>> as the other variants are less useful for verified boot. Compatible FIT
>>>> images can be created using U-Boot's mkimage tool.
>>>
>>> What about unsigned images?
>>
>> That's not our use case. We use plain zImages instead.
> 
> The solution would be to introduce an option like in U-Boot?
> 
> CONFIG_FIT_SIGNATURE:
> 
> This option enables signature verification of FIT uImages,
> using a hash signed and verified using RSA. If
> CONFIG_SHA_PROG_HW_ACCEL is defined, i.e support for progressive
> hashing is available using hardware, RSA library will use it.
> See doc/uImage.FIT/signature.txt for more details.

Technically possible, but I'm not sure what are the benefits of using
fit images, if you don't need signatures. barebox implements
freedesktop.org's bootspec and this is IMHO the way to go.

>>> I also get: unsupported algo crc32
>>> Is it intended to be supported?
>>
>> Not for our usecase - feel free to add crc32 support.
> 
> OK.
> 
> But what about FIT configuration selection syntax?

What's this?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 3/3] bootm: add initial FIT support

2016-01-05 Thread Marc Kleine-Budde
On 01/05/2016 11:28 AM, Yegor Yefremov wrote:
> Hi Marc,
> 
> thanks for reposting the patches.
> 
> On Tue, Jan 5, 2016 at 9:11 AM, Marc Kleine-Budde  wrote:
>> From: Jan Luebbe 
>>
>> This implementation is inspired by U-Boot's FIT support. Instead of
>> using libfdt (which does not exist in barebox), configuration signatures
>> are verified by using a simplified DT parser based on barebox's own
>> code.
>>
>> Currently, only signed configurations with hashed images are supported,
>> as the other variants are less useful for verified boot. Compatible FIT
>> images can be created using U-Boot's mkimage tool.
> 
> What about unsigned images?

That's not our use case. We use plain zImages instead.

> I also get: unsupported algo crc32
> Is it intended to be supported?

Not for our usecase - feel free to add crc32 support.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/3] crypto: add RSA support

2016-01-05 Thread Marc Kleine-Budde
From: Sascha Hauer 

Signed-off-by: Sascha Hauer 
Signed-off-by: Marc Kleine-Budde 
---
 crypto/Kconfig  |   3 +
 crypto/Makefile |   1 +
 crypto/rsa.c| 420 
 include/asm-generic/errno.h |   5 +
 include/rsa.h   |  54 ++
 5 files changed, 483 insertions(+)
 create mode 100644 crypto/rsa.c
 create mode 100644 include/rsa.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 41145a312d8e..ca6f03a1edd1 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -87,6 +87,9 @@ config CRYPTO_PBKDF2
select DIGEST_SHA1_GENERIC
bool
 
+config CRYPTO_RSA
+   bool
+
 config CRYPTO_KEYSTORE
bool "Keystore"
help
diff --git a/crypto/Makefile b/crypto/Makefile
index c6d17787ca4e..b4fb3d8da01f 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -11,4 +11,5 @@ obj-$(CONFIG_DIGEST_SHA384_GENERIC)   += sha4.o
 obj-$(CONFIG_DIGEST_SHA512_GENERIC)+= sha4.o
 
 obj-$(CONFIG_CRYPTO_PBKDF2)+= pbkdf2.o
+obj-$(CONFIG_CRYPTO_RSA)   += rsa.o
 obj-$(CONFIG_CRYPTO_KEYSTORE)  += keystore.o
diff --git a/crypto/rsa.c b/crypto/rsa.c
new file mode 100644
index ..3caee3ce7525
--- /dev/null
+++ b/crypto/rsa.c
@@ -0,0 +1,420 @@
+/*
+ * Copyright (c) 2013, Google Inc.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define UINT64_MULT32(v, multby)  (((uint64_t)(v)) * ((uint32_t)(multby)))
+
+#define get_unaligned_be32(a) fdt32_to_cpu(*(uint32_t *)a)
+#define put_unaligned_be32(a, b) (*(uint32_t *)(b) = cpu_to_fdt32(a))
+
+/* Default public exponent for backward compatibility */
+#define RSA_DEFAULT_PUBEXP 65537
+
+/* This is the minimum/maximum key size we support, in bits */
+#define RSA_MIN_KEY_BITS   1024
+#define RSA_MAX_KEY_BITS   4096
+
+/**
+ * subtract_modulus() - subtract modulus from the given value
+ *
+ * @key:   Key containing modulus to subtract
+ * @num:   Number to subtract modulus from, as little endian word array
+ */
+static void subtract_modulus(const struct rsa_public_key *key, uint32_t num[])
+{
+   int64_t acc = 0;
+   uint i;
+
+   for (i = 0; i < key->len; i++) {
+   acc += (uint64_t)num[i] - key->modulus[i];
+   num[i] = (uint32_t)acc;
+   acc >>= 32;
+   }
+}
+
+/**
+ * greater_equal_modulus() - check if a value is >= modulus
+ *
+ * @key:   Key containing modulus to check
+ * @num:   Number to check against modulus, as little endian word array
+ * @return 0 if num < modulus, 1 if num >= modulus
+ */
+static int greater_equal_modulus(const struct rsa_public_key *key,
+uint32_t num[])
+{
+   int i;
+
+   for (i = (int)key->len - 1; i >= 0; i--) {
+   if (num[i] < key->modulus[i])
+   return 0;
+   if (num[i] > key->modulus[i])
+   return 1;
+   }
+
+   return 1;  /* equal */
+}
+
+/**
+ * montgomery_mul_add_step() - Perform montgomery multiply-add step
+ *
+ * Operation: montgomery result[] += a * b[] / n0inv % modulus
+ *
+ * @key:   RSA key
+ * @result:Place to put result, as little endian word array
+ * @a: Multiplier
+ * @b: Multiplicand, as little endian word array
+ */
+static void montgomery_mul_add_step(const struct rsa_public_key *key,
+   uint32_t result[], const uint32_t a, const uint32_t b[])
+{
+   uint64_t acc_a, acc_b;
+   uint32_t d0;
+   uint i;
+
+   acc_a = (uint64_t)a * b[0] + result[0];
+   d0 = (uint32_t)acc_a * key->n0inv;
+   acc_b = (uint64_t)d0 * key->modulus[0] + (uint32_t)acc_a;
+   for (i = 1; i < key->len; i++) {
+   acc_a = (acc_a >> 32) + (uint64_t)a * b[i] + result[i];
+   acc_b = (acc_b >> 32) + (uint64_t)d0 * key->modulus[i] +
+   (uint32_t)acc_a;
+   result[i - 1] = (uint32_t)acc_b;
+   }
+
+   acc_a = (acc_a >> 32) + (acc_b >> 32);
+
+   result[i - 1] = (uint32_t)acc_a;
+
+   if (acc_a >> 32)
+   subtract_modulus(key, result);
+}
+
+/**
+ * montgomery_mul() - Perform montgomery mutitply
+ *
+ * Operation: montgomery result[] = a[] * b[] / n0inv % modulus
+ *
+ * @key:   RSA key
+ * @result:Place to put result, as little endian word array
+ * @a: Multiplier, as little endian word array
+ * @b: Multiplicand, as little endian word array
+ */
+static void montgomery_mul(const struct rsa_public_key *key,
+   uint32_t result[], uint32_t a[], const uint32_t b[])
+{
+   uint i;
+
+   for (i = 0; i < key->len; ++i)
+   result[i] = 0;
+   for (i = 0; i < key->len; ++i)
+   montgomery_mul_add_step(key,

Re: [RFC 0/4] FIT Support

2016-01-05 Thread Marc Kleine-Budde
On 11/13/2015 01:54 PM, Sascha Hauer wrote:
> I think we should mainline them quite soon, they are more helpful
> in-tree.
> 
> Steffen, Marc, Markus? Any volunteers to resend them?

Done.

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 3/3] bootm: add initial FIT support

2016-01-05 Thread Marc Kleine-Budde
From: Jan Luebbe 

This implementation is inspired by U-Boot's FIT support. Instead of
using libfdt (which does not exist in barebox), configuration signatures
are verified by using a simplified DT parser based on barebox's own
code.

Currently, only signed configurations with hashed images are supported,
as the other variants are less useful for verified boot. Compatible FIT
images can be created using U-Boot's mkimage tool.

Signed-off-by: Jan Luebbe 
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/lib/bootm.c |  74 +++
 commands/Kconfig |   8 +
 common/Kconfig   |   6 +
 common/Makefile  |   1 +
 common/image-fit.c   | 590 +++
 include/image-fit.h  |  42 
 6 files changed, 721 insertions(+)
 create mode 100644 common/image-fit.c
 create mode 100644 include/image-fit.h

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 7bb9b436560c..22c2d6017e7c 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -553,6 +553,78 @@ BAREBOX_MAGICVAR(aimage_noverwrite_bootargs, "Disable 
overwrite of the bootargs
 BAREBOX_MAGICVAR(aimage_noverwrite_tags, "Disable overwrite of the tags addr 
with the one present in aimage");
 #endif
 
+#include 
+
+static int do_bootm_arm_fit(struct image_data *data)
+{
+   struct fit_handle *handle;
+   int ret;
+   unsigned long mem_free;
+   unsigned long mem_start, mem_size;
+
+   handle = fit_open(data->os_file, data->os_num, data->verbose);
+   if (!handle)
+   return -EINVAL;
+
+   ret = sdram_start_and_size(&mem_start, &mem_size);
+   if (ret)
+   return ret;
+
+   /* no support for custom load address */
+   data->os_address = mem_start + PAGE_ALIGN(handle->kernel_size * 4);
+   data->os_res = request_sdram_region("fit-kernel", data->os_address, 
handle->kernel_size);
+   if (!data->os_res) {
+   pr_err("Cannot request region 0x%08lx - 0x%08lx\n",
+   data->os_address, handle->kernel_size);
+   ret = -ENOMEM;
+   goto err_out;
+   }
+   memcpy((void *)data->os_res->start, handle->kernel, 
handle->kernel_size);
+
+   /*
+* Put oftree/initrd close behind compressed kernel image to avoid
+* placing it outside of the kernels lowmem.
+*/
+   if (handle->initrd_size) {
+   data->initrd_address = PAGE_ALIGN(data->os_res->end + SZ_1M);
+   data->initrd_res = request_sdram_region("fit-initrd", 
data->initrd_address, handle->initrd_size);
+   if (!data->initrd_res) {
+   ret = -ENOMEM;
+   goto err_out;
+   }
+   memcpy((void *)data->initrd_res->start, handle->initrd, 
handle->initrd_size);
+   }
+
+   data->of_root_node = of_unflatten_dtb(handle->oftree);
+   if (!data->of_root_node) {
+   pr_err("unable to unflatten devicetree\n");
+   ret = -EINVAL;
+   goto err_out;
+   }
+
+   /*
+* Put devicetree right after initrd if present or after the kernel
+* if not.
+*/
+   if (data->initrd_res)
+   mem_free = PAGE_ALIGN(data->initrd_res->end);
+   else
+   mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);
+
+   return __do_bootm_linux(data, mem_free, 0);
+
+err_out:
+   if (handle)
+   fit_close(handle);
+   return ret;
+}
+
+static struct image_handler arm_fit_handler = {
+.name = "FIT image",
+.bootm = do_bootm_arm_fit,
+.filetype = filetype_oftree,
+};
+
 static struct binfmt_hook binfmt_aimage_hook = {
.type = filetype_aimage,
.exec = "bootm",
@@ -578,6 +650,8 @@ static int armlinux_register_image_handler(void)
register_image_handler(&aimage_handler);
binfmt_register(&binfmt_aimage_hook);
}
+   if (IS_BUILTIN(CONFIG_CMD_BOOTM_FITIMAGE))
+   register_image_handler(&arm_fit_handler);
binfmt_register(&binfmt_arm_zimage_hook);
binfmt_register(&binfmt_barebox_hook);
 
diff --git a/commands/Kconfig b/commands/Kconfig
index 1743670ed33c..b89627209f5a 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -418,6 +418,14 @@ config CMD_BOOTM_AIMAGE
help
  Support using Android Images.
 
+config CMD_BOOTM_FITIMAGE
+   bool
+   prompt "FIT image support"
+   select FITIMAGE
+   depends on CMD_BOOTM && ARM
+   help
+ Support using FIT Images.
+
 config CMD_BOOTU
tristate
default y
diff --git a/common/Kconfig b/common/Kconfig
index 8e7950968c3e..d824b5e35f04 100644
--- a/common/Kconfig
+++ b/commo

[PATCH 0/3] FIT Support

2016-01-05 Thread Marc Kleine-Budde
Hello,

taking over Jan's work. This is the current state of the FIT support patches,
which are used in production on a custom mx6 board. The FIT loading code has
basically been rewritten from scratch, as the original U-Boot code uses libfdt
and barebox's DT support works on an in-memory tree.

These patches apply on origin/next.
The two patches from Sascha are required for the basic RSA support.
The third patch adds FIT support.

regards,
Marc


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/3] crypto: add enum

2016-01-05 Thread Marc Kleine-Budde
From: Sascha Hauer 

Signed-off-by: Sascha Hauer 
Signed-off-by: Marc Kleine-Budde 
---
 arch/arm/crypto/sha1_glue.c   |  1 +
 arch/arm/crypto/sha256_glue.c |  2 ++
 crypto/digest.c   | 43 ++-
 crypto/md5.c  |  1 +
 crypto/sha1.c |  1 +
 crypto/sha2.c |  2 ++
 crypto/sha4.c |  2 ++
 include/digest.h  | 23 +++
 8 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/arch/arm/crypto/sha1_glue.c b/arch/arm/crypto/sha1_glue.c
index 176aa9ec69e0..57cd9d101458 100644
--- a/arch/arm/crypto/sha1_glue.c
+++ b/arch/arm/crypto/sha1_glue.c
@@ -119,6 +119,7 @@ static struct digest_algo m = {
.name   =   "sha1",
.driver_name=   "sha1-asm",
.priority   =   150,
+   .algo   =   HASH_ALGO_SHA1,
},
 
.init   =   sha1_init,
diff --git a/arch/arm/crypto/sha256_glue.c b/arch/arm/crypto/sha256_glue.c
index f8086f6ac7f7..e649609a8eef 100644
--- a/arch/arm/crypto/sha256_glue.c
+++ b/arch/arm/crypto/sha256_glue.c
@@ -173,6 +173,7 @@ static struct digest_algo sha224 = {
.name   =   "sha224",
.driver_name=   "sha224-asm",
.priority   =   150,
+   .algo   =   HASH_ALGO_SHA224,
},
 
.length =   SHA224_DIGEST_SIZE,
@@ -195,6 +196,7 @@ static struct digest_algo sha256 = {
.name   =   "sha256",
.driver_name=   "sha256-asm",
.priority   =   150,
+   .algo   =   HASH_ALGO_SHA256,
},
 
.length =   SHA256_DIGEST_SIZE,
diff --git a/crypto/digest.c b/crypto/digest.c
index a90e4ff79f89..46600f246ece 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -116,7 +116,27 @@ static struct digest_algo *digest_algo_get_by_name(const 
char *name)
list_for_each_entry(tmp, &digests, list) {
if (strcmp(tmp->base.name, name) != 0)
continue;
-   
+
+   if (tmp->base.priority <= priority)
+   continue;
+
+   d = tmp;
+   priority = tmp->base.priority;
+   }
+
+   return d;
+}
+
+static struct digest_algo *digest_algo_get_by_algo(enum hash_algo algo)
+{
+   struct digest_algo *d = NULL;
+   struct digest_algo *tmp;
+   int priority = -1;
+
+   list_for_each_entry(tmp, &digests, list) {
+   if (tmp->base.algo != algo)
+   continue;
+
if (tmp->base.priority <= priority)
continue;
 
@@ -160,6 +180,27 @@ struct digest *digest_alloc(const char *name)
 }
 EXPORT_SYMBOL_GPL(digest_alloc);
 
+struct digest *digest_alloc_by_algo(enum hash_algo hash_algo)
+{
+   struct digest *d;
+   struct digest_algo *algo;
+
+   algo = digest_algo_get_by_algo(hash_algo);
+   if (!algo)
+   return NULL;
+
+   d = xzalloc(sizeof(*d));
+   d->algo = algo;
+   d->ctx = xzalloc(algo->ctx_length);
+   if (d->algo->alloc(d)) {
+   digest_free(d);
+   return NULL;
+   }
+
+   return d;
+}
+EXPORT_SYMBOL_GPL(digest_alloc_by_algo);
+
 void digest_free(struct digest *d)
 {
if (!d)
diff --git a/crypto/md5.c b/crypto/md5.c
index 23892babce6c..f8f52bf4a505 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -293,6 +293,7 @@ static struct digest_algo md5 = {
.name   = "md5",
.driver_name= "md5-generic",
.priority   = 0,
+   .algo   = HASH_ALGO_MD5,
},
.init = digest_md5_init,
.update = digest_md5_update,
diff --git a/crypto/sha1.c b/crypto/sha1.c
index a3de2719d8fc..cbde4d28e475 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -287,6 +287,7 @@ static struct digest_algo m = {
.name   =   "sha1",
.driver_name=   "sha1-generic",
.priority   =   0,
+   .algo   =   HASH_ALGO_SHA1,
},
 
.init   = sha1_init,
diff --git a/crypto/sha2.c b/crypto/sha2.c
index 6ac552702807..df566c8a4b3b 100644
--- a/crypto/sha2.c
+++ b/crypto/sha2.c
@@ -327,6 +327,7 @@ static struct digest_algo m224 = {
.name   =   "sha224",
.driver_name=   "sha224-generic",
.priority   =   0,
+   .algo   =   HASH_ALGO_SHA224,
},
 
.init   = sha224_init,
@@ -352,6 +353,7 @@ static struct digest_algo m256 = {

Re: [PATCH v3 2/9] of_path: add of_find_path_by_node()

2015-10-28 Thread Marc Kleine-Budde
On 10/28/2015 07:20 AM, Sascha Hauer wrote:
> On Sun, Oct 25, 2015 at 10:03:29PM +0100, Marc Kleine-Budde wrote:
>> This patch adds the function of_find_path_by_node(), which is similar to
>> of_find_path(), but it translates a device tree node into a barebox device 
>> path
>> directly.
>>
>> Signed-off-by: Marc Kleine-Budde 
>> ---
>>  drivers/of/of_path.c | 17 -
>>  include/of.h |  1 +
>>  2 files changed, 17 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
>> index ad64bee08af9..690390525919 100644
>> --- a/drivers/of/of_path.c
>> +++ b/drivers/of/of_path.c
>> @@ -126,7 +126,7 @@ static int __of_find_path(struct device_node *node, 
>> const char *propname, char *
>>  
>>  i = 1;
>>  
>> -while (1) {
>> +while (propname) {
>>  ret = of_property_read_string_index(node, propname, i++, &str);
>>  if (ret)
>>  break;
> 
> Is this hunk intentional? Is this a fix for something?

Yes, it's called with propname == NULL by int of_find_path_by_node():

> +int of_find_path_by_node(struct device_node *node, char **outpath, unsigned 
> flags) 
> +{ 
> + return __of_find_path(node, NULL, outpath, flags);


> +} 
> + 

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 0/8] state framework enhancements

2015-10-25 Thread Marc Kleine-Budde
Hello,

this series fixes some problems and enhances the state support in barebox.

Marc

changes since v2:
* 1: make __of_find_path() static (tnx, Sascha)
* 3: add missing assignment of of_path, causing fixup to fail
* 8: update documentation got hmac

changes since v1:
* 1+2: add of_find_path_by_phandle()
* 3: don't open code OF to device path conversion in state_probe use 
of_find_path_by_phandle() inst


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 7/9] crypto: add simple keystore

2015-10-25 Thread Marc Kleine-Budde
This patch adds a simple keystore to barebox. The keystore implements a simple
key-value store to hold arbitrary values.

Signed-off-by: Marc Kleine-Budde 
---
 crypto/Kconfig|  6 
 crypto/Makefile   |  1 +
 crypto/keystore.c | 80 +++
 include/crypto/keystore.h | 26 +++
 4 files changed, 113 insertions(+)
 create mode 100644 crypto/keystore.c
 create mode 100644 include/crypto/keystore.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 27047889a658..41145a312d8e 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -87,4 +87,10 @@ config CRYPTO_PBKDF2
select DIGEST_SHA1_GENERIC
bool
 
+config CRYPTO_KEYSTORE
+   bool "Keystore"
+   help
+ This is a simple keystore, which can be used to pass keys
+ between several components via simple interface.
+
 endmenu
diff --git a/crypto/Makefile b/crypto/Makefile
index f39de718e5e7..c6d17787ca4e 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_DIGEST_SHA384_GENERIC)   += sha4.o
 obj-$(CONFIG_DIGEST_SHA512_GENERIC)+= sha4.o
 
 obj-$(CONFIG_CRYPTO_PBKDF2)+= pbkdf2.o
+obj-$(CONFIG_CRYPTO_KEYSTORE)  += keystore.o
diff --git a/crypto/keystore.c b/crypto/keystore.c
new file mode 100644
index ..90b470fe6717
--- /dev/null
+++ b/crypto/keystore.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 Pengutronix, Marc Kleine-Budde 
+ *
+ * This program is free software; you can redistribute it and/or modify it 
under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+
+static LIST_HEAD(keystore_list);
+
+#define for_each_key(key) list_for_each_entry(key, &keystore_list, list)
+
+struct keystore_key {
+   struct list_head list;
+   const char *name;
+   const u8 *secret;
+   int secret_len;
+};
+
+static int keystore_compare(struct list_head *a, struct list_head *b)
+{
+   const char *na = list_entry(a, struct keystore_key, list)->name;
+   const char *nb = list_entry(b, struct keystore_key, list)->name;
+
+   return strcmp(na, nb);
+}
+
+/**
+ * @param[in] name Name of the secret to get
+ * @param[out] secret Double pointer to memory representing the secret, do 
_not_ free() after use
+ * @param[out] secret_len Pointer to length of the secret
+ */
+int keystore_get_secret(const char *name, const u8 **secret, int *secret_len)
+{
+   struct keystore_key *key;
+
+   for_each_key(key) {
+   if (!strcmp(name, key->name)) {
+   if (!secret || !secret_len)
+   return 0;
+
+   *secret = key->secret;
+   *secret_len = key->secret_len;
+
+   return 0;
+   }
+   }
+
+   return -ENOENT;
+}
+
+/**
+ * @param[in] name Name of the secret to set
+ * @param[in] secret Pointer to memory holding the secret
+ * @param[in] secret_len Length of the secret
+ */
+int keystore_set_secret(const char *name, const u8 *secret, int secret_len)
+{
+   struct keystore_key *key;
+   int ret;
+
+   /* check if key is already in store */
+   ret = keystore_get_secret(name, NULL, NULL);
+   if (!ret)
+   return -EBUSY;
+
+   key = xzalloc(sizeof(*key));
+   INIT_LIST_HEAD(&key->list);
+   key->name = xstrdup(name);
+   key->secret = xmemdup(secret, secret_len);
+   key->secret_len = secret_len;
+
+   list_add_sort(&key->list, &keystore_list, keystore_compare);
+
+   return 0;
+}
diff --git a/include/crypto/keystore.h b/include/crypto/keystore.h
new file mode 100644
index ..29915854b851
--- /dev/null
+++ b/include/crypto/keystore.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2015 Pengutronix, Marc Kleine-Budde 
+ *
+ * This program is free software; you can redistribute it and/or modify it 
under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+
+#ifndef __CRYPTO_KEYSTORE_H
+#define __CRYPTO_KEYSTORE_H
+
+#ifdef CONFIG_CRYPTO_KEYSTORE
+int keystore_get_secret(const char *name, const u8 **secret, int *secret_len);
+int keystore_set_secret(const char *name, const u8 *secret, int secret_len);
+#else
+static inline int keystore_get_secret(const char *name, const u8 **secret, int 
*secret_len)
+{
+   return -EINVAL;
+}
+static inline int keystore_set_secret(const char *name, const u8 *secret, int 
secret_len)
+{
+   return 0;
+}
+#endif
+
+#endif
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 3/9] state: make use of of_find_path_by_node() and add return -EPROBE_DEFER if device is not available

2015-10-25 Thread Marc Kleine-Budde
Signed-off-by: Uwe Kleine-König 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/misc/state.c | 31 +--
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/drivers/misc/state.c b/drivers/misc/state.c
index f3e366480fa2..22551478e651 100644
--- a/drivers/misc/state.c
+++ b/drivers/misc/state.c
@@ -52,34 +52,21 @@ static int state_probe(struct device_d *dev)
/* guess if of_path is a path, not a phandle */
if (of_path[0] == '/' && len > 1) {
ret = of_find_path(np, "backend", &path, 0);
-   if (ret)
-   goto out_release;
} else {
-   struct device_d *dev;
-   struct cdev *cdev;
 
partition_node = of_parse_phandle(np, "backend", 0);
-   if (!partition_node) {
-   ret = -ENODEV;
-   goto out_release;
-   }
-
-   dev = of_find_device_by_node(partition_node);
-   if (!list_is_singular(&dev->cdevs)) {
-   ret = -ENODEV;
-   goto out_release;
-   }
-
-   cdev = list_first_entry(&dev->cdevs, struct cdev, devices_list);
-   if (!cdev) {
-   ret = -ENODEV;
-   goto out_release;
-   }
-
-   path = asprintf("/dev/%s", cdev->name);
+   if (!partition_node)
+   return -EINVAL;
+
of_path = partition_node->full_name;
+   ret = of_find_path_by_node(partition_node, &path, 0);
}
 
+   if (ret == -ENODEV)
+   ret = -EPROBE_DEFER;
+   if (ret)
+   goto out_release;
+
ret = of_property_read_string(np, "backend-type", &backend_type);
if (ret) {
goto out_free;
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 1/9] of_path: of_find_path() factor out device detection logic into separate function

2015-10-25 Thread Marc Kleine-Budde
This patch factors out the device detection logic into separate function, so
that it can be used from another function.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/of/of_path.c | 81 
 1 file changed, 44 insertions(+), 37 deletions(-)

diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index 992972c9b52e..ad64bee08af9 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -106,6 +106,48 @@ out:
return ret;
 }
 
+static int __of_find_path(struct device_node *node, const char *propname, char 
**outpath, unsigned flags)
+{
+   struct of_path op = {};
+   const char *str;
+   bool add_bb = false;
+   int i, ret;
+
+   op.dev = of_find_device_by_node_path(node->full_name);
+   if (!op.dev) {
+   op.dev = of_find_device_by_node_path(node->parent->full_name);
+   if (!op.dev)
+   return -ENODEV;
+   }
+
+   device_detect(op.dev);
+
+   op.cdev = cdev_by_device_node(node);
+
+   i = 1;
+
+   while (1) {
+   ret = of_property_read_string_index(node, propname, i++, &str);
+   if (ret)
+   break;
+
+   ret = of_path_parse_one(&op, str);
+   if (ret)
+   return ret;
+   }
+
+   if (!op.cdev)
+   return -ENOENT;
+
+   if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
+   mtd_can_have_bb(op.cdev->mtd))
+   add_bb = true;
+
+   *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : "");
+
+   return 0;
+}
+
 /**
  * of_find_path - translate a path description in the devicetree to a barebox
  *path
@@ -134,11 +176,8 @@ out:
  */
 int of_find_path(struct device_node *node, const char *propname, char 
**outpath, unsigned flags)
 {
-   struct of_path op = {};
struct device_node *rnode;
-   const char *path, *str;
-   bool add_bb = false;
-   int i, ret;
+   const char *path;
 
path = of_get_property(node, propname, NULL);
if (!path)
@@ -148,37 +187,5 @@ int of_find_path(struct device_node *node, const char 
*propname, char **outpath,
if (!rnode)
return -ENODEV;
 
-   op.dev = of_find_device_by_node_path(rnode->full_name);
-   if (!op.dev) {
-   op.dev = of_find_device_by_node_path(rnode->parent->full_name);
-   if (!op.dev)
-   return -ENODEV;
-   }
-
-   device_detect(op.dev);
-
-   op.cdev = cdev_by_device_node(rnode);
-
-   i = 1;
-
-   while (1) {
-   ret = of_property_read_string_index(node, propname, i++, &str);
-   if (ret)
-   break;
-
-   ret = of_path_parse_one(&op, str);
-   if (ret)
-   return ret;
-   }
-
-   if (!op.cdev)
-   return -ENOENT;
-
-   if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
-   mtd_can_have_bb(op.cdev->mtd))
-   add_bb = true;
-
-   *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : "");
-
-   return 0;
+   return __of_find_path(rnode, propname, outpath, flags);
 }
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 9/9] state: backend_raw: add hamc support

2015-10-25 Thread Marc Kleine-Budde
This patch adds hmac support to the raw backend.

With this patch, modifications of the header or data of a state partition can
be detected, as the hmac woudln't match anymore. The hmac relies on a shared
secret, which is requested from the keystore, with keystore_get_secret() using
the name of the state partition as the "name" of the secret.

Signed-off-by: Marc Kleine-Budde 
---
 .../devicetree/bindings/barebox/barebox,state.rst  |  19 +++
 common/Kconfig |  18 +++
 common/state.c | 127 +++--
 3 files changed, 156 insertions(+), 8 deletions(-)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst 
b/Documentation/devicetree/bindings/barebox/barebox,state.rst
index 4c5b06db47f6..ef6602937232 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
@@ -32,6 +32,12 @@ Required properties:
 * ``backend``: describes where the data for this state is stored
 * ``backend-type``: should be ``raw`` or ``dtb``.
 
+Optional properties:
+
+* ``algo``: A HMAC algorithm used to detect manipulation of the data
+  or header, sensible values follow this pattern ``hmac()``,
+  e.g. ``hmac(sha256)``.
+
 Variable nodes
 --
 
@@ -105,6 +111,19 @@ devicetree description of the state itself, but 
additionally contains
 the actual values of the variables. Unlike the raw state backend the
 dtb state backend can describe itself.
 
+HMAC
+
+
+With the optional property ``algo = "hmac()";`` a HMAC algorithm
+can be defined to detect unauthorized modification of the state's
+header and/or data. For this to work the HMAC and the selected hash
+algorithm have to be compiled into barebox.
+
+The shared secret for the HMAC is requested via
+``keystore_get_secret()``, using the state's name, from the barebox
+simple keystore. It's up to the developer to populate the keystore via
+``keystore_set_secret()`` in beforehand.
+
 Frontend
 
 
diff --git a/common/Kconfig b/common/Kconfig
index 877d3855a203..8e7950968c3e 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -751,6 +751,24 @@ config STATE
select OFTREE
select PARAMETER
 
+config STATE_CRYPTO
+   bool "HMAC based authentication support"
+   depends on STATE
+   select CRYPTO_KEYSTORE
+   select DIGEST
+   select DIGEST_HMAC_GENERIC
+   help
+ This options enables HMAC based authentication support for
+ the state's header and data. This means the state framework
+ can verify both the data integrity and the authentication of
+ the state's header and data.
+
+ Don't forget to select a hash algorithm in the
+ crypto/digests menu.
+
+ See Documentation/devicetree/bindings/barebox/barebox,state.rst
+ for more information.
+
 config RESET_SOURCE
bool "detect Reset cause"
depends on GLOBALVAR
diff --git a/common/state.c b/common/state.c
index d37f4ab4b539..0a9204e099d0 100644
--- a/common/state.c
+++ b/common/state.c
@@ -15,6 +15,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -28,6 +29,8 @@
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -41,7 +44,7 @@ struct state_backend;
 
 struct state {
struct device_d dev;
-   const struct device_node *root;
+   struct device_node *root;
struct list_head variables;
const char *name;
struct list_head list;
@@ -55,6 +58,7 @@ struct state_backend {
const char *name;
const char *of_path;
const char *path;
+   struct digest *digest;
 };
 
 enum state_variable_type {
@@ -948,6 +952,16 @@ static int of_state_fixup(struct device_node *root, void 
*ctx)
if (ret)
goto out;
 
+   if (state->backend->digest) {
+   p = of_new_property(new_node, "algo",
+   digest_name(state->backend->digest),
+   strlen(digest_name(state->backend->digest)) 
+ 1);
+   if (!p) {
+   ret = -ENOMEM;
+   goto out;
+   }
+   }
+
/* address-cells + size-cells */
ret = of_property_write_u32(new_node, "#address-cells", 1);
if (ret)
@@ -1230,7 +1244,7 @@ int state_backend_dtb_file(struct state *state, const 
char *of_path, const char
 struct state_backend_raw {
struct state_backend backend;
unsigned long size_data; /* The raw data size (without header) */
-   unsigned long size_full; /* The size header + raw data */
+   unsigned long size_full; /* The size header + raw data + hmac */
unsigned long stride; /* The stride size in bytes of the copies */
off_t offset; /* offset in the storage file */

[PATCH v3 4/9] state: use name of device node as name if alias is not available

2015-10-25 Thread Marc Kleine-Budde
Wihtout this patch, when using more than one state device an alias is
mandatory, otherwise the there will be two state devices with the name state.

This patch fixes the limitation by using the device node's name if no alias is
defined.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/misc/state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/state.c b/drivers/misc/state.c
index 22551478e651..d46d5b941c4c 100644
--- a/drivers/misc/state.c
+++ b/drivers/misc/state.c
@@ -37,7 +37,7 @@ static int state_probe(struct device_d *dev)
 
alias = of_alias_get(np);
if (!alias)
-   alias = "state";
+   alias = np->name;
 
state = state_new_from_node(alias, np);
if (IS_ERR(state))
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 5/9] state: disable load command

2015-10-25 Thread Marc Kleine-Budde
From: Enrico Jorns 

Explicitly loading environment is not required as it will be loaded if
available during device probing

Signed-off-by: Enrico Jorns 
Signed-off-by: Marc Kleine-Budde 
---
 commands/state.c | 19 +--
 common/state.c   | 45 ++---
 drivers/misc/state.c |  1 -
 include/state.h  |  1 -
 4 files changed, 23 insertions(+), 43 deletions(-)

diff --git a/commands/state.c b/commands/state.c
index 59d1eb850215..4b51759e3ecd 100644
--- a/commands/state.c
+++ b/commands/state.c
@@ -21,26 +21,20 @@ static int do_state(int argc, char *argv[])
 {
int opt, ret = 0;
struct state *state = NULL;
-   int do_save = 0, do_load = 0;
+   int do_save = 0;
const char *statename = "state";
 
-   while ((opt = getopt(argc, argv, "sl")) > 0) {
+   while ((opt = getopt(argc, argv, "s")) > 0) {
switch (opt) {
case 's':
do_save = 1;
break;
-   case 'l':
-   do_load = 1;
-   break;
default:
return COMMAND_ERROR_USAGE;
}
}
 
-   if (do_save && do_load)
-   return COMMAND_ERROR_USAGE;
-
-   if (!do_save && !do_load) {
+   if (!do_save) {
state_info();
return 0;
}
@@ -56,8 +50,6 @@ static int do_state(int argc, char *argv[])
 
if (do_save)
ret = state_save(state);
-   else if (do_load)
-   ret = state_load(state);
 
return ret;
 }
@@ -67,13 +59,12 @@ BAREBOX_CMD_HELP_TEXT("Usage: state [OPTIONS] [STATENAME]")
 BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("options:")
 BAREBOX_CMD_HELP_OPT ("-s", "save state")
-BAREBOX_CMD_HELP_OPT ("-l", "load state")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(state)
.cmd= do_state,
-   BAREBOX_CMD_DESC("load and save state information")
-   BAREBOX_CMD_OPTS("[-sl] [STATENAME]")
+   BAREBOX_CMD_DESC("save state information")
+   BAREBOX_CMD_OPTS("[-s] [STATENAME]")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_HELP(cmd_state_help)
 BAREBOX_CMD_END
diff --git a/common/state.c b/common/state.c
index 117a6867597d..fdb5564af3bd 100644
--- a/common/state.c
+++ b/common/state.c
@@ -51,7 +51,6 @@ struct state {
 };
 
 struct state_backend {
-   int (*load)(struct state_backend *backend, struct state *state);
int (*save)(struct state_backend *backend, struct state *state);
const char *name;
const char *of_path;
@@ -1049,30 +1048,6 @@ int state_get_name(const struct state *state, char const 
**name)
 }
 
 /*
- * state_load - load a state from the backing store
- *
- * @state  The state instance to load
- */
-int state_load(struct state *state)
-{
-   int ret;
-
-   if (!state->backend)
-   return -ENOSYS;
-
-   ret = state->backend->load(state->backend, state);
-   if (ret) {
-   dev_warn(&state->dev, "load failed\n");
-   state->dirty = 1;
-   } else {
-   dev_info(&state->dev, "load successful\n");
-   state->dirty = 0;
-   }
-
-   return ret;
-}
-
-/*
  * state_save - save a state to the backing store
  *
  * @state  The state instance to save
@@ -1226,7 +1201,6 @@ int state_backend_dtb_file(struct state *state, const 
char *of_path, const char
backend_dtb = xzalloc(sizeof(*backend_dtb));
backend = &backend_dtb->backend;
 
-   backend->load = state_backend_dtb_load;
backend->save = state_backend_dtb_save;
backend->of_path = xstrdup(of_path);
backend->path = xstrdup(path);
@@ -1238,6 +1212,15 @@ int state_backend_dtb_file(struct state *state, const 
char *of_path, const char
if (!ret && !(meminfo.flags & MTD_NO_ERASE))
backend_dtb->need_erase = true;
 
+   ret = state_backend_dtb_load(backend, state);
+   if (ret) {
+   dev_warn(&state->dev, "load failed - using defaults\n");
+   } else {
+   dev_info(&state->dev, "load successful\n");
+   state->dirty = 0;
+   }
+
+   /* ignore return value of load() */
return 0;
 }
 
@@ -1548,7 +1531,6 @@ int state_backend_raw_file(struct state *state, const 
char *of_path,
backend_raw = xzalloc(sizeof(*backend_raw));
backend = &backend_raw->backend;
 
-   backend->load = state_backend_raw_load;
backend->save = state_backend_raw_save;
backend->of_path = xstrdup(of_path);
b

[PATCH v3 2/9] of_path: add of_find_path_by_node()

2015-10-25 Thread Marc Kleine-Budde
This patch adds the function of_find_path_by_node(), which is similar to
of_find_path(), but it translates a device tree node into a barebox device path
directly.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/of/of_path.c | 17 -
 include/of.h |  1 +
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index ad64bee08af9..690390525919 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -126,7 +126,7 @@ static int __of_find_path(struct device_node *node, const 
char *propname, char *
 
i = 1;
 
-   while (1) {
+   while (propname) {
ret = of_property_read_string_index(node, propname, i++, &str);
if (ret)
break;
@@ -149,6 +149,21 @@ static int __of_find_path(struct device_node *node, const 
char *propname, char *
 }
 
 /**
+ * of_find_path_by_node - translate a node in the devicetree to a
+ *   barebox device path
+ *
+ * @node: the node we're interested in
+ * @outpath: if this function returns 0 outpath will contain the path belonging
+ *   to the input path description. Must be freed with free().
+ * @flags: use OF_FIND_PATH_FLAGS_BB to return the .bb device if available
+ *
+ */
+int of_find_path_by_node(struct device_node *node, char **outpath, unsigned 
flags)
+{
+   return __of_find_path(node, NULL, outpath, flags);
+}
+
+/**
  * of_find_path - translate a path description in the devicetree to a barebox
  *path
  *
diff --git a/include/of.h b/include/of.h
index e0ebc39b742d..e60fe8982504 100644
--- a/include/of.h
+++ b/include/of.h
@@ -246,6 +246,7 @@ void of_add_memory_bank(struct device_node *node, bool 
dump, int r,
 struct device_d *of_find_device_by_node_path(const char *path);
 #define OF_FIND_PATH_FLAGS_BB 1/* return .bb device if 
available */
 int of_find_path(struct device_node *node, const char *propname, char 
**outpath, unsigned flags);
+int of_find_path_by_node(struct device_node *node, char **outpath, unsigned 
flags);
 int of_register_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
 int of_unregister_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
 struct device_node *of_find_node_by_alias(struct device_node *root,
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 8/9] state: prepare raw backend for hmac support

2015-10-25 Thread Marc Kleine-Budde
This patch cleans up the raw backend, so that adding hmac support in the next
patch is easier.

Signed-off-by: Marc Kleine-Budde 
---
 common/state.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/common/state.c b/common/state.c
index fdb5564af3bd..d37f4ab4b539 100644
--- a/common/state.c
+++ b/common/state.c
@@ -1254,7 +1254,7 @@ static int backend_raw_load_one(struct state_backend_raw 
*backend_raw,
struct backend_raw_header header = {};
unsigned long max_len;
int ret;
-   void *buf;
+   void *buf, *data;
 
max_len = backend_raw->stride;
 
@@ -1292,13 +1292,18 @@ static int backend_raw_load_one(struct 
state_backend_raw *backend_raw,
return -EINVAL;
}
 
-   buf = xzalloc(header.data_len);
+   buf = xzalloc(sizeof(header) + header.data_len);
+   data = buf + sizeof(header);
+
+   ret = lseek(fd, offset, SEEK_SET);
+   if (ret < 0)
+   goto out_free;
 
-   ret = read_full(fd, buf, header.data_len);
+   ret = read_full(fd, buf, sizeof(header) + header.data_len);
if (ret < 0)
goto out_free;
 
-   crc = crc32(0, buf, header.data_len);
+   crc = crc32(0, data, header.data_len);
if (crc != header.data_crc) {
dev_err(&state->dev,
"invalid crc, calculated 0x%08x, found 0x%08x\n",
@@ -1310,7 +1315,7 @@ static int backend_raw_load_one(struct state_backend_raw 
*backend_raw,
list_for_each_entry(sv, &state->variables, list) {
if (sv->start + sv->size > header.data_len)
break;
-   memcpy(sv->raw, buf + sv->start, sv->size);
+   memcpy(sv->raw, data + sv->start, sv->size);
}
 
free(buf);
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 6/9] crypto: Kconfig: add submenu for crypto related config options

2015-10-25 Thread Marc Kleine-Budde
Signed-off-by: Marc Kleine-Budde 
---
 crypto/Kconfig | 4 
 1 file changed, 4 insertions(+)

diff --git a/crypto/Kconfig b/crypto/Kconfig
index ef807dec68de..27047889a658 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1,3 +1,5 @@
+menu "Crypto support"
+
 config CRC32
bool
 
@@ -84,3 +86,5 @@ config CRYPTO_PBKDF2
select DIGEST
select DIGEST_SHA1_GENERIC
bool
+
+endmenu
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 8/8] state: backend_raw: add hamc support

2015-10-21 Thread Marc Kleine-Budde
On 10/21/2015 09:13 AM, Sascha Hauer wrote:
>> +static int state_backend_raw_file_init_digest(struct state *state, struct 
>> state_backend_raw *backend_raw)
>> +{
>> +struct digest *digest;
>> +const char *algo;
>> +const unsigned char *key;
>> +int key_len, ret;
>> +
>> +ret = of_property_read_string(state->root, "algo", &algo);
> 
> This needs an update to 
> Documentation/devicetree/bindings/barebox/barebox,state.rst

ok

>> +if (ret == -EINVAL) /* -EINVAL == does not exist */
>> +return 0;
> 
> -EINVAL is such a widespread error value. Maybe better explicitly test
> for existence with of_find_property?

ok

>> +else if (ret)
>> +return ret;
>> +
>> +ret = keystore_get_secret(state->name, &key, &key_len);
>> +if (ret == -ENOENT) /* -ENOENT == does not exist */
>> +return -EPROBE_DEFER;
>> +else if (ret)
>> +return ret;
>> +
>> +digest = digest_alloc(algo);
>> +if (!digest) {
>> +dev_info(&state->dev, "algo %s not found - probe deferred\n", 
>> algo);
>> +return -EPROBE_DEFER;
>> +}
>> +
>> +ret = digest_set_key(digest, key, key_len);
>> +if (ret) {
>> +digest_free(digest);
>> +return ret;
>> +}
>> +
>> +backend_raw->backend.digest = digest;
>> +backend_raw->size_full = digest_length(digest);
>> +
>> +return 0;
>> +}
>> +
>>  /*
>>   * state_backend_raw_file - create a raw file backend store for a state 
>> instance
>>   *
>> @@ -1534,8 +1627,14 @@ int state_backend_raw_file(struct state *state, const 
>> char *of_path,
>>  return -EINVAL;
>>  
>>  backend_raw = xzalloc(sizeof(*backend_raw));
>> -backend = &backend_raw->backend;
>>  
>> +ret = state_backend_raw_file_init_digest(state, backend_raw);
>> +if (ret) {
>> +    free(backend_raw);
>> +return ret;
>> +}
> 
> Maybe better make this configurable with correct dependencies
> (CONFIG_CRYPTO_KEYSTORE, CONFIG_DIGEST) rather than depending on the
> user selecting the implicit dependencies manually?

There are noops so that it compile even if KEYSTORE and DIGEST is not
selected.

Marc
-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 1/8] of_path: of_find_path() factor out device detection logic into separate function

2015-10-20 Thread Marc Kleine-Budde
This patch factors out the device detection logic into separate function, so
that it can be used from another function.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/of/of_path.c | 81 
 1 file changed, 44 insertions(+), 37 deletions(-)

diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index 992972c9b52e..b3ef26c6a50d 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -106,6 +106,48 @@ out:
return ret;
 }
 
+int __of_find_path(struct device_node *node, const char *propname, char 
**outpath, unsigned flags)
+{
+   struct of_path op = {};
+   const char *str;
+   bool add_bb = false;
+   int i, ret;
+
+   op.dev = of_find_device_by_node_path(node->full_name);
+   if (!op.dev) {
+   op.dev = of_find_device_by_node_path(node->parent->full_name);
+   if (!op.dev)
+   return -ENODEV;
+   }
+
+   device_detect(op.dev);
+
+   op.cdev = cdev_by_device_node(node);
+
+   i = 1;
+
+   while (propname) {
+   ret = of_property_read_string_index(node, propname, i++, &str);
+   if (ret)
+   break;
+
+   ret = of_path_parse_one(&op, str);
+   if (ret)
+   return ret;
+   }
+
+   if (!op.cdev)
+   return -ENOENT;
+
+   if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
+   mtd_can_have_bb(op.cdev->mtd))
+   add_bb = true;
+
+   *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : "");
+
+   return 0;
+}
+
 /**
  * of_find_path - translate a path description in the devicetree to a barebox
  *path
@@ -134,11 +176,8 @@ out:
  */
 int of_find_path(struct device_node *node, const char *propname, char 
**outpath, unsigned flags)
 {
-   struct of_path op = {};
struct device_node *rnode;
-   const char *path, *str;
-   bool add_bb = false;
-   int i, ret;
+   const char *path;
 
path = of_get_property(node, propname, NULL);
if (!path)
@@ -148,37 +187,5 @@ int of_find_path(struct device_node *node, const char 
*propname, char **outpath,
if (!rnode)
return -ENODEV;
 
-   op.dev = of_find_device_by_node_path(rnode->full_name);
-   if (!op.dev) {
-   op.dev = of_find_device_by_node_path(rnode->parent->full_name);
-   if (!op.dev)
-   return -ENODEV;
-   }
-
-   device_detect(op.dev);
-
-   op.cdev = cdev_by_device_node(rnode);
-
-   i = 1;
-
-   while (1) {
-   ret = of_property_read_string_index(node, propname, i++, &str);
-   if (ret)
-   break;
-
-   ret = of_path_parse_one(&op, str);
-   if (ret)
-   return ret;
-   }
-
-   if (!op.cdev)
-   return -ENOENT;
-
-   if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
-   mtd_can_have_bb(op.cdev->mtd))
-   add_bb = true;
-
-   *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : "");
-
-   return 0;
+   return __of_find_path(rnode, propname, outpath, flags);
 }
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 6/8] crypto: add simple keystore

2015-10-20 Thread Marc Kleine-Budde
This patch adds a simple keystore to barebox. The keystore implements a simple
key-value store to hold arbitrary values.

Signed-off-by: Marc Kleine-Budde 
---
 crypto/Kconfig|  6 
 crypto/Makefile   |  1 +
 crypto/keystore.c | 80 +++
 include/crypto/keystore.h | 26 +++
 4 files changed, 113 insertions(+)
 create mode 100644 crypto/keystore.c
 create mode 100644 include/crypto/keystore.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index ef807dec68de..10b34912b007 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -84,3 +84,9 @@ config CRYPTO_PBKDF2
select DIGEST
select DIGEST_SHA1_GENERIC
bool
+
+config CRYPTO_KEYSTORE
+   bool "Keystore"
+   help
+ This is a simple keystore, which can be used to pass keys
+ between several components via simple interface.
diff --git a/crypto/Makefile b/crypto/Makefile
index f39de718e5e7..c6d17787ca4e 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_DIGEST_SHA384_GENERIC)   += sha4.o
 obj-$(CONFIG_DIGEST_SHA512_GENERIC)+= sha4.o
 
 obj-$(CONFIG_CRYPTO_PBKDF2)+= pbkdf2.o
+obj-$(CONFIG_CRYPTO_KEYSTORE)  += keystore.o
diff --git a/crypto/keystore.c b/crypto/keystore.c
new file mode 100644
index ..90b470fe6717
--- /dev/null
+++ b/crypto/keystore.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 Pengutronix, Marc Kleine-Budde 
+ *
+ * This program is free software; you can redistribute it and/or modify it 
under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+
+static LIST_HEAD(keystore_list);
+
+#define for_each_key(key) list_for_each_entry(key, &keystore_list, list)
+
+struct keystore_key {
+   struct list_head list;
+   const char *name;
+   const u8 *secret;
+   int secret_len;
+};
+
+static int keystore_compare(struct list_head *a, struct list_head *b)
+{
+   const char *na = list_entry(a, struct keystore_key, list)->name;
+   const char *nb = list_entry(b, struct keystore_key, list)->name;
+
+   return strcmp(na, nb);
+}
+
+/**
+ * @param[in] name Name of the secret to get
+ * @param[out] secret Double pointer to memory representing the secret, do 
_not_ free() after use
+ * @param[out] secret_len Pointer to length of the secret
+ */
+int keystore_get_secret(const char *name, const u8 **secret, int *secret_len)
+{
+   struct keystore_key *key;
+
+   for_each_key(key) {
+   if (!strcmp(name, key->name)) {
+   if (!secret || !secret_len)
+   return 0;
+
+   *secret = key->secret;
+   *secret_len = key->secret_len;
+
+   return 0;
+   }
+   }
+
+   return -ENOENT;
+}
+
+/**
+ * @param[in] name Name of the secret to set
+ * @param[in] secret Pointer to memory holding the secret
+ * @param[in] secret_len Length of the secret
+ */
+int keystore_set_secret(const char *name, const u8 *secret, int secret_len)
+{
+   struct keystore_key *key;
+   int ret;
+
+   /* check if key is already in store */
+   ret = keystore_get_secret(name, NULL, NULL);
+   if (!ret)
+   return -EBUSY;
+
+   key = xzalloc(sizeof(*key));
+   INIT_LIST_HEAD(&key->list);
+   key->name = xstrdup(name);
+   key->secret = xmemdup(secret, secret_len);
+   key->secret_len = secret_len;
+
+   list_add_sort(&key->list, &keystore_list, keystore_compare);
+
+   return 0;
+}
diff --git a/include/crypto/keystore.h b/include/crypto/keystore.h
new file mode 100644
index ..29915854b851
--- /dev/null
+++ b/include/crypto/keystore.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2015 Pengutronix, Marc Kleine-Budde 
+ *
+ * This program is free software; you can redistribute it and/or modify it 
under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+
+#ifndef __CRYPTO_KEYSTORE_H
+#define __CRYPTO_KEYSTORE_H
+
+#ifdef CONFIG_CRYPTO_KEYSTORE
+int keystore_get_secret(const char *name, const u8 **secret, int *secret_len);
+int keystore_set_secret(const char *name, const u8 *secret, int secret_len);
+#else
+static inline int keystore_get_secret(const char *name, const u8 **secret, int 
*secret_len)
+{
+   return -EINVAL;
+}
+static inline int keystore_set_secret(const char *name, const u8 *secret, int 
secret_len)
+{
+   return 0;
+}
+#endif
+
+#endif
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 1/8] state framework enhancements

2015-10-20 Thread Marc Kleine-Budde
Hello,

this series fixes some problems and enhances the state support in barebox.

Marc

changes since v1:
* 1+2: add of_find_path_by_phandle()
* 3: don't open code OF to device path conversion in state_probe use 
of_find_path_by_phandle() instead


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 7/8] state: prepare raw backend for hmac support

2015-10-20 Thread Marc Kleine-Budde
This patch cleans up the raw backend, so that adding hmac support in the next
patch is easier.

Signed-off-by: Marc Kleine-Budde 
---
 common/state.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/common/state.c b/common/state.c
index fdb5564af3bd..d37f4ab4b539 100644
--- a/common/state.c
+++ b/common/state.c
@@ -1254,7 +1254,7 @@ static int backend_raw_load_one(struct state_backend_raw 
*backend_raw,
struct backend_raw_header header = {};
unsigned long max_len;
int ret;
-   void *buf;
+   void *buf, *data;
 
max_len = backend_raw->stride;
 
@@ -1292,13 +1292,18 @@ static int backend_raw_load_one(struct 
state_backend_raw *backend_raw,
return -EINVAL;
}
 
-   buf = xzalloc(header.data_len);
+   buf = xzalloc(sizeof(header) + header.data_len);
+   data = buf + sizeof(header);
+
+   ret = lseek(fd, offset, SEEK_SET);
+   if (ret < 0)
+   goto out_free;
 
-   ret = read_full(fd, buf, header.data_len);
+   ret = read_full(fd, buf, sizeof(header) + header.data_len);
if (ret < 0)
goto out_free;
 
-   crc = crc32(0, buf, header.data_len);
+   crc = crc32(0, data, header.data_len);
if (crc != header.data_crc) {
dev_err(&state->dev,
"invalid crc, calculated 0x%08x, found 0x%08x\n",
@@ -1310,7 +1315,7 @@ static int backend_raw_load_one(struct state_backend_raw 
*backend_raw,
list_for_each_entry(sv, &state->variables, list) {
if (sv->start + sv->size > header.data_len)
break;
-   memcpy(sv->raw, buf + sv->start, sv->size);
+   memcpy(sv->raw, data + sv->start, sv->size);
}
 
free(buf);
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 4/8] state: use name of device node as name if alias is not available

2015-10-20 Thread Marc Kleine-Budde
Wihtout this patch, when using more than one state device an alias is
mandatory, otherwise the there will be two state devices with the name state.

This patch fixes the limitation by using the device node's name if no alias is
defined.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/misc/state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/state.c b/drivers/misc/state.c
index 4cda55b6efc6..e056b28f96c2 100644
--- a/drivers/misc/state.c
+++ b/drivers/misc/state.c
@@ -36,7 +36,7 @@ static int state_probe(struct device_d *dev)
 
alias = of_alias_get(np);
if (!alias)
-   alias = "state";
+   alias = np->name;
 
state = state_new_from_node(alias, np);
if (IS_ERR(state))
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 2/8] of_path: add of_find_path_by_phandle()

2015-10-20 Thread Marc Kleine-Budde
This patch adds the function of_find_path_by_phandle(), which is similar to
of_find_path(), but it takes a phandle not a barebox path description.

Signed-off-by: Marc Kleine-Budde 
---
 drivers/of/of_path.c | 22 ++
 include/of.h |  1 +
 2 files changed, 23 insertions(+)

diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index b3ef26c6a50d..dae7eb628acb 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -149,6 +149,28 @@ int __of_find_path(struct device_node *node, const char 
*propname, char **outpat
 }
 
 /**
+ * of_find_path_by_phandle - translate a phanle in the devicetree to a
+ *   barebox device path
+ *
+ * @node: the node containing the phandle pointing to the device tree node
+ * @phandle: the phandle pointing to the devicetree node
+ * @outpath: if this function returns 0 outpath will contain the path belonging
+ *   to the input path description. Must be freed with free().
+ * @flags: use OF_FIND_PATH_FLAGS_BB to return the .bb device if available
+ *
+ */
+int of_find_path_by_phandle(struct device_node *node, const char *phandle, 
char **outpath, unsigned flags)
+{
+   struct device_node *rnode;
+
+   rnode = of_parse_phandle(node, phandle, 0);
+   if (!rnode)
+   return -EINVAL;
+
+   return __of_find_path(rnode, NULL, outpath, flags);
+}
+
+/**
  * of_find_path - translate a path description in the devicetree to a barebox
  *path
  *
diff --git a/include/of.h b/include/of.h
index e0ebc39b742d..c1c17e70b389 100644
--- a/include/of.h
+++ b/include/of.h
@@ -246,6 +246,7 @@ void of_add_memory_bank(struct device_node *node, bool 
dump, int r,
 struct device_d *of_find_device_by_node_path(const char *path);
 #define OF_FIND_PATH_FLAGS_BB 1/* return .bb device if 
available */
 int of_find_path(struct device_node *node, const char *propname, char 
**outpath, unsigned flags);
+int of_find_path_by_phandle(struct device_node *node, const char *phandle, 
char **outpath, unsigned flags);
 int of_register_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
 int of_unregister_fixup(int (*fixup)(struct device_node *, void *), void 
*context);
 struct device_node *of_find_node_by_alias(struct device_node *root,
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 5/8] state: disable load command

2015-10-20 Thread Marc Kleine-Budde
From: Enrico Jorns 

Explicitly loading environment is not required as it will be loaded if
available during device probing

Signed-off-by: Enrico Jorns 
Signed-off-by: Marc Kleine-Budde 
---
 commands/state.c | 19 +--
 common/state.c   | 45 ++---
 drivers/misc/state.c |  1 -
 include/state.h  |  1 -
 4 files changed, 23 insertions(+), 43 deletions(-)

diff --git a/commands/state.c b/commands/state.c
index 59d1eb850215..4b51759e3ecd 100644
--- a/commands/state.c
+++ b/commands/state.c
@@ -21,26 +21,20 @@ static int do_state(int argc, char *argv[])
 {
int opt, ret = 0;
struct state *state = NULL;
-   int do_save = 0, do_load = 0;
+   int do_save = 0;
const char *statename = "state";
 
-   while ((opt = getopt(argc, argv, "sl")) > 0) {
+   while ((opt = getopt(argc, argv, "s")) > 0) {
switch (opt) {
case 's':
do_save = 1;
break;
-   case 'l':
-   do_load = 1;
-   break;
default:
return COMMAND_ERROR_USAGE;
}
}
 
-   if (do_save && do_load)
-   return COMMAND_ERROR_USAGE;
-
-   if (!do_save && !do_load) {
+   if (!do_save) {
state_info();
return 0;
}
@@ -56,8 +50,6 @@ static int do_state(int argc, char *argv[])
 
if (do_save)
ret = state_save(state);
-   else if (do_load)
-   ret = state_load(state);
 
return ret;
 }
@@ -67,13 +59,12 @@ BAREBOX_CMD_HELP_TEXT("Usage: state [OPTIONS] [STATENAME]")
 BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("options:")
 BAREBOX_CMD_HELP_OPT ("-s", "save state")
-BAREBOX_CMD_HELP_OPT ("-l", "load state")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(state)
.cmd= do_state,
-   BAREBOX_CMD_DESC("load and save state information")
-   BAREBOX_CMD_OPTS("[-sl] [STATENAME]")
+   BAREBOX_CMD_DESC("save state information")
+   BAREBOX_CMD_OPTS("[-s] [STATENAME]")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_HELP(cmd_state_help)
 BAREBOX_CMD_END
diff --git a/common/state.c b/common/state.c
index 117a6867597d..fdb5564af3bd 100644
--- a/common/state.c
+++ b/common/state.c
@@ -51,7 +51,6 @@ struct state {
 };
 
 struct state_backend {
-   int (*load)(struct state_backend *backend, struct state *state);
int (*save)(struct state_backend *backend, struct state *state);
const char *name;
const char *of_path;
@@ -1049,30 +1048,6 @@ int state_get_name(const struct state *state, char const 
**name)
 }
 
 /*
- * state_load - load a state from the backing store
- *
- * @state  The state instance to load
- */
-int state_load(struct state *state)
-{
-   int ret;
-
-   if (!state->backend)
-   return -ENOSYS;
-
-   ret = state->backend->load(state->backend, state);
-   if (ret) {
-   dev_warn(&state->dev, "load failed\n");
-   state->dirty = 1;
-   } else {
-   dev_info(&state->dev, "load successful\n");
-   state->dirty = 0;
-   }
-
-   return ret;
-}
-
-/*
  * state_save - save a state to the backing store
  *
  * @state  The state instance to save
@@ -1226,7 +1201,6 @@ int state_backend_dtb_file(struct state *state, const 
char *of_path, const char
backend_dtb = xzalloc(sizeof(*backend_dtb));
backend = &backend_dtb->backend;
 
-   backend->load = state_backend_dtb_load;
backend->save = state_backend_dtb_save;
backend->of_path = xstrdup(of_path);
backend->path = xstrdup(path);
@@ -1238,6 +1212,15 @@ int state_backend_dtb_file(struct state *state, const 
char *of_path, const char
if (!ret && !(meminfo.flags & MTD_NO_ERASE))
backend_dtb->need_erase = true;
 
+   ret = state_backend_dtb_load(backend, state);
+   if (ret) {
+   dev_warn(&state->dev, "load failed - using defaults\n");
+   } else {
+   dev_info(&state->dev, "load successful\n");
+   state->dirty = 0;
+   }
+
+   /* ignore return value of load() */
return 0;
 }
 
@@ -1548,7 +1531,6 @@ int state_backend_raw_file(struct state *state, const 
char *of_path,
backend_raw = xzalloc(sizeof(*backend_raw));
backend = &backend_raw->backend;
 
-   backend->load = state_backend_raw_load;
backend->save = state_backend_raw_save;
backend->of_path = xstrdup(of_path);
b

[PATCH v2 3/8] state: make use of of_find_path_by_phandle() and add return -EPROBE_DEFER if device is not available

2015-10-20 Thread Marc Kleine-Budde
Signed-off-by: Uwe Kleine-König 
Signed-off-by: Marc Kleine-Budde 
---
 drivers/misc/state.c | 37 -
 1 file changed, 8 insertions(+), 29 deletions(-)

diff --git a/drivers/misc/state.c b/drivers/misc/state.c
index f3e366480fa2..4cda55b6efc6 100644
--- a/drivers/misc/state.c
+++ b/drivers/misc/state.c
@@ -24,7 +24,6 @@
 static int state_probe(struct device_d *dev)
 {
struct device_node *np = dev->device_node;
-   struct device_node *partition_node;
struct state *state;
const char *alias;
const char *backend_type = NULL;
@@ -50,35 +49,15 @@ static int state_probe(struct device_d *dev)
}
 
/* guess if of_path is a path, not a phandle */
-   if (of_path[0] == '/' && len > 1) {
+   if (of_path[0] == '/' && len > 1)
ret = of_find_path(np, "backend", &path, 0);
-   if (ret)
-   goto out_release;
-   } else {
-   struct device_d *dev;
-   struct cdev *cdev;
-
-   partition_node = of_parse_phandle(np, "backend", 0);
-   if (!partition_node) {
-   ret = -ENODEV;
-   goto out_release;
-   }
-
-   dev = of_find_device_by_node(partition_node);
-   if (!list_is_singular(&dev->cdevs)) {
-   ret = -ENODEV;
-   goto out_release;
-   }
-
-   cdev = list_first_entry(&dev->cdevs, struct cdev, devices_list);
-   if (!cdev) {
-   ret = -ENODEV;
-   goto out_release;
-   }
-
-   path = asprintf("/dev/%s", cdev->name);
-   of_path = partition_node->full_name;
-   }
+   else
+   ret = of_find_path_by_phandle(np, "backend", &path, 0);
+
+   if (ret == -ENODEV)
+   ret = -EPROBE_DEFER;
+   if (ret)
+   goto out_release;
 
ret = of_property_read_string(np, "backend-type", &backend_type);
if (ret) {
-- 
2.6.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  1   2   3   4   >