mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/9] RK3568 updates
@ 2021-10-11  8:03 Sascha Hauer
  2021-10-11  8:03 ` [PATCH 1/9] phy: rockchip: Add dummy driver for child node Sascha Hauer
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

This series has some updates for the Rockchip RK3568 support

Sascha Hauer (9):
  phy: rockchip: Add dummy driver for child node
  ARM: Rockchip rk3568 EVB: Enable deep probe
  ARM: Rockchip: rk3568 EVB: use 64bit partition sizes
  phy: rockchip-inno-usb2: handle disabled child nodes gracefully
  usb: dwc3: reset controller before using it
  usb: dwc3: Clarify error message
  ARM: rk3568: Detect USB boot
  cdev: Add function to get unallocated start of device
  ARM: Rockchip: RK3568: implement failsafe barebox update

 arch/arm/boards/rockchip-rk3568-evb/board.c   |   7 +-
 arch/arm/dts/rk3568-evb1-v10.dts              |  22 +---
 arch/arm/mach-rockchip/Makefile               |   1 +
 arch/arm/mach-rockchip/bbu.c                  | 117 ++++++++++++++++++
 arch/arm/mach-rockchip/include/mach/bbu.h     |   9 +-
 arch/arm/mach-rockchip/rk3568.c               |   5 +
 common/partitions.c                           |  28 +++++
 drivers/phy/rockchip/phy-rockchip-inno-usb2.c |  12 +-
 drivers/usb/dwc3/core.c                       |  15 ++-
 drivers/usb/dwc3/core.h                       |   2 +
 include/driver.h                              |   1 +
 11 files changed, 195 insertions(+), 24 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/bbu.c

-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/9] phy: rockchip: Add dummy driver for child node
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11  8:03 ` [PATCH 2/9] ARM: Rockchip rk3568 EVB: Enable deep probe Sascha Hauer
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

To satisfy deep probe mechanism.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index bb1a5c747e..37c2ae1d16 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -423,6 +423,7 @@ static int rockchip_usb2phy_probe(struct device_d *dev)
 	for_each_child_of_node(np, child) {
 		struct rockchip_usb2phy_phy *p;
 		struct phy *phy;
+		struct device_d *phydev;
 
 		if (!strcmp(child->name, "host-port")) {
 			port = USB2PHY_PORT_OTG;
@@ -436,7 +437,10 @@ static int rockchip_usb2phy_probe(struct device_d *dev)
 		if (rphy->phys[port].phy)
 			return -EINVAL;
 
-		phy = phy_create(dev, child, &rockchip_usb2phy_ops);
+		phydev = of_platform_device_create(child, dev);
+		of_platform_device_dummy_drv(phydev);
+
+		phy = phy_create(phydev, child, &rockchip_usb2phy_ops);
 		if (IS_ERR(phy)) {
 			ret = PTR_ERR(phy);
 			if (ret != -EPROBE_DEFER)
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 2/9] ARM: Rockchip rk3568 EVB: Enable deep probe
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
  2021-10-11  8:03 ` [PATCH 1/9] phy: rockchip: Add dummy driver for child node Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11  8:03 ` [PATCH 3/9] ARM: Rockchip: rk3568 EVB: use 64bit partition sizes Sascha Hauer
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

The rk3568 EVB board is successfully tested with deep probe support,
enable it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/rockchip-rk3568-evb/board.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
index 9cd84d7fb9..2d472d1331 100644
--- a/arch/arm/boards/rockchip-rk3568-evb/board.c
+++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
@@ -10,6 +10,7 @@
 #include <environment.h>
 #include <globalvar.h>
 #include <magicvar.h>
+#include <deep-probe.h>
 
 static bool machine_is_rk3568_evb = false;
 
@@ -45,6 +46,8 @@ static struct driver_d rk3568_evb_board_driver = {
 };
 coredevice_platform_driver(rk3568_evb_board_driver);
 
+BAREBOX_DEEP_PROBE_ENABLE(rk3568_evb_of_match);
+
 static int rk3568_evb_detect_hwid(void)
 {
 	int ret;
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 3/9] ARM: Rockchip: rk3568 EVB: use 64bit partition sizes
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
  2021-10-11  8:03 ` [PATCH 1/9] phy: rockchip: Add dummy driver for child node Sascha Hauer
  2021-10-11  8:03 ` [PATCH 2/9] ARM: Rockchip rk3568 EVB: Enable deep probe Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11  8:03 ` [PATCH 4/9] phy: rockchip-inno-usb2: handle disabled child nodes gracefully Sascha Hauer
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

The ofpart partition fixup will use #address-cells = <2> and #size-cells
= <2>. Use the same in the dts file to make the diff between the live
tree and its fixed version smaller.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/dts/rk3568-evb1-v10.dts | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/arm/dts/rk3568-evb1-v10.dts b/arch/arm/dts/rk3568-evb1-v10.dts
index bd583015e8..ebfd45ada8 100644
--- a/arch/arm/dts/rk3568-evb1-v10.dts
+++ b/arch/arm/dts/rk3568-evb1-v10.dts
@@ -472,17 +472,17 @@
 
 	partitions {
 		compatible = "fixed-partitions";
-		#address-cells = <1>;
-		#size-cells = <1>;
+		#address-cells = <2>;
+		#size-cells = <2>;
 
 		partition@8000 {
 			label = "barebox";
-			reg = <0x8000 0x400000>;
+			reg = <0x0 0x8000 0x0 0x400000>;
 		};
 
 		environment_emmc: partition@408000 {
 			label = "barebox-environment";
-			reg = <0x408000 0x8000>;
+			reg = <0x0 0x408000 0x0 0x8000>;
 		};
 	};
 };
@@ -503,17 +503,17 @@
 
 	partitions {
 		compatible = "fixed-partitions";
-		#address-cells = <1>;
-		#size-cells = <1>;
+		#address-cells = <2>;
+		#size-cells = <2>;
 
 		partition@8000 {
 			label = "barebox";
-			reg = <0x8000 0x400000>;
+			reg = <0x0 0x8000 0x0 0x400000>;
 		};
 
 		environment_sd: partition@408000 {
 			label = "barebox-environment";
-			reg = <0x408000 0x8000>;
+			reg = <0x0 0x408000 0x0 0x8000>;
 		};
 	};
 };
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 4/9] phy: rockchip-inno-usb2: handle disabled child nodes gracefully
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
                   ` (2 preceding siblings ...)
  2021-10-11  8:03 ` [PATCH 3/9] ARM: Rockchip: rk3568 EVB: use 64bit partition sizes Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11  8:03 ` [PATCH 5/9] usb: dwc3: reset controller before using it Sascha Hauer
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

When child nodes of the phy node are disabled then
of_platform_device_create() on them returns a NULL pointer. Make sure we
skip initialization for these disabled nodes and also skip them when
iterating over them in the xlate function.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index 37c2ae1d16..6b9d54f344 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -264,6 +264,9 @@ static struct phy *rockchip_usb2phy_of_xlate(struct device_d *dev,
 	int port;
 
 	for (port = 0; port < 2; port++) {
+		if (!rphy->phys[port].phy)
+			continue;
+
 		if (phynode == rphy->phys[port].phy->dev.device_node) {
 			p = &rphy->phys[port];
 			return p->phy;
@@ -438,6 +441,9 @@ static int rockchip_usb2phy_probe(struct device_d *dev)
 			return -EINVAL;
 
 		phydev = of_platform_device_create(child, dev);
+		if (!phydev)
+			continue;
+
 		of_platform_device_dummy_drv(phydev);
 
 		phy = phy_create(phydev, child, &rockchip_usb2phy_ops);
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 5/9] usb: dwc3: reset controller before using it
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
                   ` (3 preceding siblings ...)
  2021-10-11  8:03 ` [PATCH 4/9] phy: rockchip-inno-usb2: handle disabled child nodes gracefully Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11  8:03 ` [PATCH 6/9] usb: dwc3: Clarify error message Sascha Hauer
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

Some dwc3 controllers have a reset assigned to them. Request it and
reset the device before using it.
Linux upstream driver uses an array of resets here, but in barebox we
currently do have this functionality, so for now use the first reset
only.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/dwc3/core.c | 11 +++++++++++
 drivers/usb/dwc3/core.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 04b700d12d..f618435cb6 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -14,6 +14,7 @@
 #include <dma.h>
 #include <driver.h>
 #include <init.h>
+#include <linux/reset.h>
 
 #include "gadget.h"
 #include "core.h"
@@ -1125,6 +1126,16 @@ static int dwc3_probe(struct device_d *dev)
 	if (ret)
 		return ret;
 
+	dwc->reset = reset_control_get(dev, NULL);
+	if (IS_ERR(dwc->reset)) {
+		dev_err(dev, "Failed to get reset control: %pe\n", dwc->reset);
+		return PTR_ERR(dwc->reset);
+	}
+
+	reset_control_assert(dwc->reset);
+	mdelay(1);
+	reset_control_deassert(dwc->reset);
+
 	dwc3_coresoft_reset(dwc);
 
 	dwc3_cache_hwparams(dwc);
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index f2f7a311d1..94cc594920 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1003,6 +1003,8 @@ struct dwc3 {
 	struct clk_bulk_data	*clks;
 	int			num_clks;
 
+	struct reset_control	*reset;
+
 	struct phy		*usb2_generic_phy;
 	struct phy		*usb3_generic_phy;
 
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 6/9] usb: dwc3: Clarify error message
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
                   ` (4 preceding siblings ...)
  2021-10-11  8:03 ` [PATCH 5/9] usb: dwc3: reset controller before using it Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11 17:43   ` Trent Piepho
  2021-10-11  8:03 ` [PATCH 7/9] ARM: rk3568: Detect USB boot Sascha Hauer
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

When the DWC3 controller uses a mode which is currently not compiled
into barebox we answer with "Controller does not support ... mode". Make
clear that it's not the controller which doesn't support it, but the
currently running barebox.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/dwc3/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index f618435cb6..17caf136ef 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -43,7 +43,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
 	case DWC3_GHWPARAMS0_MODE_GADGET:
 		if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
 			dev_err(dev,
-				"Controller does not support host mode.\n");
+				"This barebox does not support DWC3 host mode.\n");
 			return -EINVAL;
 		}
 		mode = USB_DR_MODE_PERIPHERAL;
@@ -51,7 +51,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
 	case DWC3_GHWPARAMS0_MODE_HOST:
 		if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
 			dev_err(dev,
-				"Controller does not support device mode.\n");
+				"This barebox does not support DWC3 device mode.\n");
 			return -EINVAL;
 		}
 		mode = USB_DR_MODE_HOST;
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 7/9] ARM: rk3568: Detect USB boot
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
                   ` (5 preceding siblings ...)
  2021-10-11  8:03 ` [PATCH 6/9] usb: dwc3: Clarify error message Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11 17:53   ` Trent Piepho
  2021-10-11  8:03 ` [PATCH 8/9] cdev: Add function to get unallocated start of device Sascha Hauer
  2021-10-11  8:03 ` [PATCH 9/9] ARM: Rockchip: RK3568: implement failsafe barebox update Sascha Hauer
  8 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

The table of register content to bootsource mapping has been taken from
the vendor U-Boot. This table lacks an entry for USB boot. Add this
entry. It's unknown if this entry is entirely correct, it reflects the
value read from the register when doing USB boot.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-rockchip/rk3568.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/mach-rockchip/rk3568.c b/arch/arm/mach-rockchip/rk3568.c
index fcf3cb7053..35c4afd4c2 100644
--- a/arch/arm/mach-rockchip/rk3568.c
+++ b/arch/arm/mach-rockchip/rk3568.c
@@ -151,6 +151,11 @@ static struct rk_bootsource bootdev_map[] = {
 	{ .src = BOOTSOURCE_SPI_NOR, .instance = 0 },
 	{ .src = BOOTSOURCE_SPI_NAND, .instance = 0 },
 	{ .src = BOOTSOURCE_MMC, .instance = 1 },
+	{ .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
+	{ .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
+	{ .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
+	{ .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
+	{ .src = BOOTSOURCE_USB, .instance = 0 },
 };
 
 static enum bootsource rk3568_bootsource(void)
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 8/9] cdev: Add function to get unallocated start of device
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
                   ` (6 preceding siblings ...)
  2021-10-11  8:03 ` [PATCH 7/9] ARM: rk3568: Detect USB boot Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11  8:03 ` [PATCH 9/9] ARM: Rockchip: RK3568: implement failsafe barebox update Sascha Hauer
  8 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

On several SoCs barebox is written to the raw device in front of the
first partition. So far we blindly trust that there is enough space
available for the barebox image. Start changing this by adding a
function that retrieves the available space.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/partitions.c | 28 ++++++++++++++++++++++++++++
 include/driver.h    |  1 +
 2 files changed, 29 insertions(+)

diff --git a/common/partitions.c b/common/partitions.c
index d80878e065..e36341fc1e 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -156,3 +156,31 @@ int partition_parser_register(struct partition_parser *p)
 
 	return 0;
 }
+
+/**
+ * cdev_unallocated_start - return unallocated space
+ * @name: The cdev name
+ *
+ * This function returns the space that is not allocated by any partition
+ * at the start of a device.
+ *
+ * Return: The unallocated space at the start of the device in bytes
+ */
+loff_t cdev_unallocated_start(const char *name)
+{
+	struct cdev *cdev, *partcdev;
+	loff_t start;
+
+	cdev = cdev_by_name(name);
+	if (!cdev)
+		return 0;
+
+	start = cdev->size;
+
+	list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
+		if (partcdev->offset < start)
+			start = partcdev->offset;
+	}
+
+	return start;
+}
diff --git a/include/driver.h b/include/driver.h
index c7f5903fce..38aa3cf8f5 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -494,6 +494,7 @@ ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulo
 ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags);
 int cdev_ioctl(struct cdev *cdev, int cmd, void *buf);
 int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset);
+loff_t cdev_unallocated_start(const char *name);
 
 #define DEVFS_PARTITION_FIXED		(1U << 0)
 #define DEVFS_PARTITION_READONLY	(1U << 1)
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 9/9] ARM: Rockchip: RK3568: implement failsafe barebox update
  2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
                   ` (7 preceding siblings ...)
  2021-10-11  8:03 ` [PATCH 8/9] cdev: Add function to get unallocated start of device Sascha Hauer
@ 2021-10-11  8:03 ` Sascha Hauer
  2021-10-11  9:59   ` Michael Riesch
  8 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2021-10-11  8:03 UTC (permalink / raw)
  To: Barebox List

The RK3568 ROM searches for valid boot images at different positions
on SD/eMMC cards. This can be used to implement a failsafe barebox
update which is immune against power failures.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/rockchip-rk3568-evb/board.c |   4 +-
 arch/arm/dts/rk3568-evb1-v10.dts            |  10 --
 arch/arm/mach-rockchip/Makefile             |   1 +
 arch/arm/mach-rockchip/bbu.c                | 117 ++++++++++++++++++++
 arch/arm/mach-rockchip/include/mach/bbu.h   |   9 +-
 5 files changed, 126 insertions(+), 15 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/bbu.c

diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
index 2d472d1331..09385bea29 100644
--- a/arch/arm/boards/rockchip-rk3568-evb/board.c
+++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
@@ -28,8 +28,8 @@ static int rk3568_evb_probe(struct device_d *dev)
 	else
 		of_device_enable_path("/chosen/environment-emmc");
 
-	rk3568_bbu_mmc_register("emmc", BBU_HANDLER_FLAG_DEFAULT, "/dev/emmc.barebox");
-	rk3568_bbu_mmc_register("sd", 0, "/dev/sd.barebox");
+	rk3568_bbu_mmc_register("emmc", BBU_HANDLER_FLAG_DEFAULT, "/dev/emmc");
+	rk3568_bbu_mmc_register("sd", 0, "/dev/sd");
 
 	return 0;
 }
diff --git a/arch/arm/dts/rk3568-evb1-v10.dts b/arch/arm/dts/rk3568-evb1-v10.dts
index ebfd45ada8..6f1eebc619 100644
--- a/arch/arm/dts/rk3568-evb1-v10.dts
+++ b/arch/arm/dts/rk3568-evb1-v10.dts
@@ -475,11 +475,6 @@
 		#address-cells = <2>;
 		#size-cells = <2>;
 
-		partition@8000 {
-			label = "barebox";
-			reg = <0x0 0x8000 0x0 0x400000>;
-		};
-
 		environment_emmc: partition@408000 {
 			label = "barebox-environment";
 			reg = <0x0 0x408000 0x0 0x8000>;
@@ -506,11 +501,6 @@
 		#address-cells = <2>;
 		#size-cells = <2>;
 
-		partition@8000 {
-			label = "barebox";
-			reg = <0x0 0x8000 0x0 0x400000>;
-		};
-
 		environment_sd: partition@408000 {
 			label = "barebox-environment";
 			reg = <0x0 0x408000 0x0 0x8000>;
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index ebaa3a5450..66bcdba2eb 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_ARCH_RK3188) += rk3188.o
 obj-$(CONFIG_ARCH_RK3288) += rk3288.o
 obj-pbl-$(CONFIG_ARCH_RK3568) += rk3568.o
 obj-$(CONFIG_ARCH_RK3568) += bootm.o
+obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
diff --git a/arch/arm/mach-rockchip/bbu.c b/arch/arm/mach-rockchip/bbu.c
new file mode 100644
index 0000000000..6bfba95133
--- /dev/null
+++ b/arch/arm/mach-rockchip/bbu.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <common.h>
+#include <malloc.h>
+#include <bbu.h>
+#include <filetype.h>
+#include <errno.h>
+#include <fs.h>
+#include <fcntl.h>
+#include <linux/sizes.h>
+#include <linux/stat.h>
+#include <ioctl.h>
+#include <environment.h>
+#include <mach/bbu.h>
+#include <libfile.h>
+
+/* The MaskROM looks for images on these four locations: */
+#define IMG_OFFSET_0	(0 * SZ_1K + SZ_32K)
+#define IMG_OFFSET_1	(512 * SZ_1K + SZ_32K)
+#define IMG_OFFSET_2	(1024 * SZ_1K + SZ_32K)
+#define IMG_OFFSET_3	(1536 * SZ_1K + SZ_32K)
+#define IMG_OFFSET_4	(2048 * SZ_1K + SZ_32K)
+
+/*
+ * The strategy here is:
+ * The MaskROM iterates over the above four locations until it finds a valid
+ * boot image. The images are protected with sha sums, so any change to an
+ * image on disk is invalidating it. We first check if we have enough space to
+ * write two copies of barebox. To make it simple we only use IMG_OFFSET_0 and
+ * IMG_OFFSET_4 which leaves the maximum size for a single image. When there's
+ * not enough free space on the beginning of the disk we only write a single
+ * image. When we have enough space for two images we first write the second one
+ * (leaving the first one intact). Afterwards we write the first one which
+ * leaves the previously written second image as a fallback in case writing the
+ * first one gets interrupted.
+ * This mechanism assumes that the first image is valid which isn't the case
+ * when the previous update has been interrupted. Two power failures in a row
+ * can leave the board unbootable. To prevent that we would have to be able
+ * to detect valid images to determine the order in which we write the two
+ * images.
+ */
+static int rk3568_bbu_mmc_handler(struct bbu_handler *handler,
+				  struct bbu_data *data)
+{
+	enum filetype filetype;
+	int ret, fd;
+	loff_t space;
+
+	filetype = file_detect_type(data->image, data->len);
+	if (filetype != filetype_rockchip_rkns_image) {
+		if (!bbu_force(data, "incorrect image type. Expected: %s, got %s",
+				file_type_to_string(filetype_rockchip_rkns_image),
+				file_type_to_string(filetype)))
+			return -EINVAL;
+	}
+
+	device_detect_by_name(devpath_to_name(data->devicefile));
+
+	ret = bbu_confirm(data);
+	if (ret)
+		return ret;
+
+	space = cdev_unallocated_start(devpath_to_name(data->devicefile));
+
+	if (space < IMG_OFFSET_0 + data->len) {
+		pr_err("Unallocated space on %s is too small for one image\n", data->devicefile);
+		return -ENOSPC;
+	}
+
+	fd = open(data->devicefile, O_WRONLY);
+	if (fd < 0)
+		return fd;
+        
+	if (space >= IMG_OFFSET_4 + data->len) {
+		pr_info("Unallocated space is enough for two copies, doing failsafe update\n");
+
+		ret = pwrite_full(fd, data->image, data->len, IMG_OFFSET_4);
+		if (ret < 0) {
+			pr_err("writing to %s failed with %s\n", data->devicefile,
+				strerror(-ret));
+			goto err_close;
+		}
+	}
+
+	ret = pwrite_full(fd, data->image, data->len, IMG_OFFSET_0);
+	if (ret < 0) {
+		pr_err("writing to %s failed with %s\n", data->devicefile,
+			strerror(-ret));
+		goto err_close;
+	}
+
+	ret = 0;
+
+err_close:
+	close(fd);
+
+	return ret;
+}
+
+int rk3568_bbu_mmc_register(const char *name, unsigned long flags,
+                const char *devicefile)
+{
+	struct bbu_handler *handler;
+	int ret;
+
+	handler = xzalloc(sizeof(*handler));
+
+	handler->flags = flags;
+	handler->devicefile = devicefile;
+	handler->name = name;
+	handler->handler = rk3568_bbu_mmc_handler;
+
+	ret = bbu_register_handler(handler);
+	if (ret)
+		free(handler);
+
+	return ret;
+}
diff --git a/arch/arm/mach-rockchip/include/mach/bbu.h b/arch/arm/mach-rockchip/include/mach/bbu.h
index e61e0615e2..7fb08a0a9e 100644
--- a/arch/arm/mach-rockchip/include/mach/bbu.h
+++ b/arch/arm/mach-rockchip/include/mach/bbu.h
@@ -3,12 +3,15 @@
 
 #include <bbu.h>
 
+#ifdef CONFIG_BAREBOX_UPDATE
+int rk3568_bbu_mmc_register(const char *name, unsigned long flags,
+                const char *devicefile);
+#else
 static inline int rk3568_bbu_mmc_register(const char *name, unsigned long flags,
                 const char *devicefile)
 {
-	return bbu_register_std_file_update(name, flags,
-                devicefile, filetype_rockchip_rkns_image);
-
+	return -ENOSYS;
 }
+#endif
 
 # endif /* __MACH_ROCKCHIP_BBU_H */
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 9/9] ARM: Rockchip: RK3568: implement failsafe barebox update
  2021-10-11  8:03 ` [PATCH 9/9] ARM: Rockchip: RK3568: implement failsafe barebox update Sascha Hauer
@ 2021-10-11  9:59   ` Michael Riesch
  0 siblings, 0 replies; 15+ messages in thread
From: Michael Riesch @ 2021-10-11  9:59 UTC (permalink / raw)
  To: barebox, Sascha Hauer

Hello Sascha,

On 10/11/21 10:03 AM, Sascha Hauer wrote:
> The RK3568 ROM searches for valid boot images at different positions
> on SD/eMMC cards. This can be used to implement a failsafe barebox
> update which is immune against power failures.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/boards/rockchip-rk3568-evb/board.c |   4 +-
>  arch/arm/dts/rk3568-evb1-v10.dts            |  10 --
>  arch/arm/mach-rockchip/Makefile             |   1 +
>  arch/arm/mach-rockchip/bbu.c                | 117 ++++++++++++++++++++
>  arch/arm/mach-rockchip/include/mach/bbu.h   |   9 +-
>  5 files changed, 126 insertions(+), 15 deletions(-)
>  create mode 100644 arch/arm/mach-rockchip/bbu.c
> 
> diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
> index 2d472d1331..09385bea29 100644
> --- a/arch/arm/boards/rockchip-rk3568-evb/board.c
> +++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
> @@ -28,8 +28,8 @@ static int rk3568_evb_probe(struct device_d *dev)
>  	else
>  		of_device_enable_path("/chosen/environment-emmc");
>  
> -	rk3568_bbu_mmc_register("emmc", BBU_HANDLER_FLAG_DEFAULT, "/dev/emmc.barebox");
> -	rk3568_bbu_mmc_register("sd", 0, "/dev/sd.barebox");
> +	rk3568_bbu_mmc_register("emmc", BBU_HANDLER_FLAG_DEFAULT, "/dev/emmc");
> +	rk3568_bbu_mmc_register("sd", 0, "/dev/sd");
>  
>  	return 0;
>  }
> diff --git a/arch/arm/dts/rk3568-evb1-v10.dts b/arch/arm/dts/rk3568-evb1-v10.dts
> index ebfd45ada8..6f1eebc619 100644
> --- a/arch/arm/dts/rk3568-evb1-v10.dts
> +++ b/arch/arm/dts/rk3568-evb1-v10.dts
> @@ -475,11 +475,6 @@
>  		#address-cells = <2>;
>  		#size-cells = <2>;
>  
> -		partition@8000 {
> -			label = "barebox";
> -			reg = <0x0 0x8000 0x0 0x400000>;
> -		};
> -
>  		environment_emmc: partition@408000 {
>  			label = "barebox-environment";
>  			reg = <0x0 0x408000 0x0 0x8000>;
> @@ -506,11 +501,6 @@
>  		#address-cells = <2>;
>  		#size-cells = <2>;
>  
> -		partition@8000 {
> -			label = "barebox";
> -			reg = <0x0 0x8000 0x0 0x400000>;
> -		};
> -
>  		environment_sd: partition@408000 {
>  			label = "barebox-environment";
>  			reg = <0x0 0x408000 0x0 0x8000>;
> diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
> index ebaa3a5450..66bcdba2eb 100644
> --- a/arch/arm/mach-rockchip/Makefile
> +++ b/arch/arm/mach-rockchip/Makefile
> @@ -4,3 +4,4 @@ obj-$(CONFIG_ARCH_RK3188) += rk3188.o
>  obj-$(CONFIG_ARCH_RK3288) += rk3288.o
>  obj-pbl-$(CONFIG_ARCH_RK3568) += rk3568.o
>  obj-$(CONFIG_ARCH_RK3568) += bootm.o
> +obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
> diff --git a/arch/arm/mach-rockchip/bbu.c b/arch/arm/mach-rockchip/bbu.c
> new file mode 100644
> index 0000000000..6bfba95133
> --- /dev/null
> +++ b/arch/arm/mach-rockchip/bbu.c
> @@ -0,0 +1,117 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +#include <common.h>
> +#include <malloc.h>
> +#include <bbu.h>
> +#include <filetype.h>
> +#include <errno.h>
> +#include <fs.h>
> +#include <fcntl.h>
> +#include <linux/sizes.h>
> +#include <linux/stat.h>
> +#include <ioctl.h>
> +#include <environment.h>
> +#include <mach/bbu.h>
> +#include <libfile.h>
> +
> +/* The MaskROM looks for images on these four locations: */
> +#define IMG_OFFSET_0	(0 * SZ_1K + SZ_32K)
> +#define IMG_OFFSET_1	(512 * SZ_1K + SZ_32K)
> +#define IMG_OFFSET_2	(1024 * SZ_1K + SZ_32K)
> +#define IMG_OFFSET_3	(1536 * SZ_1K + SZ_32K)
> +#define IMG_OFFSET_4	(2048 * SZ_1K + SZ_32K)

That's five locations, isn't it?

> +
> +/*
> + * The strategy here is:
> + * The MaskROM iterates over the above four locations until it finds a valid

Five?

Best regards,
Michael

> + * boot image. The images are protected with sha sums, so any change to an
> + * image on disk is invalidating it. We first check if we have enough space to
> + * write two copies of barebox. To make it simple we only use IMG_OFFSET_0 and
> + * IMG_OFFSET_4 which leaves the maximum size for a single image. When there's
> + * not enough free space on the beginning of the disk we only write a single
> + * image. When we have enough space for two images we first write the second one
> + * (leaving the first one intact). Afterwards we write the first one which
> + * leaves the previously written second image as a fallback in case writing the
> + * first one gets interrupted.
> + * This mechanism assumes that the first image is valid which isn't the case
> + * when the previous update has been interrupted. Two power failures in a row
> + * can leave the board unbootable. To prevent that we would have to be able
> + * to detect valid images to determine the order in which we write the two
> + * images.
> + */
> +static int rk3568_bbu_mmc_handler(struct bbu_handler *handler,
> +				  struct bbu_data *data)
> +{
> +	enum filetype filetype;
> +	int ret, fd;
> +	loff_t space;
> +
> +	filetype = file_detect_type(data->image, data->len);
> +	if (filetype != filetype_rockchip_rkns_image) {
> +		if (!bbu_force(data, "incorrect image type. Expected: %s, got %s",
> +				file_type_to_string(filetype_rockchip_rkns_image),
> +				file_type_to_string(filetype)))
> +			return -EINVAL;
> +	}
> +
> +	device_detect_by_name(devpath_to_name(data->devicefile));
> +
> +	ret = bbu_confirm(data);
> +	if (ret)
> +		return ret;
> +
> +	space = cdev_unallocated_start(devpath_to_name(data->devicefile));
> +
> +	if (space < IMG_OFFSET_0 + data->len) {
> +		pr_err("Unallocated space on %s is too small for one image\n", data->devicefile);
> +		return -ENOSPC;
> +	}
> +
> +	fd = open(data->devicefile, O_WRONLY);
> +	if (fd < 0)
> +		return fd;
> +        
> +	if (space >= IMG_OFFSET_4 + data->len) {
> +		pr_info("Unallocated space is enough for two copies, doing failsafe update\n");
> +
> +		ret = pwrite_full(fd, data->image, data->len, IMG_OFFSET_4);
> +		if (ret < 0) {
> +			pr_err("writing to %s failed with %s\n", data->devicefile,
> +				strerror(-ret));
> +			goto err_close;
> +		}
> +	}
> +
> +	ret = pwrite_full(fd, data->image, data->len, IMG_OFFSET_0);
> +	if (ret < 0) {
> +		pr_err("writing to %s failed with %s\n", data->devicefile,
> +			strerror(-ret));
> +		goto err_close;
> +	}
> +
> +	ret = 0;
> +
> +err_close:
> +	close(fd);
> +
> +	return ret;
> +}
> +
> +int rk3568_bbu_mmc_register(const char *name, unsigned long flags,
> +                const char *devicefile)
> +{
> +	struct bbu_handler *handler;
> +	int ret;
> +
> +	handler = xzalloc(sizeof(*handler));
> +
> +	handler->flags = flags;
> +	handler->devicefile = devicefile;
> +	handler->name = name;
> +	handler->handler = rk3568_bbu_mmc_handler;
> +
> +	ret = bbu_register_handler(handler);
> +	if (ret)
> +		free(handler);
> +
> +	return ret;
> +}
> diff --git a/arch/arm/mach-rockchip/include/mach/bbu.h b/arch/arm/mach-rockchip/include/mach/bbu.h
> index e61e0615e2..7fb08a0a9e 100644
> --- a/arch/arm/mach-rockchip/include/mach/bbu.h
> +++ b/arch/arm/mach-rockchip/include/mach/bbu.h
> @@ -3,12 +3,15 @@
>  
>  #include <bbu.h>
>  
> +#ifdef CONFIG_BAREBOX_UPDATE
> +int rk3568_bbu_mmc_register(const char *name, unsigned long flags,
> +                const char *devicefile);
> +#else
>  static inline int rk3568_bbu_mmc_register(const char *name, unsigned long flags,
>                  const char *devicefile)
>  {
> -	return bbu_register_std_file_update(name, flags,
> -                devicefile, filetype_rockchip_rkns_image);
> -
> +	return -ENOSYS;
>  }
> +#endif
>  
>  # endif /* __MACH_ROCKCHIP_BBU_H */
> 

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/9] usb: dwc3: Clarify error message
  2021-10-11  8:03 ` [PATCH 6/9] usb: dwc3: Clarify error message Sascha Hauer
@ 2021-10-11 17:43   ` Trent Piepho
  2021-10-12  7:10     ` Sascha Hauer
  0 siblings, 1 reply; 15+ messages in thread
From: Trent Piepho @ 2021-10-11 17:43 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Mon, Oct 11, 2021 at 1:04 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
>         case DWC3_GHWPARAMS0_MODE_GADGET:
>                 if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
>                         dev_err(dev,
> -                               "Controller does not support host mode.\n");
> +                               "This barebox does not support DWC3 host mode.\n");

Aren't these messages backward?  The hardware is set to device mode,
CONFIG_USB_DWC3_HOST means, "Support only host mode," so it should
fail because Barebox does not support device mode.

Maybe something like: "Barebox built without support for DWC3 USB
device mode (USB_DWC_HOST).\n"  Let the person know what variable to
search for in the config menu to change it.

>                         return -EINVAL;
>                 }
>                 mode = USB_DR_MODE_PERIPHERAL;
> @@ -51,7 +51,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
>         case DWC3_GHWPARAMS0_MODE_HOST:
>                 if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
>                         dev_err(dev,
> -                               "Controller does not support device mode.\n");
> +                               "This barebox does not support DWC3 device mode.\n");
>                         return -EINVAL;
>                 }
>                 mode = USB_DR_MODE_HOST;

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 7/9] ARM: rk3568: Detect USB boot
  2021-10-11  8:03 ` [PATCH 7/9] ARM: rk3568: Detect USB boot Sascha Hauer
@ 2021-10-11 17:53   ` Trent Piepho
  2021-10-12  7:15     ` Sascha Hauer
  0 siblings, 1 reply; 15+ messages in thread
From: Trent Piepho @ 2021-10-11 17:53 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Mon, Oct 11, 2021 at 1:04 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
> @@ -151,6 +151,11 @@ static struct rk_bootsource bootdev_map[] = {
>         { .src = BOOTSOURCE_SPI_NOR, .instance = 0 },
>         { .src = BOOTSOURCE_SPI_NAND, .instance = 0 },
>         { .src = BOOTSOURCE_MMC, .instance = 1 },
> +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> +       { .src = BOOTSOURCE_USB, .instance = 0 },
>  };

Instead of blank entries, one could do designated array initialization
(since BOOTSOURCE_UNKNOWN is 0):

static struct rk_bootsource bootdev_map[] = {
       [0x01] = { .src = BOOTSOURCE_NAND, .instance = 0 },
       [0x02] = { .src = BOOTSOURCE_MMC, .instance = 0 },
       [0x03] = { .src = BOOTSOURCE_SPI_NOR, .instance = 0 },
       [0x04] = { .src = BOOTSOURCE_SPI_NAND, .instance = 0 },
       [0x05] = { .src = BOOTSOURCE_MMC, .instance = 1 },
       [0x0a] =  { .src = BOOTSOURCE_USB, .instance = 0 },
};

I also like the way the register value shows up in the table.

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/9] usb: dwc3: Clarify error message
  2021-10-11 17:43   ` Trent Piepho
@ 2021-10-12  7:10     ` Sascha Hauer
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-12  7:10 UTC (permalink / raw)
  To: Trent Piepho; +Cc: Barebox List

On Mon, Oct 11, 2021 at 10:43:55AM -0700, Trent Piepho wrote:
> On Mon, Oct 11, 2021 at 1:04 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
> >         case DWC3_GHWPARAMS0_MODE_GADGET:
> >                 if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
> >                         dev_err(dev,
> > -                               "Controller does not support host mode.\n");
> > +                               "This barebox does not support DWC3 host mode.\n");
> 
> Aren't these messages backward?  The hardware is set to device mode,
> CONFIG_USB_DWC3_HOST means, "Support only host mode," so it should
> fail because Barebox does not support device mode.

Let's drop this patch. I misread the message as "We want to do device
mode, but only host mode is compiled in", but really it says "Controller
can only do device mode, but we have only host mode complied in". I
wasn't aware that there are DWC3 cores with only host or only device
mode supported.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 7/9] ARM: rk3568: Detect USB boot
  2021-10-11 17:53   ` Trent Piepho
@ 2021-10-12  7:15     ` Sascha Hauer
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2021-10-12  7:15 UTC (permalink / raw)
  To: Trent Piepho; +Cc: Barebox List

On Mon, Oct 11, 2021 at 10:53:07AM -0700, Trent Piepho wrote:
> On Mon, Oct 11, 2021 at 1:04 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > @@ -151,6 +151,11 @@ static struct rk_bootsource bootdev_map[] = {
> >         { .src = BOOTSOURCE_SPI_NOR, .instance = 0 },
> >         { .src = BOOTSOURCE_SPI_NAND, .instance = 0 },
> >         { .src = BOOTSOURCE_MMC, .instance = 1 },
> > +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> > +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> > +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> > +       { .src = BOOTSOURCE_UNKNOWN, .instance = 0 },
> > +       { .src = BOOTSOURCE_USB, .instance = 0 },
> >  };
> 
> Instead of blank entries, one could do designated array initialization
> (since BOOTSOURCE_UNKNOWN is 0):
> 
> static struct rk_bootsource bootdev_map[] = {
>        [0x01] = { .src = BOOTSOURCE_NAND, .instance = 0 },
>        [0x02] = { .src = BOOTSOURCE_MMC, .instance = 0 },
>        [0x03] = { .src = BOOTSOURCE_SPI_NOR, .instance = 0 },
>        [0x04] = { .src = BOOTSOURCE_SPI_NAND, .instance = 0 },
>        [0x05] = { .src = BOOTSOURCE_MMC, .instance = 1 },
>        [0x0a] =  { .src = BOOTSOURCE_USB, .instance = 0 },
> };
> 
> I also like the way the register value shows up in the table.

Apart from the implicit assumption that BOOTSOURCE_UNKNOWN is 0 your
approach is all better. Changed it like that.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-10-12  7:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11  8:03 [PATCH 0/9] RK3568 updates Sascha Hauer
2021-10-11  8:03 ` [PATCH 1/9] phy: rockchip: Add dummy driver for child node Sascha Hauer
2021-10-11  8:03 ` [PATCH 2/9] ARM: Rockchip rk3568 EVB: Enable deep probe Sascha Hauer
2021-10-11  8:03 ` [PATCH 3/9] ARM: Rockchip: rk3568 EVB: use 64bit partition sizes Sascha Hauer
2021-10-11  8:03 ` [PATCH 4/9] phy: rockchip-inno-usb2: handle disabled child nodes gracefully Sascha Hauer
2021-10-11  8:03 ` [PATCH 5/9] usb: dwc3: reset controller before using it Sascha Hauer
2021-10-11  8:03 ` [PATCH 6/9] usb: dwc3: Clarify error message Sascha Hauer
2021-10-11 17:43   ` Trent Piepho
2021-10-12  7:10     ` Sascha Hauer
2021-10-11  8:03 ` [PATCH 7/9] ARM: rk3568: Detect USB boot Sascha Hauer
2021-10-11 17:53   ` Trent Piepho
2021-10-12  7:15     ` Sascha Hauer
2021-10-11  8:03 ` [PATCH 8/9] cdev: Add function to get unallocated start of device Sascha Hauer
2021-10-11  8:03 ` [PATCH 9/9] ARM: Rockchip: RK3568: implement failsafe barebox update Sascha Hauer
2021-10-11  9:59   ` Michael Riesch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox