Skip to contentSkip to conversation

ARM: i.MX: Kamstrup mx7 concentrator board support

PATCH Superseded Lars Pedersen 3 participants 10 messages Apr 9, 2021 – Apr 12, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: i.MX: Kamstrup mx7 concentrator board support

This adds support for Kamstrup mx7 concentrator board

---
 arch/arm/boards/Makefile                      |   1 +
 .../boards/kamstrup-mx7-concentrator/Makefile |   2 +
 .../boards/kamstrup-mx7-concentrator/board.c  |  51 +++++++++
 .../flash-header-tqma7d.imxcfg                |  79 +++++++++++++
 .../kamstrup-mx7-concentrator/lowlevel.c      |  35 ++++++
 arch/arm/dts/Makefile                         |   1 +
 arch/arm/dts/imx7d-flex-concentrator-mfg.dts  | 108 ++++++++++++++++++
 arch/arm/mach-imx/Kconfig                     |   5 +
 images/Makefile.imx                           |   5 +
 9 files changed, 287 insertions(+)
 create mode 100644 arch/arm/boards/kamstrup-mx7-concentrator/Makefile
 create mode 100644 arch/arm/boards/kamstrup-mx7-concentrator/board.c
 create mode 100644 arch/arm/boards/kamstrup-mx7-concentrator/flash-header-tqma7d.imxcfg
 create mode 100644 arch/arm/boards/kamstrup-mx7-concentrator/lowlevel.c
 create mode 100644 arch/arm/dts/imx7d-flex-concentrator-mfg.dts
arch/arm/boards/Makefile +1 -0
index 9ccb75e27..0e59d6a77 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_MACH_HABA_KNX_LITE)		+= haba-knx/
 obj-$(CONFIG_MACH_IMX21ADS)			+= freescale-mx21-ads/
 obj-$(CONFIG_MACH_IMX233_OLINUXINO)		+= imx233-olinuxino/
 obj-$(CONFIG_MACH_IMX27ADS)			+= freescale-mx27-ads/
+obj-$(CONFIG_MACH_KAMSTRUP_MX7_CONCENTRATOR)	+= kamstrup-mx7-concentrator/
 obj-$(CONFIG_MACH_KINDLE3)			+= kindle3/
 obj-$(CONFIG_MACH_KONTRON_SAMX6I)		+= kontron-samx6i/
 obj-$(CONFIG_MACH_LENOVO_IX4_300D)		+= lenovo-ix4-300d/
arch/arm/boards/kamstrup-mx7-concentrator/Makefile new file +2 -0
new file mode 100644
index 000000000..a8b45be12
@@ -0,0 +1,2 @@
+obj-y += board.o
+lwl-y += lowlevel.o
\ No newline at end of file
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +51 -0

51 lines not on this page · raw message

arch/arm/boards/kamstrup-mx7-concentrator/flash-header-tqma7d.imxcfg new file +79 -0

79 lines not on this page · raw message

arch/arm/boards/kamstrup-mx7-concentrator/lowlevel.c new file +35 -0
new file mode 100644
index 000000000..8cd6d67f7
@@ -0,0 +1,35 @@
+#include <debug_ll.h>
+#include <io.h>
+#include <common.h>
+#include <linux/sizes.h>
+#include <mach/generic.h>
+#include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
+#include <mach/imx7-ccm-regs.h>
+#include <mach/iomux-mx7.h>
+#include <mach/debug_ll.h>
+#include <asm/cache.h>
+#include <mach/esdctl.h>
+
+extern char __dtb_z_imx7d_flex_concentrator_mfg_start[];
+
+static inline void setup_uart(void)
+{
+	imx7_early_setup_uart_clock();
+
+	imx7_setup_pad(MX7D_PAD_SAI2_TX_BCLK__UART4_DCE_TX);
+
+	imx7_uart_setup_ll();
+
+	putc_ll('>');
+}
+
+ENTRY_FUNCTION(start_kamstrup_mx7_concentrator, r0, r1, r2)
+{
+	imx7_cpu_lowlevel_init();
+
+	if (IS_ENABLED(CONFIG_DEBUG_LL))
+		setup_uart();
+
+	imx7d_barebox_entry(__dtb_z_imx7d_flex_concentrator_mfg_start + get_runtime_offset());
+}
arch/arm/dts/Makefile +1 -0
index d5f61768a..d66b6db07 100644
@@ -30,6 +30,7 @@ lwl-$(CONFIG_MACH_GRINN_LITEBOARD) += imx6ul-liteboard.dtb.o
 lwl-$(CONFIG_MACH_GUF_SANTARO) += imx6q-guf-santaro.dtb.o
 lwl-$(CONFIG_MACH_GUF_VINCELL) += imx53-guf-vincell.dtb.o imx53-guf-vincell-lt.dtb.o
 lwl-$(CONFIG_MACH_GW_VENTANA) += imx6q-gw54xx.dtb.o
+lwl-$(CONFIG_MACH_KAMSTRUP_MX7_CONCENTRATOR) += imx7d-flex-concentrator-mfg.dtb.o
 lwl-$(CONFIG_MACH_KONTRON_SAMX6I) += imx6q-samx6i.dtb.o \
 					imx6dl-samx6i.dtb.o
 lwl-$(CONFIG_MACH_LENOVO_IX4_300D) += armada-xp-lenovo-ix4-300d-bb.dtb.o
arch/arm/dts/imx7d-flex-concentrator-mfg.dts new file +108 -0

108 lines not on this page · raw message

arch/arm/mach-imx/Kconfig +5 -0
index 3f8012c73..cc73d0a0d 100644
@@ -526,6 +526,11 @@ config MACH_FREESCALE_MX7_SABRESD
 
 	  https://goo.gl/6EKGdk
 
+config MACH_KAMSTRUP_MX7_CONCENTRATOR
+	bool "Kamstrup i.MX7 Concentrator"
+	select ARCH_IMX7
+	select ARM_USE_COMPRESSED_DTB
+
 config MACH_NXP_IMX6ULL_EVK
 	bool "NXP i.MX6ull EVK Board"
 	select ARCH_IMX6UL
images/Makefile.imx +5 -0
index b892ec019..bc5ad1c7c 100644
@@ -403,6 +403,11 @@ CFG_start_zii_imx7d_dev.pblb.imximg = $(board)/zii-imx7d-dev/flash-header-zii-im
 FILE_barebox-zii-imx7d-dev.img = start_zii_imx7d_dev.pblb.imximg
 image-$(CONFIG_MACH_ZII_IMX7D_DEV) += barebox-zii-imx7d-dev.img
 
+pblb-$(CONFIG_MACH_KAMSTRUP_MX7_CONCENTRATOR) += start_kamstrup_mx7_concentrator
+CFG_start_kamstrup_mx7_concentrator.pblb.imximg = $(board)/kamstrup-mx7-concentrator/flash-header-tqma7d.imxcfg
+FILE_barebox-kamstrup-mx7-concentrator.img = start_kamstrup_mx7_concentrator.pblb.imximg
+image-$(CONFIG_MACH_KAMSTRUP_MX7_CONCENTRATOR) += barebox-kamstrup-mx7-concentrator.img
+
 # ----------------------- i.MX8mm based boards --------------------------
 pblb-$(CONFIG_MACH_NXP_IMX8MM_EVK) += start_nxp_imx8mm_evk
 CFG_start_nxp_imx8mm_evk.pblb.imximg = $(board)/nxp-imx8mm-evk/flash-header-imx8mm-evk.imxcfg
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Reviewed-by on v1 1/1
#1 lore raw

Hello Lars,

Quoted 25 lines · Lars Pedersen
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +19 -0
new file mode 100644
index 000000000..ac32e9b05
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2021 Kamstrup A/S
+
+/* Author: Lars Pedersen <[email protected]> */
+
+#include <common.h>
+#include <init.h>
+#include <io.h>
+#include <gpio.h>
+#include <restart.h>
+#include <mach/imx7-regs.h>
+#include <mach/iomux-mx7.h>
+#include <mach/generic.h>
+#include <mfd/imx7-iomuxc-gpr.h>
+
+#define BOARD_RESTART_GPIO IMX_GPIO_NR(7, 12)
+#define TPM_RESET_GPIO IMX_GPIO_NR(3, 8)
+
+static void kamstrup_mx7_tpm_reset(void)

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 29

Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +10 -0
+{
+	imx7_setup_pad(MX7D_PAD_LCD_DATA03__GPIO3_IO8);
+
+	gpio_request(TPM_RESET_GPIO, "tpm-reset");
+	gpio_direction_output(TPM_RESET_GPIO, 1);
+	mdelay(100);
+	gpio_set_value(TPM_RESET_GPIO, 0);
+	mdelay(100);
+	gpio_set_value(TPM_RESET_GPIO, 1);
+	gpio_free(TPM_RESET_GPIO);

We are trying to cut down on code that doesn't use the driver model. Couldn't this be represented as a gpio-hog in the device tree or a reset line for the SPI device?

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 38

Quoted 9 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+}
+
+static void __noreturn kamstrup_mx7_board_restart_gpio(struct restart_handler *rst)
+{
+	imx7_setup_pad(MX7D_PAD_ENET1_TX_CLK__GPIO7_IO12);
+
+	gpio_direction_output(BOARD_RESTART_GPIO, 0);
+	mdelay(1);
+	gpio_set_value(BOARD_RESTART_GPIO, 0);

I just sent out a patch[1] with a driver implementing the "gpio-restart" device tree binding. Could you test that one and use it here instead?

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 47

Quoted 9 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+
+	hang();
+}
+
+static int kamstrup_mx7_concentrator_coredevices_init(void)
+{
+	kamstrup_mx7_tpm_reset();
+	restart_handler_register_fn("board", kamstrup_mx7_board_restart_gpio);
+	barebox_set_model("Kamstrup OMNIA Concentrator");

The default model name is "Kamstrup OMNIA Flex Concentrator". If that's too long, you could override /model in the barebox device tree. With the changes suggested above, you could drop board.c then altogether.

The rest of the patch looks good to me. With the feedback addressed:

[1]: https://lore.pengutronix.de/barebox/[email protected]/T/#mc4dbda46e6bd868fc9ecfcfa42f3dbfe943bef47

Cheers,
Ahmad

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Hello Ahmad.

Thanks for the feedback.

Quoted 35 lines · Ahmad Fatoum

Hello Lars,

Quoted 31 lines · Lars Pedersen
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +25 -0
new file mode 100644
index 000000000..ac32e9b05
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2021 Kamstrup A/S
+
+/* Author: Lars Pedersen <[email protected]> */
+
+#include <common.h>
+#include <init.h>
+#include <io.h>
+#include <gpio.h>
+#include <restart.h>
+#include <mach/imx7-regs.h>
+#include <mach/iomux-mx7.h>
+#include <mach/generic.h>
+#include <mfd/imx7-iomuxc-gpr.h>
+
+#define BOARD_RESTART_GPIO IMX_GPIO_NR(7, 12)
+#define TPM_RESET_GPIO IMX_GPIO_NR(3, 8)
+
+static void kamstrup_mx7_tpm_reset(void)
+{
+     imx7_setup_pad(MX7D_PAD_LCD_DATA03__GPIO3_IO8);
+
+     gpio_request(TPM_RESET_GPIO, "tpm-reset");
+     gpio_direction_output(TPM_RESET_GPIO, 1);
+     mdelay(100);
Quoted 8 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 29

Quoted 4 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +4 -0
+     gpio_set_value(TPM_RESET_GPIO, 0);
+     mdelay(100);
+     gpio_set_value(TPM_RESET_GPIO, 1);
+     gpio_free(TPM_RESET_GPIO);

We are trying to cut down on code that doesn't use the driver model. Couldn't this be represented as a gpio-hog in the device tree or a reset line for the SPI device?

I can't find anything in the DT binding for the SPI/TPM driver to use a reset line. Can a DT gpio-hog toggle the pin? Don't you need a driver for this? I see the following options:

1) gpio-hog with a label and use new gpiolib in board.c.
2) gpio-hog and control the pin in a boot script.

Quoted 14 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 38

Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+}
+
+static void __noreturn kamstrup_mx7_board_restart_gpio(struct restart_handler *rst)
+{
+     imx7_setup_pad(MX7D_PAD_ENET1_TX_CLK__GPIO7_IO12);
+
+     gpio_direction_output(BOARD_RESTART_GPIO, 0);
+     mdelay(1);
+     gpio_set_value(BOARD_RESTART_GPIO, 0);

I just sent out a patch[1] with a driver implementing the "gpio-restart" device tree binding. Could you test that one and use it here instead?

I have applied the patches on a master branch (Last patch failed to apply but was only watchdog) and the gpio-restart works perfectly.

Quoted 5 lines
Quoted 5 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +5 -0
+
+     hang();
+}
+
+static int kamstrup_mx7_concentrator_coredevices_init(void)
Quoted 9 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 47

Quoted 4 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +4 -0
+{
+     kamstrup_mx7_tpm_reset();
+     restart_handler_register_fn("board", kamstrup_mx7_board_restart_gpio);
+     barebox_set_model("Kamstrup OMNIA Concentrator");

The default model name is "Kamstrup OMNIA Flex Concentrator". If that's too long, you could override /model in the barebox device tree. With the changes suggested above, you could drop board.c then altogether.

I'll move this into the device tree or delete it entirely.

Quoted 5 lines

The rest of the patch looks good to me. With the feedback addressed:

[1]: https://lore.pengutronix.de/barebox/[email protected]/T/#mc4dbda46e6bd868fc9ecfcfa42f3dbfe943bef47

Quoted 8 lines

Cheers,
Ahmad

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw

Hello Lars,

Quoted 19 lines · Lars Pedersen
Quoted 10 lines
Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +10 -0
+#define BOARD_RESTART_GPIO IMX_GPIO_NR(7, 12)
+#define TPM_RESET_GPIO IMX_GPIO_NR(3, 8)
+
+static void kamstrup_mx7_tpm_reset(void)
+{
+     imx7_setup_pad(MX7D_PAD_LCD_DATA03__GPIO3_IO8);
+
+     gpio_request(TPM_RESET_GPIO, "tpm-reset");
+     gpio_direction_output(TPM_RESET_GPIO, 1);
+     mdelay(100);
Quoted 8 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 29

Quoted 4 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +4 -0
+     gpio_set_value(TPM_RESET_GPIO, 0);
+     mdelay(100);
+     gpio_set_value(TPM_RESET_GPIO, 1);
+     gpio_free(TPM_RESET_GPIO);

We are trying to cut down on code that doesn't use the driver model. Couldn't this be represented as a gpio-hog in the device tree or a reset line for the SPI device?

Quoted 2 lines

I can't find anything in the DT binding for the SPI/TPM driver to use a reset line.

Proper way would be for this to be added into Linux then, but that's out of scope for the patch here.

Quoted 2 lines

Can a DT gpio-hog toggle the pin? Don't you need a driver for this?

You can't pulse with a gpio-hog. I assumed the TPM is in reset by default.

Quoted 4 lines

I see the following options:

1) gpio-hog with a label and use new gpiolib in board.c.
2) gpio-hog and control the pin in a boot script.

If there's no straight-forward way to do it without board code, it's ok the way it is with one change though: I missed it the first time, but your board breaks multi-image support because you don't check whether the initcall is indeed running on your board (See for example imx_v7_defconfig, which builds over a hundred boards at once).

Easiest way to get this right is to write a board driver. See arch/arm/boards/lxa-mc1/board.c for an example.

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +4 -0
+}
+
+static void __noreturn kamstrup_mx7_board_restart_gpio(struct restart_handler *rst)
+{
Quoted 9 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 38

Quoted 5 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +5 -0
+     imx7_setup_pad(MX7D_PAD_ENET1_TX_CLK__GPIO7_IO12);
+
+     gpio_direction_output(BOARD_RESTART_GPIO, 0);
+     mdelay(1);
+     gpio_set_value(BOARD_RESTART_GPIO, 0);

I just sent out a patch[1] with a driver implementing the "gpio-restart" device tree binding. Could you test that one and use it here instead?

Quoted 2 lines

I have applied the patches on a master branch (Last patch failed to apply but was only watchdog) and the gpio-restart works perfectly.

Thanks for testing! You can add your Tested-By on the patch in question if you like.

Quoted 16 lines
Quoted 15 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 47

Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+
+     hang();
+}
+
+static int kamstrup_mx7_concentrator_coredevices_init(void)
+{
+     kamstrup_mx7_tpm_reset();
+     restart_handler_register_fn("board", kamstrup_mx7_board_restart_gpio);
+     barebox_set_model("Kamstrup OMNIA Concentrator");

The default model name is "Kamstrup OMNIA Flex Concentrator". If that's too long, you could override /model in the barebox device tree. With the changes suggested above, you could drop board.c then altogether.

Quoted 1 line

I'll move this into the device tree or delete it entirely.

Great. :-)

Cheers,
Ahmad

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Hello again. Thanks for the quick response :)

Quoted 40 lines · Ahmad Fatoum

Hello Lars,

Quoted 19 lines · Lars Pedersen
Quoted 10 lines
Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +10 -0
+#define BOARD_RESTART_GPIO IMX_GPIO_NR(7, 12)
+#define TPM_RESET_GPIO IMX_GPIO_NR(3, 8)
+
+static void kamstrup_mx7_tpm_reset(void)
+{
+     imx7_setup_pad(MX7D_PAD_LCD_DATA03__GPIO3_IO8);
+
+     gpio_request(TPM_RESET_GPIO, "tpm-reset");
+     gpio_direction_output(TPM_RESET_GPIO, 1);
+     mdelay(100);
Quoted 8 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 29

Quoted 4 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +4 -0
+     gpio_set_value(TPM_RESET_GPIO, 0);
+     mdelay(100);
+     gpio_set_value(TPM_RESET_GPIO, 1);
+     gpio_free(TPM_RESET_GPIO);

We are trying to cut down on code that doesn't use the driver model. Couldn't this be represented as a gpio-hog in the device tree or a reset line for the SPI device?

Quoted 2 lines

I can't find anything in the DT binding for the SPI/TPM driver to use a reset line.

Proper way would be for this to be added into Linux then, but that's out of scope for the patch here.

Quoted 2 lines

Can a DT gpio-hog toggle the pin? Don't you need a driver for this?

You can't pulse with a gpio-hog. I assumed the TPM is in reset by default.

Quoted 4 lines

I see the following options:

1) gpio-hog with a label and use new gpiolib in board.c.
2) gpio-hog and control the pin in a boot script.

Quoted 8 lines

If there's no straight-forward way to do it without board code, it's ok the way it is with one change though: I missed it the first time, but your board breaks multi-image support because you don't check whether the initcall is indeed running on your board (See for example imx_v7_defconfig, which builds over a hundred boards at once).

Easiest way to get this right is to write a board driver. See arch/arm/boards/lxa-mc1/board.c for an example.

In arch/arm/boards/freescale-mx7-sabresd/board.c they do something like:

if (!of_machine_is_compatible("fsl,imx7d-sdb"))
return 0;

Can't I just do the same?

if (!of_machine_is_compatible("kam,imx7d-flex-concentrator-mfg"))
return 0;

The board driver in arch/arm/boards/lxa-mc1/board.c seems more complicated.

Quoted 42 lines
Quoted 15 lines
Quoted 14 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 38

Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+}
+
+static void __noreturn kamstrup_mx7_board_restart_gpio(struct restart_handler *rst)
+{
+     imx7_setup_pad(MX7D_PAD_ENET1_TX_CLK__GPIO7_IO12);
+
+     gpio_direction_output(BOARD_RESTART_GPIO, 0);
+     mdelay(1);
+     gpio_set_value(BOARD_RESTART_GPIO, 0);

I just sent out a patch[1] with a driver implementing the "gpio-restart" device tree binding. Could you test that one and use it here instead?

Quoted 2 lines

I have applied the patches on a master branch (Last patch failed to apply but was only watchdog) and the gpio-restart works perfectly.

Thanks for testing! You can add your Tested-By on the patch in question if you like.

Quoted 16 lines
Quoted 15 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 47

Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+
+     hang();
+}
+
+static int kamstrup_mx7_concentrator_coredevices_init(void)
+{
+     kamstrup_mx7_tpm_reset();
+     restart_handler_register_fn("board", kamstrup_mx7_board_restart_gpio);
+     barebox_set_model("Kamstrup OMNIA Concentrator");

The default model name is "Kamstrup OMNIA Flex Concentrator". If that's too long, you could override /model in the barebox device tree. With the changes suggested above, you could drop board.c then altogether.

Quoted 1 line

I'll move this into the device tree or delete it entirely.

Great. :-)

Quoted 8 lines

Cheers,
Ahmad

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw

Hello Lars,

Quoted 9 lines · Lars Pedersen

Hello again. Thanks for the quick response :)

Quoted 2 lines

Easiest way to get this right is to write a board driver. See arch/arm/boards/lxa-mc1/board.c for an example.

In arch/arm/boards/freescale-mx7-sabresd/board.c they do something like:

if (!of_machine_is_compatible("fsl,imx7d-sdb"))
return 0;

Quoted 6 lines

Can't I just do the same?

if (!of_machine_is_compatible("kam,imx7d-flex-concentrator-mfg"))
return 0;

The board driver in arch/arm/boards/lxa-mc1/board.c seems more complicated.

The board driver support is recent and not many boards use it. Doing of_machine_is_compatible check manually is error-prone (inverted logic, sometimes it's forgotten, like in v1 here) and doesn't scale once you have multiple compatibles you want to match against. Drivers can also EPROBE_DEFER if they can't yet acquire a resource.

For the simple case of toggling a reset, likely only difference now is that you can verify your driver availability with drvinfo. I'd prefer new code uses board from the get-go though if board code is really needed.

Cheers,
Ahmad

Quoted 52 lines
Quoted 51 lines
Quoted 16 lines
Quoted 15 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 38

Quoted 11 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+}
+
+static void __noreturn kamstrup_mx7_board_restart_gpio(struct restart_handler *rst)
+{
+     imx7_setup_pad(MX7D_PAD_ENET1_TX_CLK__GPIO7_IO12);
+
+     gpio_direction_output(BOARD_RESTART_GPIO, 0);
+     mdelay(1);
+     gpio_set_value(BOARD_RESTART_GPIO, 0);

I just sent out a patch[1] with a driver implementing the "gpio-restart" device tree binding. Could you test that one and use it here instead?

Quoted 2 lines

I have applied the patches on a master branch (Last patch failed to apply but was only watchdog) and the gpio-restart works perfectly.

Thanks for testing! You can add your Tested-By on the patch in question if you like.

Quoted 16 lines
Quoted 15 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 47

Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+
+     hang();
+}
+
+static int kamstrup_mx7_concentrator_coredevices_init(void)
+{
+     kamstrup_mx7_tpm_reset();
+     restart_handler_register_fn("board", kamstrup_mx7_board_restart_gpio);
+     barebox_set_model("Kamstrup OMNIA Concentrator");

The default model name is "Kamstrup OMNIA Flex Concentrator". If that's too long, you could override /model in the barebox device tree. With the changes suggested above, you could drop board.c then altogether.

Quoted 1 line

I'll move this into the device tree or delete it entirely.

Great. :-)

Cheers,
Ahmad

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Hello Ahmad

Quoted 26 lines · Ahmad Fatoum

Hello Lars,

Quoted 9 lines · Lars Pedersen

Hello again. Thanks for the quick response :)

Quoted 2 lines

Easiest way to get this right is to write a board driver. See arch/arm/boards/lxa-mc1/board.c for an example.

In arch/arm/boards/freescale-mx7-sabresd/board.c they do something like:

if (!of_machine_is_compatible("fsl,imx7d-sdb"))
return 0;

Quoted 6 lines

Can't I just do the same?

if (!of_machine_is_compatible("kam,imx7d-flex-concentrator-mfg"))
return 0;

The board driver in arch/arm/boards/lxa-mc1/board.c seems more complicated.

The board driver support is recent and not many boards use it. Doing of_machine_is_compatible check manually is error-prone (inverted logic, sometimes it's forgotten, like in v1 here) and doesn't scale once you have multiple compatibles you want to match against. Drivers can also EPROBE_DEFER if they can't yet acquire a resource.

Quoted 4 lines

For the simple case of toggling a reset, likely only difference now is that you can verify your driver availability with drvinfo. I'd prefer new code uses board from the get-go though if board code is really needed.

I got it working but we have decided to update the hardware to reset the TPM after your colleague mentioned how it should be done correctly :)

Just to be clear. I can now remove board.c as you first mentioned since I don't need any special stuff.

Also I need to update imx_v7_defconfig with this board with default value yes.

Quoted 56 lines

Cheers,
Ahmad

Quoted 43 lines
Quoted 43 lines
Quoted 16 lines
Quoted 15 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 38

Quoted 11 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+}
+
+static void __noreturn kamstrup_mx7_board_restart_gpio(struct restart_handler *rst)
+{
+     imx7_setup_pad(MX7D_PAD_ENET1_TX_CLK__GPIO7_IO12);
+
+     gpio_direction_output(BOARD_RESTART_GPIO, 0);
+     mdelay(1);
+     gpio_set_value(BOARD_RESTART_GPIO, 0);

I just sent out a patch[1] with a driver implementing the "gpio-restart" device tree binding. Could you test that one and use it here instead?

Quoted 2 lines

I have applied the patches on a master branch (Last patch failed to apply but was only watchdog) and the gpio-restart works perfectly.

Thanks for testing! You can add your Tested-By on the patch in question if you like.

Quoted 16 lines
Quoted 15 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 47

Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +9 -0
+
+     hang();
+}
+
+static int kamstrup_mx7_concentrator_coredevices_init(void)
+{
+     kamstrup_mx7_tpm_reset();
+     restart_handler_register_fn("board", kamstrup_mx7_board_restart_gpio);
+     barebox_set_model("Kamstrup OMNIA Concentrator");

The default model name is "Kamstrup OMNIA Flex Concentrator". If that's too long, you could override /model in the barebox device tree. With the changes suggested above, you could drop board.c then altogether.

Quoted 1 line

I'll move this into the device tree or delete it entirely.

Great. :-)

Quoted 9 lines
Quoted 8 lines

Cheers,
Ahmad

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Quoted 5 lines

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#7 lore raw

Hello,

Quoted 11 lines · Lars Pedersen
Quoted 4 lines

For the simple case of toggling a reset, likely only difference now is that you can verify your driver availability with drvinfo. I'd prefer new code uses board from the get-go though if board code is really needed.

I got it working but we have decided to update the hardware to reset the TPM after your colleague mentioned how it should be done correctly :)

Just to be clear. I can now remove board.c as you first mentioned since I don't need any special stuff.

Great!

Quoted 1 line

Also I need to update imx_v7_defconfig with this board with default value yes.

This is optional. I'd recommend you do it, so you benefit from build-time coverage for your board-specific code.

Cheers,
Ahmad

Quoted 63 lines
Quoted 62 lines

Cheers,
Ahmad

Quoted 43 lines
Quoted 43 lines
Quoted 16 lines
Quoted 15 lines

Review

Quoted 11 lines
(quoted diff) +9 -0
+}
+
+static void __noreturn kamstrup_mx7_board_restart_gpio(struct restart_handler *rst)
+{
+     imx7_setup_pad(MX7D_PAD_ENET1_TX_CLK__GPIO7_IO12);
+
+     gpio_direction_output(BOARD_RESTART_GPIO, 0);
+     mdelay(1);
+     gpio_set_value(BOARD_RESTART_GPIO, 0);

I just sent out a patch[1] with a driver implementing the "gpio-restart" device tree binding. Could you test that one and use it here instead?

Quoted 2 lines

I have applied the patches on a master branch (Last patch failed to apply but was only watchdog) and the gpio-restart works perfectly.

Thanks for testing! You can add your Tested-By on the patch in question if you like.

Quoted 16 lines
Quoted 15 lines

Review

Quoted 10 lines
(quoted diff) +9 -0
+
+     hang();
+}
+
+static int kamstrup_mx7_concentrator_coredevices_init(void)
+{
+     kamstrup_mx7_tpm_reset();
+     restart_handler_register_fn("board", kamstrup_mx7_board_restart_gpio);
+     barebox_set_model("Kamstrup OMNIA Concentrator");

The default model name is "Kamstrup OMNIA Flex Concentrator". If that's too long, you could override /model in the barebox device tree. With the changes suggested above, you could drop board.c then altogether.

Quoted 1 line

I'll move this into the device tree or delete it entirely.

Great. :-)

Quoted 9 lines
Quoted 8 lines

Cheers,
Ahmad

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw
In reply to Ahmad Fatoum
Quoted 39 lines · Ahmad Fatoum

Hello Lars,

Quoted 19 lines · Lars Pedersen
Quoted 10 lines
Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +10 -0
+#define BOARD_RESTART_GPIO IMX_GPIO_NR(7, 12)
+#define TPM_RESET_GPIO IMX_GPIO_NR(3, 8)
+
+static void kamstrup_mx7_tpm_reset(void)
+{
+     imx7_setup_pad(MX7D_PAD_LCD_DATA03__GPIO3_IO8);
+
+     gpio_request(TPM_RESET_GPIO, "tpm-reset");
+     gpio_direction_output(TPM_RESET_GPIO, 1);
+     mdelay(100);
Quoted 8 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 29

Quoted 4 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +4 -0
+     gpio_set_value(TPM_RESET_GPIO, 0);
+     mdelay(100);
+     gpio_set_value(TPM_RESET_GPIO, 1);
+     gpio_free(TPM_RESET_GPIO);

We are trying to cut down on code that doesn't use the driver model. Couldn't this be represented as a gpio-hog in the device tree or a reset line for the SPI device?

Quoted 2 lines

I can't find anything in the DT binding for the SPI/TPM driver to use a reset line.

Proper way would be for this to be added into Linux then, but that's out of scope for the patch here.

Quoted 2 lines

Can a DT gpio-hog toggle the pin? Don't you need a driver for this?

You can't pulse with a gpio-hog. I assumed the TPM is in reset by default.

Quoted 4 lines

I see the following options:

1) gpio-hog with a label and use new gpiolib in board.c.
2) gpio-hog and control the pin in a boot script.

Quoted 8 lines

If there's no straight-forward way to do it without board code, it's ok the way it is with one change though: I missed it the first time, but your board breaks multi-image support because you don't check whether the initcall is indeed running on your board (See for example imx_v7_defconfig, which builds over a hundred boards at once).

Easiest way to get this right is to write a board driver. See arch/arm/boards/lxa-mc1/board.c for an example.

TPMs usually don't have a reset line since it is a hardware misdesign if the reset needs to be done within the bootloader. This opens up the TPM to an attack where the system is properly booted, unlocking keys which are only accessible if the correct PCR sequence is send to the TPM. Than the attacker resets the hardware/CPU, but potentially loads up a different bootloader or tricks the bootloader into skipping the TPM reset. This will leave the TPM keys accessible even if the system has not been booted with the correct measured boot values. Boards with TPMs should be designed so that a CPU-Reset always results in a TPM Reset as well.

Regards,
Rouven

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#9 lore raw

Hello Rouven.

Thanks for your response.

We will need another hardware update before production so we will try to get this added.

Regards,
Lars Pedersen

Quoted 61 lines · Rouven Czerwinski
Quoted 39 lines · Ahmad Fatoum

Hello Lars,

Quoted 19 lines · Lars Pedersen
Quoted 10 lines
Quoted 10 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +10 -0
+#define BOARD_RESTART_GPIO IMX_GPIO_NR(7, 12)
+#define TPM_RESET_GPIO IMX_GPIO_NR(3, 8)
+
+static void kamstrup_mx7_tpm_reset(void)
+{
+     imx7_setup_pad(MX7D_PAD_LCD_DATA03__GPIO3_IO8);
+
+     gpio_request(TPM_RESET_GPIO, "tpm-reset");
+     gpio_direction_output(TPM_RESET_GPIO, 1);
+     mdelay(100);
Quoted 8 lines

arch/arm/boards/kamstrup-mx7-concentrator/board.c line 29

Quoted 4 lines
arch/arm/boards/kamstrup-mx7-concentrator/board.c new file +4 -0
+     gpio_set_value(TPM_RESET_GPIO, 0);
+     mdelay(100);
+     gpio_set_value(TPM_RESET_GPIO, 1);
+     gpio_free(TPM_RESET_GPIO);

We are trying to cut down on code that doesn't use the driver model. Couldn't this be represented as a gpio-hog in the device tree or a reset line for the SPI device?

Quoted 2 lines

I can't find anything in the DT binding for the SPI/TPM driver to use a reset line.

Proper way would be for this to be added into Linux then, but that's out of scope for the patch here.

Quoted 2 lines

Can a DT gpio-hog toggle the pin? Don't you need a driver for this?

You can't pulse with a gpio-hog. I assumed the TPM is in reset by default.

Quoted 4 lines

I see the following options:

1) gpio-hog with a label and use new gpiolib in board.c.
2) gpio-hog and control the pin in a boot script.

Quoted 8 lines

If there's no straight-forward way to do it without board code, it's ok the way it is with one change though: I missed it the first time, but your board breaks multi-image support because you don't check whether the initcall is indeed running on your board (See for example imx_v7_defconfig, which builds over a hundred boards at once).

Easiest way to get this right is to write a board driver. See arch/arm/boards/lxa-mc1/board.c for an example.

TPMs usually don't have a reset line since it is a hardware misdesign if the reset needs to be done within the bootloader. This opens up the TPM to an attack where the system is properly booted, unlocking keys which are only accessible if the correct PCR sequence is send to the TPM. Than the attacker resets the hardware/CPU, but potentially loads up a different bootloader or tricks the bootloader into skipping the TPM reset. This will leave the TPM keys accessible even if the system has not been booted with the correct measured boot values. Boards with TPMs should be designed so that a CPU-Reset always results in a TPM Reset as well.

Quoted 3 lines

Regards,
Rouven

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox