Skip to contentSkip to conversation

Synology DS414 integration mini-review

PATCH New Phil Sutter 2 participants 30 messages Mar 3, 2021 – Apr 8, 2021

lore
Share & tools
lore
#0 lore raw

cover Synology DS414 integration mini-review

Board-specific code lacked a Kconfig file defining CONFIG_SYS_BOARD, CONFIG_SYS_VENDOR, etc - patch 1 fixes that.

I was very pleased to notice the recent changes in PCI/USB code fixed xhci-pci functionality on DS414, so patch 2 enables XHCI support in defconfig.

Adjusting DS109 atags code for DS414 allowed to successfully boot vendor Linux, so I went ahead and generalized the code to support both boards in patch 3.

Patch 4 introduces a misc_init_r() routine populating environment from Synology's special flash partition if appropriate - less manual work for users and no need for random MAC address fallback anymore.

Patch 6 extends the default environment by a command to update u-boot via tftp.

Phil Sutter (5):
ds414: Add a Kconfig defining some strings
configs: ds414: Enable XHCI_PCI by default
board/Synology: Unify legacy kernel support
ds414: Auto-populate env if appropriate
ds414: Add sample u-boot update command

 board/Synology/common/Makefile  |  5 +++
 board/Synology/common/legacy.c  | 75 +++++++++++++++++++++++++++++++++
 board/Synology/common/legacy.h  | 33 +++++++++++++++
 board/Synology/ds109/ds109.c    | 32 --------------
 board/Synology/ds109/ds109.h    | 17 --------
 board/Synology/ds414/Kconfig    | 12 ++++++
 board/Synology/ds414/cmd_syno.c |  2 +-
 board/Synology/ds414/ds414.c    | 13 ++++++
 configs/ds414_defconfig         |  7 ++-
 include/configs/ds109.h         |  3 +-
 include/configs/ds414.h         | 20 ++++++++-
 11 files changed, 163 insertions(+), 56 deletions(-)
 create mode 100644 board/Synology/common/Makefile
 create mode 100644 board/Synology/common/legacy.c
 create mode 100644 board/Synology/common/legacy.h
 create mode 100644 board/Synology/ds414/Kconfig
Signature · 1 line
2.30.1
#1 lore raw

PATCH 1/5 ds414: Add a Kconfig defining some strings

A rather cosmetic change to conform with other board definitions.

---
 board/Synology/ds414/Kconfig | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 board/Synology/ds414/Kconfig
board/Synology/ds414/Kconfig new file +12 -0
new file mode 100644
index 0000000000000..4d308525546d7
@@ -0,0 +1,12 @@
+if TARGET_DS414
+
+config SYS_BOARD
+	default "ds414"
+
+config SYS_VENDOR
+	default "Synology"
+
+config SYS_CONFIG_NAME
+	default "ds414"
+
+endif
Signature · 1 line
2.30.1
#3 lore raw

PATCH 2/5 configs: ds414: Enable XHCI_PCI by default

In reply to Phil Sutter

With the recent fixes in pci_mvebu and xhci-pci drivers, the two rear USB3 ports are finally usable and accessing them no longer hangs the system.

---
 configs/ds414_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/ds414_defconfig +1 -0
index 3e6dcec3edde3..254e42f84d2e9 100644
@@ -65,5 +65,6 @@ CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
+CONFIG_USB_XHCI_PCI=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
Signature · 1 line
2.30.1
#5 lore raw

PATCH 2/5 configs: ds414: Enable XHCI_PCI by default

Quoted 8 lines · Stefan Roese
Quoted 5 lines · Phil Sutter

With the recent fixes in pci_mvebu and xhci-pci drivers, the two rear USB3 ports are finally usable and accessing them no longer hangs the system.

Please hold back on this one, I noticed it needs CONFIG_XHCI_HCD as well. Will send a v2 later.

Sorry for the mess!

Phil

#6 lore raw

PATCH v2 2/5 configs: ds414: Enable XHCI_PCI by default

In reply to Phil Sutter

With the recent fixes in pci_mvebu and xhci-pci drivers, the two rear USB3 ports are finally usable and accessing them no longer hangs the system. Moreover, if Linux is booted without a prior call to 'pci enum' and 'usb start', the HCD is detected but attached devices are not usable:

| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 2
| xhci_hcd 0000:02:00.0: hcc params 0x040040a5 hci version 0x100 quirks 0x0000000000080490
| usb usb2: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
| usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb2: Product: xHCI Host Controller
| usb usb2: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb2: SerialNumber: 0000:02:00.0
| hub 2-0:1.0: USB hub found
| ata1: SATA link down (SStatus 0 SControl 300)
| hub 2-0:1.0: 2 ports detected
| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 3
| xhci_hcd 0000:02:00.0: Host supports USB 3.0 SuperSpeed
| usb usb3: We don't know the algorithms for LPM for this host, disabling LPM.
| usb usb3: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.04
| usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb3: Product: xHCI Host Controller
| usb usb3: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb3: SerialNumber: 0000:02:00.0
| hub 3-0:1.0: USB hub found
| hub 3-0:1.0: 2 ports detected
[...]
| xhci_hcd 0000:02:00.0: Error while assigning device slot ID
| xhci_hcd 0000:02:00.0: Max number of devices this xHCI host supports is 64.
| usb usb2-port2: couldn't allocate usb_device

To avoid this problem, enumerate PCI (and USB) from PREBOOT.

---
Changes since v1:
- Have to enable XHCI_HCD as well to fulfill Kconfig dependency.
- Explicitly disable XHCI_MARVELL which defaults to enabled.
- Prefix PREBOOT with 'pci enum'.
- Update commit message accordingly.

---
 configs/ds414_defconfig | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
configs/ds414_defconfig +4 -1
index 3e6dcec3edde3..24466d81dffdb 100644
@@ -22,7 +22,7 @@ CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS0,115200"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="usb start; sf probe"
+CONFIG_PREBOOT="pci enum; usb start; sf probe"
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_I2C_SUPPORT=y
@@ -65,5 +65,8 @@ CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
+CONFIG_USB_XHCI_HCD=y
+# CONFIG_USB_XHCI_MVEBU is not set
+CONFIG_USB_XHCI_PCI=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
Signature · 1 line
2.30.1
#7 lore raw

PATCH v2 2/5 configs: ds414: Enable XHCI_PCI by default

Quoted 35 lines · Phil Sutter

With the recent fixes in pci_mvebu and xhci-pci drivers, the two rear USB3 ports are finally usable and accessing them no longer hangs the system. Moreover, if Linux is booted without a prior call to 'pci enum' and 'usb start', the HCD is detected but attached devices are not usable:

| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 2
| xhci_hcd 0000:02:00.0: hcc params 0x040040a5 hci version 0x100 quirks 0x0000000000080490
| usb usb2: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
| usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb2: Product: xHCI Host Controller
| usb usb2: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb2: SerialNumber: 0000:02:00.0
| hub 2-0:1.0: USB hub found
| ata1: SATA link down (SStatus 0 SControl 300)
| hub 2-0:1.0: 2 ports detected
| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 3
| xhci_hcd 0000:02:00.0: Host supports USB 3.0 SuperSpeed
| usb usb3: We don't know the algorithms for LPM for this host, disabling LPM.
| usb usb3: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.04
| usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb3: Product: xHCI Host Controller
| usb usb3: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb3: SerialNumber: 0000:02:00.0
| hub 3-0:1.0: USB hub found
| hub 3-0:1.0: 2 ports detected
[...]
| xhci_hcd 0000:02:00.0: Error while assigning device slot ID
| xhci_hcd 0000:02:00.0: Max number of devices this xHCI host supports is 64.
| usb usb2-port2: couldn't allocate usb_device

To avoid this problem, enumerate PCI (and USB) from PREBOOT.

Quoted 7 lines

---
Changes since v1:
- Have to enable XHCI_HCD as well to fulfill Kconfig dependency.
- Explicitly disable XHCI_MARVELL which defaults to enabled.
- Prefix PREBOOT with 'pci enum'.
- Update commit message accordingly.

Hmmm, in general is should not be necessary to configure / setup any of the devices in the bootloader so that it works correctly in Linux. It's best practice, that Linux does not rely on any bootloader setup. If a device, like PCI and/or USB does not work in Linux without this U-Boot setup, then it should be fixed in Linux instead.

Especially calling "usb start" adds a quite big delay to the bootup time. I would really like to not add such changes. Perhaps you could check with the maintainer(s) of the Linux PCI driver and/or the USB PCI controller driver about this issue instead?

Thanks,
Stefan

Quoted 19 lines
---
  configs/ds414_defconfig | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
configs/ds414_defconfig +1 -1
index 3e6dcec3edde3..24466d81dffdb 100644
@@ -22,7 +22,7 @@ CONFIG_BOOTDELAY=3
  CONFIG_USE_BOOTARGS=y
  CONFIG_BOOTARGS="console=ttyS0,115200"
  CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="usb start; sf probe"
+CONFIG_PREBOOT="pci enum; usb start; sf probe"
  # CONFIG_DISPLAY_BOARDINFO is not set
  CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_SPL_I2C_SUPPORT=y

configs/ds414_defconfig CONFIG_SYS_NS16550=y · line 72

Quoted 8 lines
configs/ds414_defconfig +3 -0
@@ -65,5 +65,8 @@ CONFIG_SYS_NS16550=y
  CONFIG_KIRKWOOD_SPI=y
  CONFIG_USB=y
  CONFIG_DM_USB=y
+CONFIG_USB_XHCI_HCD=y
+# CONFIG_USB_XHCI_MVEBU is not set
+CONFIG_USB_XHCI_PCI=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_STORAGE=y

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#8 lore raw

PATCH v2 2/5 configs: ds414: Enable XHCI_PCI by default

Quoted 50 lines · Stefan Roese
Quoted 35 lines · Phil Sutter

With the recent fixes in pci_mvebu and xhci-pci drivers, the two rear USB3 ports are finally usable and accessing them no longer hangs the system. Moreover, if Linux is booted without a prior call to 'pci enum' and 'usb start', the HCD is detected but attached devices are not usable:

| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 2
| xhci_hcd 0000:02:00.0: hcc params 0x040040a5 hci version 0x100 quirks 0x0000000000080490
| usb usb2: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
| usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb2: Product: xHCI Host Controller
| usb usb2: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb2: SerialNumber: 0000:02:00.0
| hub 2-0:1.0: USB hub found
| ata1: SATA link down (SStatus 0 SControl 300)
| hub 2-0:1.0: 2 ports detected
| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 3
| xhci_hcd 0000:02:00.0: Host supports USB 3.0 SuperSpeed
| usb usb3: We don't know the algorithms for LPM for this host, disabling LPM.
| usb usb3: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.04
| usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb3: Product: xHCI Host Controller
| usb usb3: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb3: SerialNumber: 0000:02:00.0
| hub 3-0:1.0: USB hub found
| hub 3-0:1.0: 2 ports detected
[...]
| xhci_hcd 0000:02:00.0: Error while assigning device slot ID
| xhci_hcd 0000:02:00.0: Max number of devices this xHCI host supports is 64.
| usb usb2-port2: couldn't allocate usb_device

To avoid this problem, enumerate PCI (and USB) from PREBOOT.

Quoted 7 lines

---
Changes since v1:
- Have to enable XHCI_HCD as well to fulfill Kconfig dependency.
- Explicitly disable XHCI_MARVELL which defaults to enabled.
- Prefix PREBOOT with 'pci enum'.
- Update commit message accordingly.

Hmmm, in general is should not be necessary to configure / setup any of the devices in the bootloader so that it works correctly in Linux. It's best practice, that Linux does not rely on any bootloader setup. If a device, like PCI and/or USB does not work in Linux without this U-Boot setup, then it should be fixed in Linux instead.

Quoted 4 lines

Especially calling "usb start" adds a quite big delay to the bootup time. I would really like to not add such changes. Perhaps you could check with the maintainer(s) of the Linux PCI driver and/or the USB PCI controller driver about this issue instead?

Turns out I should have tried a more recent kernel first, the bug I was working around is quite certainly fixed by Linux commit 216f8e95aacc8 ("PCI: mvebu: Setup BAR0 in order to fix MSI").

I'll send a v3 without the fuss but with the Kconfig fix.

Sorry for the noise,

Phil

#9 lore raw

PATCH v2 2/5 configs: ds414: Enable XHCI_PCI by default

Quoted 51 lines · Phil Sutter
Quoted 50 lines · Stefan Roese
Quoted 35 lines · Phil Sutter

With the recent fixes in pci_mvebu and xhci-pci drivers, the two rear USB3 ports are finally usable and accessing them no longer hangs the system. Moreover, if Linux is booted without a prior call to 'pci enum' and 'usb start', the HCD is detected but attached devices are not usable:

| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 2
| xhci_hcd 0000:02:00.0: hcc params 0x040040a5 hci version 0x100 quirks 0x0000000000080490
| usb usb2: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
| usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb2: Product: xHCI Host Controller
| usb usb2: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb2: SerialNumber: 0000:02:00.0
| hub 2-0:1.0: USB hub found
| ata1: SATA link down (SStatus 0 SControl 300)
| hub 2-0:1.0: 2 ports detected
| xhci_hcd 0000:02:00.0: xHCI Host Controller
| xhci_hcd 0000:02:00.0: new USB bus registered, assigned bus number 3
| xhci_hcd 0000:02:00.0: Host supports USB 3.0 SuperSpeed
| usb usb3: We don't know the algorithms for LPM for this host, disabling LPM.
| usb usb3: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.04
| usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
| usb usb3: Product: xHCI Host Controller
| usb usb3: Manufacturer: Linux 5.4.92-1 xhci-hcd
| usb usb3: SerialNumber: 0000:02:00.0
| hub 3-0:1.0: USB hub found
| hub 3-0:1.0: 2 ports detected
[...]
| xhci_hcd 0000:02:00.0: Error while assigning device slot ID
| xhci_hcd 0000:02:00.0: Max number of devices this xHCI host supports is 64.
| usb usb2-port2: couldn't allocate usb_device

To avoid this problem, enumerate PCI (and USB) from PREBOOT.

Quoted 7 lines

---
Changes since v1:
- Have to enable XHCI_HCD as well to fulfill Kconfig dependency.
- Explicitly disable XHCI_MARVELL which defaults to enabled.
- Prefix PREBOOT with 'pci enum'.
- Update commit message accordingly.

Hmmm, in general is should not be necessary to configure / setup any of the devices in the bootloader so that it works correctly in Linux. It's best practice, that Linux does not rely on any bootloader setup. If a device, like PCI and/or USB does not work in Linux without this U-Boot setup, then it should be fixed in Linux instead.

Quoted 8 lines
Quoted 4 lines

Especially calling "usb start" adds a quite big delay to the bootup time. I would really like to not add such changes. Perhaps you could check with the maintainer(s) of the Linux PCI driver and/or the USB PCI controller driver about this issue instead?

Turns out I should have tried a more recent kernel first, the bug I was working around is quite certainly fixed by Linux commit 216f8e95aacc8 ("PCI: mvebu: Setup BAR0 in order to fix MSI").

This is actually good news. Thanks for testing and reporting.

Quoted 3 lines

I'll send a v3 without the fuss but with the Kconfig fix.

Sorry for the noise,

NP. ;)

Thanks,
Stefan

#10 lore raw

PATCH v3 2/5 configs: ds414: Enable XHCI_PCI by default

In reply to Phil Sutter

With the recent fixes in pci_mvebu and xhci-pci drivers, the two rear USB3 ports are finally usable and accessing them no longer hangs the system.

---
Changes since v2:
- Leave PREBOOT alone, with recent kernels XHCI HCD works fine even if not initialized.
- Adjust commit message again.

Changes since v1:
- Have to enable XHCI_HCD as well to fulfill Kconfig dependency.
- Explicitly disable XHCI_MARVELL which defaults to enabled.
- Prefix PREBOOT with 'pci enum'.
- Update commit message accordingly.

---
 configs/ds414_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/ds414_defconfig +3 -0
index 3e6dcec3edde3..412559256e6ca 100644
@@ -65,5 +65,8 @@ CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
+CONFIG_USB_XHCI_HCD=y
+# CONFIG_USB_XHCI_MVEBU is not set
+CONFIG_USB_XHCI_PCI=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
Signature · 1 line
2.30.1
#12 lore raw

PATCH 3/5 board/Synology: Unify legacy kernel support

In reply to Phil Sutter

Move the relevant bits from ds109.{c,h} into common/ and adjust the code to fit both DS109 and DS414. Moreover:

* Introduce syno_board_id() which translates CONFIG_MACH_TYPE into the expected board ID tag value.

* Properly initialize isusbhost, mac and mtu fields from env variables.

* Set the right bootargs/bootcmd to correctly boot legacy kernel out of the (DS414) box. Getting the ramdisk location right is a bit tedious.

Cc Walter Schweizer <[email protected]>
---
 board/Synology/common/Makefile |  5 +++
 board/Synology/common/legacy.c | 75 ++++++++++++++++++++++++++++++++++
 board/Synology/common/legacy.h | 33 +++++++++++++++
 board/Synology/ds109/ds109.c   | 32 ---------------
 board/Synology/ds109/ds109.h   | 17 --------
 configs/ds414_defconfig        |  2 +-
 include/configs/ds109.h        |  3 +-
 include/configs/ds414.h        | 15 ++++++-
 8 files changed, 130 insertions(+), 52 deletions(-)
 create mode 100644 board/Synology/common/Makefile
 create mode 100644 board/Synology/common/legacy.c
 create mode 100644 board/Synology/common/legacy.h
board/Synology/common/Makefile new file +5 -0
new file mode 100644
index 0000000000000..62354cc2e82e6
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2021 Phil Sutter <[email protected]>
+
+obj-y	+= legacy.o
board/Synology/common/legacy.c new file +75 -0

75 lines not on this page · raw message

board/Synology/common/legacy.h new file +33 -0
new file mode 100644
index 0000000000000..595e57f09eae0
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#ifndef __SYNO_LEGACY_H
+#define __SYNO_LEGACY_H
+
+/* Marvell uboot parameters */
+#define ATAG_MV_UBOOT 0x41000403
+#define VER_NUM       0x03040400 /* 3.4.4 */
+
+#define BOARD_ID_BASE 0x0
+#define SYNO_DS109_ID (BOARD_ID_BASE+0x15)
+#define SYNO_AXP_4BAY_2BAY (0xf + 1)
+
+#define ETHADDR_MAX	4
+#define USBPORT_MAX	3
+
+struct tag_mv_uboot {
+	u32 uboot_version;
+	u32 tclk;
+	u32 sysclk;
+	u32 isusbhost;
+	u8 macaddr[ETHADDR_MAX][ETH_ALEN];
+	u16 mtu[ETHADDR_MAX];
+	u32 fw_image_base;
+	u32 fw_image_size;
+};
+
+#endif /* __SYNO_LEGACY_H */
board/Synology/ds109/ds109.c +0 -32
index eaac95460c6e1..3914faaf37bb4 100644
@@ -114,38 +114,6 @@ void reset_misc(void)
 		     SOFTWARE_REBOOT);
 }
 
-/* Support old kernels */
-void setup_board_tags(struct tag **in_params)
-{
-	unsigned int boardId;
-	struct tag *params;
-	struct tag_mv_uboot *t;
-	int i;
-
-	printf("Synology board tags...");
-	params = *in_params;
-	t = (struct tag_mv_uboot *)&params->u;
-
-	t->uboot_version = VER_NUM;
-
-	boardId = SYNO_DS109_ID;
-	t->uboot_version |= boardId;
-
-	t->tclk = CONFIG_SYS_TCLK;
-	t->sysclk = CONFIG_SYS_TCLK*2;
-
-	t->isusbhost = 1;
-	for (i = 0; i < 4; i++)	{
-		memset(t->macaddr[i], 0, sizeof(t->macaddr[i]));
-		t->mtu[i] = 0;
-	}
-
-	params->hdr.tag = ATAG_MV_UBOOT;
-	params->hdr.size = tag_size(tag_mv_uboot);
-	params = tag_next(params);
-	*in_params = params;
-}
-
 #ifdef CONFIG_RESET_PHY_R
 /* Configure and enable MV88E1116 PHY */
 void reset_phy(void)
board/Synology/ds109/ds109.h +0 -17
index cc6ef991f3973..0cf05257c8d35 100644
@@ -23,21 +23,4 @@
 #define MV88E1116_RGMII_TXTM_CTRL	(1 << 4)
 #define MV88E1116_RGMII_RXTM_CTRL	(1 << 5)
 
-/* Marvell uboot parameters */
-#define ATAG_MV_UBOOT 0x41000403
-#define VER_NUM       0x03040400 /* 3.4.4 */
-#define BOARD_ID_BASE 0x0
-#define SYNO_DS109_ID (BOARD_ID_BASE+0x15)
-
-struct tag_mv_uboot {
-	u32 uboot_version;
-	u32 tclk;
-	u32 sysclk;
-	u32 isusbhost;
-	char macaddr[4][6];
-	u16 mtu[4];
-	u32 fw_image_base;
-	u32 fw_image_size;
-};
-
 #endif /* __DS109_H */
configs/ds414_defconfig +1 -1
index 254e42f84d2e9..fa9366778748c 100644
@@ -20,7 +20,7 @@ CONFIG_DEFAULT_DEVICE_TREE="armada-xp-synology-ds414"
 CONFIG_DEBUG_UART=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="console=ttyS0,115200"
+CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 rw syno_hw_version=DS414r1 ihd_num=4 netif_num=2 flash_size=8 SataLedSpecial=1 HddHotplug=1"
 CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="usb start; sf probe"
 # CONFIG_DISPLAY_BOARDINFO is not set
include/configs/ds109.h +2 -1
index 1f033ababf6ee..35d85361b4542 100644
@@ -44,7 +44,8 @@
 	"x_bootcmd_kernel=fatload usb 0 0x6400000 uImage\0" \
 	"x_bootargs=console=ttyS0,115200\0"	\
 	"x_bootargs_root=root=/dev/sda2 rootdelay=10\0" \
-	"ipaddr=192.168.1.5\0"
+	"ipaddr=192.168.1.5\0"		\
+	"usb0Mode=host\0"
 
 /*
  * Ethernet Driver configuration
include/configs/ds414.h +14 -1
index 8aa2d47bec68d..a2248cf75ad72 100644
@@ -6,6 +6,9 @@
 #ifndef _CONFIG_SYNOLOGY_DS414_H
 #define _CONFIG_SYNOLOGY_DS414_H
 
+/* Vendor kernel expects this MACH_TYPE */
+#define CONFIG_MACH_TYPE	3036
+
 /*
  * High Level Configuration Options (easy to change)
  */
@@ -74,8 +77,18 @@
 #define CONFIG_DDR_32BIT
 
 /* Default Environment */
-#define CONFIG_BOOTCOMMAND	"sf read ${loadaddr} 0xd0000 0x700000; bootm"
 #define CONFIG_LOADADDR		0x80000
+#define CONFIG_BOOTCOMMAND					\
+	"sf probe; "						\
+	"sf read ${loadaddr} 0xd0000 0x2d0000; "		\
+	"sf read ${ramdisk_addr_r} 0x3a0000 0x430000; "		\
+	"bootm ${loadaddr} ${ramdisk_addr_r}"
+
+#define CONFIG_EXTRA_ENV_SETTINGS				\
+	"initrd_high=0xffffffff\0"				\
+	"ramdisk_addr_r=0x8000000\0"				\
+	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
+	"ethmtu=1500\0eth1mtu=1500\0"
 
 /* increase autoneg timeout, my NIC sucks */
 #define PHY_ANEG_TIMEOUT	16000
Signature · 1 line
2.30.1
#13 lore raw

PATCH 3/5 board/Synology: Unify legacy kernel support

Quoted 44 lines · Phil Sutter

Move the relevant bits from ds109.{c,h} into common/ and adjust the code to fit both DS109 and DS414. Moreover:

* Introduce syno_board_id() which translates CONFIG_MACH_TYPE into the expected board ID tag value.

* Properly initialize isusbhost, mac and mtu fields from env variables.

* Set the right bootargs/bootcmd to correctly boot legacy kernel out of the (DS414) box. Getting the ramdisk location right is a bit tedious.

Cc Walter Schweizer <[email protected]>
---
  board/Synology/common/Makefile |  5 +++
  board/Synology/common/legacy.c | 75 ++++++++++++++++++++++++++++++++++
  board/Synology/common/legacy.h | 33 +++++++++++++++
  board/Synology/ds109/ds109.c   | 32 ---------------
  board/Synology/ds109/ds109.h   | 17 --------
  configs/ds414_defconfig        |  2 +-
  include/configs/ds109.h        |  3 +-
  include/configs/ds414.h        | 15 ++++++-
  8 files changed, 130 insertions(+), 52 deletions(-)

create mode 100644 board/Synology/common/Makefile create mode 100644 board/Synology/common/legacy.c create mode 100644 board/Synology/common/legacy.h

board/Synology/common/Makefile new file +5 -0
new file mode 100644
index 0000000000000..62354cc2e82e6
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2021 Phil Sutter <[email protected]>
+
+obj-y	+= legacy.o
board/Synology/common/legacy.c new file +0 -0
new file mode 100644
index 0000000000000..678e7b6809168

board/Synology/common/legacy.c line 8

Quoted 8 lines
board/Synology/common/legacy.c new file +8 -0
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#include <common.h>

Please don't include "common.h" any more. There is ongoing work to depricate this common header.

Other than this:

Thanks,
Stefan

Quoted 227 lines
board/Synology/common/legacy.c new file +67 -0
+#include <env.h>
+#include <net.h>
+#include <asm/setup.h>
+
+#include "legacy.h"
+
+static unsigned int syno_board_id(void)
+{
+	switch (CONFIG_MACH_TYPE) {
+	case 527:
+		return SYNO_DS109_ID;
+	case 3036:
+		return SYNO_AXP_4BAY_2BAY;
+	default:
+		return 0;
+	}
+}
+
+static unsigned int usb_port_modes(void)
+{
+	unsigned int i, ret = 0;
+	char var[32], *val;
+
+	for (i = 0; i < USBPORT_MAX; i++) {
+		snprintf(var, 32, "usb%dMode", i);
+		val = env_get(var);
+
+		if (!val || strcasecmp(val, "host"))
+			continue;
+
+		ret |= 1 << i;
+	}
+	return ret;
+}
+
+/* Support old kernels */
+void setup_board_tags(struct tag **in_params)
+{
+	struct tag_mv_uboot *t;
+	struct tag *params;
+	int i;
+
+	debug("Synology board tags...\n");
+
+	params = *in_params;
+	t = (struct tag_mv_uboot *)&params->u;
+
+	t->uboot_version = VER_NUM | syno_board_id();
+	t->tclk = CONFIG_SYS_TCLK;
+	t->sysclk = CONFIG_SYS_TCLK * 2;
+	t->isusbhost = usb_port_modes();
+
+	for (i = 0; i < ETHADDR_MAX; i++) {
+		char addrvar[16], mtuvar[16];
+
+		sprintf(addrvar, i ? "eth%daddr" : "ethaddr", i);
+		sprintf(mtuvar, i ? "eth%dmtu" : "ethmtu", i);
+
+		eth_env_get_enetaddr(addrvar, t->macaddr[i]);
+		t->mtu[i] = env_get_ulong(mtuvar, 10, 0);
+	}
+
+	params->hdr.tag = ATAG_MV_UBOOT;
+	params->hdr.size = tag_size(tag_mv_uboot);
+	params = tag_next(params);
+	*in_params = params;
+}
board/Synology/common/legacy.h new file +33 -0
new file mode 100644
index 0000000000000..595e57f09eae0
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#ifndef __SYNO_LEGACY_H
+#define __SYNO_LEGACY_H
+
+/* Marvell uboot parameters */
+#define ATAG_MV_UBOOT 0x41000403
+#define VER_NUM       0x03040400 /* 3.4.4 */
+
+#define BOARD_ID_BASE 0x0
+#define SYNO_DS109_ID (BOARD_ID_BASE+0x15)
+#define SYNO_AXP_4BAY_2BAY (0xf + 1)
+
+#define ETHADDR_MAX	4
+#define USBPORT_MAX	3
+
+struct tag_mv_uboot {
+	u32 uboot_version;
+	u32 tclk;
+	u32 sysclk;
+	u32 isusbhost;
+	u8 macaddr[ETHADDR_MAX][ETH_ALEN];
+	u16 mtu[ETHADDR_MAX];
+	u32 fw_image_base;
+	u32 fw_image_size;
+};
+
+#endif /* __SYNO_LEGACY_H */
board/Synology/ds109/ds109.c +0 -32
index eaac95460c6e1..3914faaf37bb4 100644
@@ -114,38 +114,6 @@ void reset_misc(void)
  		     SOFTWARE_REBOOT);
  }
 
-/* Support old kernels */
-void setup_board_tags(struct tag **in_params)
-{
-	unsigned int boardId;
-	struct tag *params;
-	struct tag_mv_uboot *t;
-	int i;
-
-	printf("Synology board tags...");
-	params = *in_params;
-	t = (struct tag_mv_uboot *)&params->u;
-
-	t->uboot_version = VER_NUM;
-
-	boardId = SYNO_DS109_ID;
-	t->uboot_version |= boardId;
-
-	t->tclk = CONFIG_SYS_TCLK;
-	t->sysclk = CONFIG_SYS_TCLK*2;
-
-	t->isusbhost = 1;
-	for (i = 0; i < 4; i++)	{
-		memset(t->macaddr[i], 0, sizeof(t->macaddr[i]));
-		t->mtu[i] = 0;
-	}
-
-	params->hdr.tag = ATAG_MV_UBOOT;
-	params->hdr.size = tag_size(tag_mv_uboot);
-	params = tag_next(params);
-	*in_params = params;
-}
-
  #ifdef CONFIG_RESET_PHY_R
  /* Configure and enable MV88E1116 PHY */
  void reset_phy(void)
board/Synology/ds109/ds109.h +0 -17
index cc6ef991f3973..0cf05257c8d35 100644
@@ -23,21 +23,4 @@
  #define MV88E1116_RGMII_TXTM_CTRL	(1 << 4)
  #define MV88E1116_RGMII_RXTM_CTRL	(1 << 5)
 
-/* Marvell uboot parameters */
-#define ATAG_MV_UBOOT 0x41000403
-#define VER_NUM       0x03040400 /* 3.4.4 */
-#define BOARD_ID_BASE 0x0
-#define SYNO_DS109_ID (BOARD_ID_BASE+0x15)
-
-struct tag_mv_uboot {
-	u32 uboot_version;
-	u32 tclk;
-	u32 sysclk;
-	u32 isusbhost;
-	char macaddr[4][6];
-	u16 mtu[4];
-	u32 fw_image_base;
-	u32 fw_image_size;
-};
-
  #endif /* __DS109_H */
configs/ds414_defconfig +1 -1
index 254e42f84d2e9..fa9366778748c 100644
@@ -20,7 +20,7 @@ CONFIG_DEFAULT_DEVICE_TREE="armada-xp-synology-ds414"
  CONFIG_DEBUG_UART=y
  CONFIG_BOOTDELAY=3
  CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="console=ttyS0,115200"
+CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 rw syno_hw_version=DS414r1 ihd_num=4 netif_num=2 flash_size=8 SataLedSpecial=1 HddHotplug=1"
  CONFIG_USE_PREBOOT=y
  CONFIG_PREBOOT="usb start; sf probe"
  # CONFIG_DISPLAY_BOARDINFO is not set
include/configs/ds109.h +2 -1
index 1f033ababf6ee..35d85361b4542 100644
@@ -44,7 +44,8 @@
  	"x_bootcmd_kernel=fatload usb 0 0x6400000 uImage\0" \
  	"x_bootargs=console=ttyS0,115200\0"	\
  	"x_bootargs_root=root=/dev/sda2 rootdelay=10\0" \
-	"ipaddr=192.168.1.5\0"
+	"ipaddr=192.168.1.5\0"		\
+	"usb0Mode=host\0"
 
  /*
   * Ethernet Driver configuration
include/configs/ds414.h +7 -1
index 8aa2d47bec68d..a2248cf75ad72 100644
@@ -6,6 +6,9 @@
  #ifndef _CONFIG_SYNOLOGY_DS414_H
  #define _CONFIG_SYNOLOGY_DS414_H
 
+/* Vendor kernel expects this MACH_TYPE */
+#define CONFIG_MACH_TYPE	3036
+
  /*
   * High Level Configuration Options (easy to change)
   */
@@ -74,8 +77,18 @@
  #define CONFIG_DDR_32BIT
 
  /* Default Environment */
-#define CONFIG_BOOTCOMMAND	"sf read ${loadaddr} 0xd0000 0x700000; bootm"
  #define CONFIG_LOADADDR		0x80000
+#define CONFIG_BOOTCOMMAND					\
+	"sf probe; "						\
+	"sf read ${loadaddr} 0xd0000 0x2d0000; "		\
+	"sf read ${ramdisk_addr_r} 0x3a0000 0x430000; "		\

include/configs/ds414.h line 94

Quoted 10 lines
include/configs/ds414.h +7 -0
+	"bootm ${loadaddr} ${ramdisk_addr_r}"
+
+#define CONFIG_EXTRA_ENV_SETTINGS				\
+	"initrd_high=0xffffffff\0"				\
+	"ramdisk_addr_r=0x8000000\0"				\
+	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
+	"ethmtu=1500\0eth1mtu=1500\0"
 
  /* increase autoneg timeout, my NIC sucks */
  #define PHY_ANEG_TIMEOUT	16000

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#14 lore raw

PATCH 3/5 board/Synology: Unify legacy kernel support

Quoted 48 lines · Stefan Roese
Quoted 47 lines · Phil Sutter

Move the relevant bits from ds109.{c,h} into common/ and adjust the code to fit both DS109 and DS414. Moreover:

* Introduce syno_board_id() which translates CONFIG_MACH_TYPE into the expected board ID tag value.

* Properly initialize isusbhost, mac and mtu fields from env variables.

* Set the right bootargs/bootcmd to correctly boot legacy kernel out of the (DS414) box. Getting the ramdisk location right is a bit tedious.

Cc Walter Schweizer <[email protected]>
---
  board/Synology/common/Makefile |  5 +++
  board/Synology/common/legacy.c | 75 ++++++++++++++++++++++++++++++++++
  board/Synology/common/legacy.h | 33 +++++++++++++++
  board/Synology/ds109/ds109.c   | 32 ---------------
  board/Synology/ds109/ds109.h   | 17 --------
  configs/ds414_defconfig        |  2 +-
  include/configs/ds109.h        |  3 +-
  include/configs/ds414.h        | 15 ++++++-
  8 files changed, 130 insertions(+), 52 deletions(-)

create mode 100644 board/Synology/common/Makefile create mode 100644 board/Synology/common/legacy.c create mode 100644 board/Synology/common/legacy.h

board/Synology/common/Makefile new file +5 -0
new file mode 100644
index 0000000000000..62354cc2e82e6
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2021 Phil Sutter <[email protected]>
+
+obj-y	+= legacy.o
board/Synology/common/legacy.c new file +3 -0
new file mode 100644
index 0000000000000..678e7b6809168
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021
Quoted 8 lines

board/Synology/common/legacy.c line 8

Quoted 5 lines
board/Synology/common/legacy.c new file +5 -0
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#include <common.h>

Please don't include "common.h" any more. There is ongoing work to depricate this common header.

OK, I'll respin. Thanks for the heads-up!

Phil

#15 lore raw

PATCH v2 3/5 board/Synology: Unify legacy kernel support

In reply to Phil Sutter

Move the relevant bits from ds109.{c,h} into common/ and adjust the code to fit both DS109 and DS414. Moreover:

* Introduce syno_board_id() which translates CONFIG_MACH_TYPE into the expected board ID tag value.

* Properly initialize isusbhost, mac and mtu fields from env variables.

* Set the right bootargs/bootcmd to correctly boot legacy kernel out of the (DS414) box. Getting the ramdisk location right is a bit tedious.

Cc Walter Schweizer <[email protected]>

--
Changes since v1:
- Avoid deprecated common.h header include.
- Remove 'sf probe' call from DS414 PREBOOT, bootcmd contains it now.
- Use proper comment-style for SPDX tag in introduced legacy.h.

---
 board/Synology/common/Makefile |  5 +++
 board/Synology/common/legacy.c | 76 ++++++++++++++++++++++++++++++++++
 board/Synology/common/legacy.h | 33 +++++++++++++++
 board/Synology/ds109/ds109.c   | 32 --------------
 board/Synology/ds109/ds109.h   | 17 --------
 configs/ds414_defconfig        |  4 +-
 include/configs/ds109.h        |  3 +-
 include/configs/ds414.h        | 15 ++++++-
 8 files changed, 132 insertions(+), 53 deletions(-)
 create mode 100644 board/Synology/common/Makefile
 create mode 100644 board/Synology/common/legacy.c
 create mode 100644 board/Synology/common/legacy.h
board/Synology/common/Makefile new file +5 -0
new file mode 100644
index 0000000000000..62354cc2e82e6
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2021 Phil Sutter <[email protected]>
+
+obj-y	+= legacy.o
board/Synology/common/legacy.c new file +76 -0

76 lines not on this page · raw message

board/Synology/common/legacy.h new file +33 -0
new file mode 100644
index 0000000000000..0a814324d0977
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2021
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#ifndef __SYNO_LEGACY_H
+#define __SYNO_LEGACY_H
+
+/* Marvell uboot parameters */
+#define ATAG_MV_UBOOT 0x41000403
+#define VER_NUM       0x03040400 /* 3.4.4 */
+
+#define BOARD_ID_BASE 0x0
+#define SYNO_DS109_ID (BOARD_ID_BASE + 0x15)
+#define SYNO_AXP_4BAY_2BAY (0xf + 1)
+
+#define ETHADDR_MAX	4
+#define USBPORT_MAX	3
+
+struct tag_mv_uboot {
+	u32 uboot_version;
+	u32 tclk;
+	u32 sysclk;
+	u32 isusbhost;
+	u8 macaddr[ETHADDR_MAX][ETH_ALEN];
+	u16 mtu[ETHADDR_MAX];
+	u32 fw_image_base;
+	u32 fw_image_size;
+};
+
+#endif /* __SYNO_LEGACY_H */
board/Synology/ds109/ds109.c +0 -32
index eaac95460c6e1..3914faaf37bb4 100644
@@ -114,38 +114,6 @@ void reset_misc(void)
 		     SOFTWARE_REBOOT);
 }
 
-/* Support old kernels */
-void setup_board_tags(struct tag **in_params)
-{
-	unsigned int boardId;
-	struct tag *params;
-	struct tag_mv_uboot *t;
-	int i;
-
-	printf("Synology board tags...");
-	params = *in_params;
-	t = (struct tag_mv_uboot *)&params->u;
-
-	t->uboot_version = VER_NUM;
-
-	boardId = SYNO_DS109_ID;
-	t->uboot_version |= boardId;
-
-	t->tclk = CONFIG_SYS_TCLK;
-	t->sysclk = CONFIG_SYS_TCLK*2;
-
-	t->isusbhost = 1;
-	for (i = 0; i < 4; i++)	{
-		memset(t->macaddr[i], 0, sizeof(t->macaddr[i]));
-		t->mtu[i] = 0;
-	}
-
-	params->hdr.tag = ATAG_MV_UBOOT;
-	params->hdr.size = tag_size(tag_mv_uboot);
-	params = tag_next(params);
-	*in_params = params;
-}
-
 #ifdef CONFIG_RESET_PHY_R
 /* Configure and enable MV88E1116 PHY */
 void reset_phy(void)
board/Synology/ds109/ds109.h +0 -17
index cc6ef991f3973..0cf05257c8d35 100644
@@ -23,21 +23,4 @@
 #define MV88E1116_RGMII_TXTM_CTRL	(1 << 4)
 #define MV88E1116_RGMII_RXTM_CTRL	(1 << 5)
 
-/* Marvell uboot parameters */
-#define ATAG_MV_UBOOT 0x41000403
-#define VER_NUM       0x03040400 /* 3.4.4 */
-#define BOARD_ID_BASE 0x0
-#define SYNO_DS109_ID (BOARD_ID_BASE+0x15)
-
-struct tag_mv_uboot {
-	u32 uboot_version;
-	u32 tclk;
-	u32 sysclk;
-	u32 isusbhost;
-	char macaddr[4][6];
-	u16 mtu[4];
-	u32 fw_image_base;
-	u32 fw_image_size;
-};
-
 #endif /* __DS109_H */
configs/ds414_defconfig +2 -2
index 24466d81dffdb..4fb0abee81c58 100644
@@ -20,9 +20,9 @@ CONFIG_DEFAULT_DEVICE_TREE="armada-xp-synology-ds414"
 CONFIG_DEBUG_UART=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="console=ttyS0,115200"
+CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 rw syno_hw_version=DS414r1 ihd_num=4 netif_num=2 flash_size=8 SataLedSpecial=1 HddHotplug=1"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="pci enum; usb start; sf probe"
+CONFIG_PREBOOT="pci enum; usb start"
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_I2C_SUPPORT=y
include/configs/ds109.h +2 -1
index 1f033ababf6ee..35d85361b4542 100644
@@ -44,7 +44,8 @@
 	"x_bootcmd_kernel=fatload usb 0 0x6400000 uImage\0" \
 	"x_bootargs=console=ttyS0,115200\0"	\
 	"x_bootargs_root=root=/dev/sda2 rootdelay=10\0" \
-	"ipaddr=192.168.1.5\0"
+	"ipaddr=192.168.1.5\0"		\
+	"usb0Mode=host\0"
 
 /*
  * Ethernet Driver configuration
include/configs/ds414.h +14 -1
index 8aa2d47bec68d..a2248cf75ad72 100644
@@ -6,6 +6,9 @@
 #ifndef _CONFIG_SYNOLOGY_DS414_H
 #define _CONFIG_SYNOLOGY_DS414_H
 
+/* Vendor kernel expects this MACH_TYPE */
+#define CONFIG_MACH_TYPE	3036
+
 /*
  * High Level Configuration Options (easy to change)
  */
@@ -74,8 +77,18 @@
 #define CONFIG_DDR_32BIT
 
 /* Default Environment */
-#define CONFIG_BOOTCOMMAND	"sf read ${loadaddr} 0xd0000 0x700000; bootm"
 #define CONFIG_LOADADDR		0x80000
+#define CONFIG_BOOTCOMMAND					\
+	"sf probe; "						\
+	"sf read ${loadaddr} 0xd0000 0x2d0000; "		\
+	"sf read ${ramdisk_addr_r} 0x3a0000 0x430000; "		\
+	"bootm ${loadaddr} ${ramdisk_addr_r}"
+
+#define CONFIG_EXTRA_ENV_SETTINGS				\
+	"initrd_high=0xffffffff\0"				\
+	"ramdisk_addr_r=0x8000000\0"				\
+	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
+	"ethmtu=1500\0eth1mtu=1500\0"
 
 /* increase autoneg timeout, my NIC sucks */
 #define PHY_ANEG_TIMEOUT	16000
Signature · 1 line
2.30.1
#16 lore raw

PATCH v3 3/5 board/Synology: Unify legacy kernel support

Move the relevant bits from ds109.{c,h} into common/ and adjust the code to fit both DS109 and DS414. Moreover:

* Introduce syno_board_id() which translates CONFIG_MACH_TYPE into the expected board ID tag value.

* Properly initialize isusbhost, mac and mtu fields from env variables.

* Set the right bootargs/bootcmd to correctly boot legacy kernel out of the (DS414) box. Getting the ramdisk location right is a bit tedious.

Cc Walter Schweizer <[email protected]>

--
Changes since v2:
- Drop PREBOOT entirely, 'usb init' is not needed.

Changes since v1:
- Avoid deprecated common.h header include.
- Remove 'sf probe' call from DS414 PREBOOT, bootcmd contains it now.

---
 board/Synology/common/Makefile |  5 +++
 board/Synology/common/legacy.c | 76 ++++++++++++++++++++++++++++++++++
 board/Synology/common/legacy.h | 33 +++++++++++++++
 board/Synology/ds109/ds109.c   | 32 --------------
 board/Synology/ds109/ds109.h   | 17 --------
 configs/ds414_defconfig        |  5 +--
 include/configs/ds109.h        |  3 +-
 include/configs/ds414.h        | 15 ++++++-
 8 files changed, 132 insertions(+), 54 deletions(-)
 create mode 100644 board/Synology/common/Makefile
 create mode 100644 board/Synology/common/legacy.c
 create mode 100644 board/Synology/common/legacy.h
board/Synology/common/Makefile new file +5 -0
new file mode 100644
index 0000000000000..62354cc2e82e6
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2021 Phil Sutter <[email protected]>
+
+obj-y	+= legacy.o
board/Synology/common/legacy.c new file +76 -0

76 lines not on this page · raw message

board/Synology/common/legacy.h new file +33 -0
new file mode 100644
index 0000000000000..0a814324d0977
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2021
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#ifndef __SYNO_LEGACY_H
+#define __SYNO_LEGACY_H
+
+/* Marvell uboot parameters */
+#define ATAG_MV_UBOOT 0x41000403
+#define VER_NUM       0x03040400 /* 3.4.4 */
+
+#define BOARD_ID_BASE 0x0
+#define SYNO_DS109_ID (BOARD_ID_BASE + 0x15)
+#define SYNO_AXP_4BAY_2BAY (0xf + 1)
+
+#define ETHADDR_MAX	4
+#define USBPORT_MAX	3
+
+struct tag_mv_uboot {
+	u32 uboot_version;
+	u32 tclk;
+	u32 sysclk;
+	u32 isusbhost;
+	u8 macaddr[ETHADDR_MAX][ETH_ALEN];
+	u16 mtu[ETHADDR_MAX];
+	u32 fw_image_base;
+	u32 fw_image_size;
+};
+
+#endif /* __SYNO_LEGACY_H */
board/Synology/ds109/ds109.c +0 -32
index eaac95460c6e1..3914faaf37bb4 100644
@@ -114,38 +114,6 @@ void reset_misc(void)
 		     SOFTWARE_REBOOT);
 }
 
-/* Support old kernels */
-void setup_board_tags(struct tag **in_params)
-{
-	unsigned int boardId;
-	struct tag *params;
-	struct tag_mv_uboot *t;
-	int i;
-
-	printf("Synology board tags...");
-	params = *in_params;
-	t = (struct tag_mv_uboot *)&params->u;
-
-	t->uboot_version = VER_NUM;
-
-	boardId = SYNO_DS109_ID;
-	t->uboot_version |= boardId;
-
-	t->tclk = CONFIG_SYS_TCLK;
-	t->sysclk = CONFIG_SYS_TCLK*2;
-
-	t->isusbhost = 1;
-	for (i = 0; i < 4; i++)	{
-		memset(t->macaddr[i], 0, sizeof(t->macaddr[i]));
-		t->mtu[i] = 0;
-	}
-
-	params->hdr.tag = ATAG_MV_UBOOT;
-	params->hdr.size = tag_size(tag_mv_uboot);
-	params = tag_next(params);
-	*in_params = params;
-}
-
 #ifdef CONFIG_RESET_PHY_R
 /* Configure and enable MV88E1116 PHY */
 void reset_phy(void)
board/Synology/ds109/ds109.h +0 -17
index cc6ef991f3973..0cf05257c8d35 100644
@@ -23,21 +23,4 @@
 #define MV88E1116_RGMII_TXTM_CTRL	(1 << 4)
 #define MV88E1116_RGMII_RXTM_CTRL	(1 << 5)
 
-/* Marvell uboot parameters */
-#define ATAG_MV_UBOOT 0x41000403
-#define VER_NUM       0x03040400 /* 3.4.4 */
-#define BOARD_ID_BASE 0x0
-#define SYNO_DS109_ID (BOARD_ID_BASE+0x15)
-
-struct tag_mv_uboot {
-	u32 uboot_version;
-	u32 tclk;
-	u32 sysclk;
-	u32 isusbhost;
-	char macaddr[4][6];
-	u16 mtu[4];
-	u32 fw_image_base;
-	u32 fw_image_size;
-};
-
 #endif /* __DS109_H */
configs/ds414_defconfig +2 -3
index 412559256e6ca..8ef2e79dc91b0 100644
@@ -20,9 +20,8 @@ CONFIG_DEFAULT_DEVICE_TREE="armada-xp-synology-ds414"
 CONFIG_DEBUG_UART=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="console=ttyS0,115200"
-CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="usb start; sf probe"
+CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 rw syno_hw_version=DS414r1 ihd_num=4 netif_num=2 flash_size=8 SataLedSpecial=1 HddHotplug=1"
+# CONFIG_USE_PREBOOT is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_I2C_SUPPORT=y
include/configs/ds109.h +2 -1
index 1f033ababf6ee..35d85361b4542 100644
@@ -44,7 +44,8 @@
 	"x_bootcmd_kernel=fatload usb 0 0x6400000 uImage\0" \
 	"x_bootargs=console=ttyS0,115200\0"	\
 	"x_bootargs_root=root=/dev/sda2 rootdelay=10\0" \
-	"ipaddr=192.168.1.5\0"
+	"ipaddr=192.168.1.5\0"		\
+	"usb0Mode=host\0"
 
 /*
  * Ethernet Driver configuration
include/configs/ds414.h +14 -1
index 8aa2d47bec68d..a2248cf75ad72 100644
@@ -6,6 +6,9 @@
 #ifndef _CONFIG_SYNOLOGY_DS414_H
 #define _CONFIG_SYNOLOGY_DS414_H
 
+/* Vendor kernel expects this MACH_TYPE */
+#define CONFIG_MACH_TYPE	3036
+
 /*
  * High Level Configuration Options (easy to change)
  */
@@ -74,8 +77,18 @@
 #define CONFIG_DDR_32BIT
 
 /* Default Environment */
-#define CONFIG_BOOTCOMMAND	"sf read ${loadaddr} 0xd0000 0x700000; bootm"
 #define CONFIG_LOADADDR		0x80000
+#define CONFIG_BOOTCOMMAND					\
+	"sf probe; "						\
+	"sf read ${loadaddr} 0xd0000 0x2d0000; "		\
+	"sf read ${ramdisk_addr_r} 0x3a0000 0x430000; "		\
+	"bootm ${loadaddr} ${ramdisk_addr_r}"
+
+#define CONFIG_EXTRA_ENV_SETTINGS				\
+	"initrd_high=0xffffffff\0"				\
+	"ramdisk_addr_r=0x8000000\0"				\
+	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
+	"ethmtu=1500\0eth1mtu=1500\0"
 
 /* increase autoneg timeout, my NIC sucks */
 #define PHY_ANEG_TIMEOUT	16000
Signature · 1 line
2.30.1
#17 lore raw

PATCH v3 3/5 board/Synology: Unify legacy kernel support

Quoted 6 lines · Phil Sutter

Move the relevant bits from ds109.{c,h} into common/ and adjust the code to fit both DS109 and DS414. Moreover:

* Introduce syno_board_id() which translates CONFIG_MACH_TYPE into the expected board ID tag value.

Quoted 7 lines

* Properly initialize isusbhost, mac and mtu fields from env variables.

* Set the right bootargs/bootcmd to correctly boot legacy kernel out of the (DS414) box. Getting the ramdisk location right is a bit tedious.

Cc Walter Schweizer <[email protected]>

Thanks,
Stefan

Quoted 277 lines

--
Changes since v2:
- Drop PREBOOT entirely, 'usb init' is not needed.

Changes since v1:
- Avoid deprecated common.h header include.
- Remove 'sf probe' call from DS414 PREBOOT, bootcmd contains it now.

---
  board/Synology/common/Makefile |  5 +++
  board/Synology/common/legacy.c | 76 ++++++++++++++++++++++++++++++++++
  board/Synology/common/legacy.h | 33 +++++++++++++++
  board/Synology/ds109/ds109.c   | 32 --------------
  board/Synology/ds109/ds109.h   | 17 --------
  configs/ds414_defconfig        |  5 +--
  include/configs/ds109.h        |  3 +-
  include/configs/ds414.h        | 15 ++++++-
  8 files changed, 132 insertions(+), 54 deletions(-)

create mode 100644 board/Synology/common/Makefile create mode 100644 board/Synology/common/legacy.c create mode 100644 board/Synology/common/legacy.h

board/Synology/common/Makefile new file +5 -0
new file mode 100644
index 0000000000000..62354cc2e82e6
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2021 Phil Sutter <[email protected]>
+
+obj-y	+= legacy.o
board/Synology/common/legacy.c new file +76 -0
new file mode 100644
index 0000000000000..3c89e92ae7382
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#include <config.h>
+#include <vsprintf.h>
+#include <env.h>
+#include <net.h>
+#include <asm/setup.h>
+
+#include "legacy.h"
+
+static unsigned int syno_board_id(void)
+{
+	switch (CONFIG_MACH_TYPE) {
+	case 527:
+		return SYNO_DS109_ID;
+	case 3036:
+		return SYNO_AXP_4BAY_2BAY;
+	default:
+		return 0;
+	}
+}
+
+static unsigned int usb_port_modes(void)
+{
+	unsigned int i, ret = 0;
+	char var[32], *val;
+
+	for (i = 0; i < USBPORT_MAX; i++) {
+		snprintf(var, 32, "usb%dMode", i);
+		val = env_get(var);
+
+		if (!val || strcasecmp(val, "host"))
+			continue;
+
+		ret |= 1 << i;
+	}
+	return ret;
+}
+
+/* Support old kernels */
+void setup_board_tags(struct tag **in_params)
+{
+	struct tag_mv_uboot *t;
+	struct tag *params;
+	int i;
+
+	debug("Synology board tags...\n");
+
+	params = *in_params;
+	t = (struct tag_mv_uboot *)&params->u;
+
+	t->uboot_version = VER_NUM | syno_board_id();
+	t->tclk = CONFIG_SYS_TCLK;
+	t->sysclk = CONFIG_SYS_TCLK * 2;
+	t->isusbhost = usb_port_modes();
+
+	for (i = 0; i < ETHADDR_MAX; i++) {
+		char addrvar[16], mtuvar[16];
+
+		sprintf(addrvar, i ? "eth%daddr" : "ethaddr", i);
+		sprintf(mtuvar, i ? "eth%dmtu" : "ethmtu", i);
+
+		eth_env_get_enetaddr(addrvar, t->macaddr[i]);
+		t->mtu[i] = env_get_ulong(mtuvar, 10, 0);
+	}
+
+	params->hdr.tag = ATAG_MV_UBOOT;
+	params->hdr.size = tag_size(tag_mv_uboot);
+	params = tag_next(params);
+	*in_params = params;
+}
board/Synology/common/legacy.h new file +33 -0
new file mode 100644
index 0000000000000..0a814324d0977
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2021
+ * Walter Schweizer <[email protected]>
+ * Phil Sutter <[email protected]>
+ */
+
+#ifndef __SYNO_LEGACY_H
+#define __SYNO_LEGACY_H
+
+/* Marvell uboot parameters */
+#define ATAG_MV_UBOOT 0x41000403
+#define VER_NUM       0x03040400 /* 3.4.4 */
+
+#define BOARD_ID_BASE 0x0
+#define SYNO_DS109_ID (BOARD_ID_BASE + 0x15)
+#define SYNO_AXP_4BAY_2BAY (0xf + 1)
+
+#define ETHADDR_MAX	4
+#define USBPORT_MAX	3
+
+struct tag_mv_uboot {
+	u32 uboot_version;
+	u32 tclk;
+	u32 sysclk;
+	u32 isusbhost;
+	u8 macaddr[ETHADDR_MAX][ETH_ALEN];
+	u16 mtu[ETHADDR_MAX];
+	u32 fw_image_base;
+	u32 fw_image_size;
+};
+
+#endif /* __SYNO_LEGACY_H */
board/Synology/ds109/ds109.c +0 -32
index eaac95460c6e1..3914faaf37bb4 100644
@@ -114,38 +114,6 @@ void reset_misc(void)
  		     SOFTWARE_REBOOT);
  }
 
-/* Support old kernels */
-void setup_board_tags(struct tag **in_params)
-{
-	unsigned int boardId;
-	struct tag *params;
-	struct tag_mv_uboot *t;
-	int i;
-
-	printf("Synology board tags...");
-	params = *in_params;
-	t = (struct tag_mv_uboot *)&params->u;
-
-	t->uboot_version = VER_NUM;
-
-	boardId = SYNO_DS109_ID;
-	t->uboot_version |= boardId;
-
-	t->tclk = CONFIG_SYS_TCLK;
-	t->sysclk = CONFIG_SYS_TCLK*2;
-
-	t->isusbhost = 1;
-	for (i = 0; i < 4; i++)	{
-		memset(t->macaddr[i], 0, sizeof(t->macaddr[i]));
-		t->mtu[i] = 0;
-	}
-
-	params->hdr.tag = ATAG_MV_UBOOT;
-	params->hdr.size = tag_size(tag_mv_uboot);
-	params = tag_next(params);
-	*in_params = params;
-}
-
  #ifdef CONFIG_RESET_PHY_R
  /* Configure and enable MV88E1116 PHY */
  void reset_phy(void)
board/Synology/ds109/ds109.h +0 -17
index cc6ef991f3973..0cf05257c8d35 100644
@@ -23,21 +23,4 @@
  #define MV88E1116_RGMII_TXTM_CTRL	(1 << 4)
  #define MV88E1116_RGMII_RXTM_CTRL	(1 << 5)
 
-/* Marvell uboot parameters */
-#define ATAG_MV_UBOOT 0x41000403
-#define VER_NUM       0x03040400 /* 3.4.4 */
-#define BOARD_ID_BASE 0x0
-#define SYNO_DS109_ID (BOARD_ID_BASE+0x15)
-
-struct tag_mv_uboot {
-	u32 uboot_version;
-	u32 tclk;
-	u32 sysclk;
-	u32 isusbhost;
-	char macaddr[4][6];
-	u16 mtu[4];
-	u32 fw_image_base;
-	u32 fw_image_size;
-};
-
  #endif /* __DS109_H */
configs/ds414_defconfig +2 -3
index 412559256e6ca..8ef2e79dc91b0 100644
@@ -20,9 +20,8 @@ CONFIG_DEFAULT_DEVICE_TREE="armada-xp-synology-ds414"
  CONFIG_DEBUG_UART=y
  CONFIG_BOOTDELAY=3
  CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="console=ttyS0,115200"
-CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="usb start; sf probe"
+CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 rw syno_hw_version=DS414r1 ihd_num=4 netif_num=2 flash_size=8 SataLedSpecial=1 HddHotplug=1"
+# CONFIG_USE_PREBOOT is not set
  # CONFIG_DISPLAY_BOARDINFO is not set
  CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_SPL_I2C_SUPPORT=y
include/configs/ds109.h +2 -1
index 1f033ababf6ee..35d85361b4542 100644
@@ -44,7 +44,8 @@
  	"x_bootcmd_kernel=fatload usb 0 0x6400000 uImage\0" \
  	"x_bootargs=console=ttyS0,115200\0"	\
  	"x_bootargs_root=root=/dev/sda2 rootdelay=10\0" \
-	"ipaddr=192.168.1.5\0"
+	"ipaddr=192.168.1.5\0"		\
+	"usb0Mode=host\0"
 
  /*
   * Ethernet Driver configuration
include/configs/ds414.h +7 -1
index 8aa2d47bec68d..a2248cf75ad72 100644
@@ -6,6 +6,9 @@
  #ifndef _CONFIG_SYNOLOGY_DS414_H
  #define _CONFIG_SYNOLOGY_DS414_H
 
+/* Vendor kernel expects this MACH_TYPE */
+#define CONFIG_MACH_TYPE	3036
+
  /*
   * High Level Configuration Options (easy to change)
   */
@@ -74,8 +77,18 @@
  #define CONFIG_DDR_32BIT
 
  /* Default Environment */
-#define CONFIG_BOOTCOMMAND	"sf read ${loadaddr} 0xd0000 0x700000; bootm"
  #define CONFIG_LOADADDR		0x80000
+#define CONFIG_BOOTCOMMAND					\
+	"sf probe; "						\
+	"sf read ${loadaddr} 0xd0000 0x2d0000; "		\
+	"sf read ${ramdisk_addr_r} 0x3a0000 0x430000; "		\

include/configs/ds414.h line 94

Quoted 10 lines
include/configs/ds414.h +7 -0
+	"bootm ${loadaddr} ${ramdisk_addr_r}"
+
+#define CONFIG_EXTRA_ENV_SETTINGS				\
+	"initrd_high=0xffffffff\0"				\
+	"ramdisk_addr_r=0x8000000\0"				\
+	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
+	"ethmtu=1500\0eth1mtu=1500\0"
 
  /* increase autoneg timeout, my NIC sucks */
  #define PHY_ANEG_TIMEOUT	16000

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#18 lore raw

PATCH 4/5 ds414: Auto-populate env if appropriate

In reply to Phil Sutter

Define a misc_init_r() which calls "syno populate_env" if the environment seems incomplete (or default), indicated by missing "ethaddr" variable. With this in place, no random MAC address fallback is needed anymore.

---
 board/Synology/ds414/cmd_syno.c |  2 +-
 board/Synology/ds414/ds414.c    | 13 +++++++++++++
 configs/ds414_defconfig         |  4 +---
 3 files changed, 15 insertions(+), 4 deletions(-)
board/Synology/ds414/cmd_syno.c +1 -1
index a120c3123ffb3..07bb395da3acc 100644
@@ -22,7 +22,7 @@
 #define SYNO_CHKSUM_TAG		"CHK="
 
 
-static int do_syno_populate(int argc, char *const argv[])
+int do_syno_populate(int argc, char *const argv[])
 {
 	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
 	unsigned int cs = CONFIG_SF_DEFAULT_CS;
board/Synology/ds414/ds414.c +13 -0
index 9c4ce670ddfbd..c2469d6665255 100644
@@ -179,6 +179,19 @@ int board_init(void)
 	return 0;
 }
 
+#ifndef CONFIG_SPL_BUILD
+int do_syno_populate(int argc, char *const argv[]);
+
+int misc_init_r(void)
+{
+	if (!env_get("ethaddr")) {
+		puts("Incomplete environment, populating from SPI flash\n");
+		do_syno_populate(0, NULL);
+	}
+	return 0;
+}
+#endif
+
 int checkboard(void)
 {
 	puts("Board: DS414\n");
configs/ds414_defconfig +1 -3
index fa9366778748c..948b22f3d1f66 100644
@@ -21,10 +21,9 @@ CONFIG_DEBUG_UART=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 rw syno_hw_version=DS414r1 ihd_num=4 netif_num=2 flash_size=8 SataLedSpecial=1 HddHotplug=1"
-CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="usb start; sf probe"
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_I2C=y
@@ -47,7 +46,6 @@ CONFIG_ENV_OVERWRITE=y
 CONFIG_USE_ENV_SPI_MAX_HZ=y
 CONFIG_ENV_SPI_MAX_HZ=50000000
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SPL_OF_TRANSLATE=y
 CONFIG_BLK=y
 # CONFIG_MMC is not set
Signature · 1 line
2.30.1
#19 lore raw

PATCH 4/5 ds414: Auto-populate env if appropriate

Quoted 30 lines · Phil Sutter

Define a misc_init_r() which calls "syno populate_env" if the environment seems incomplete (or default), indicated by missing "ethaddr" variable. With this in place, no random MAC address fallback is needed anymore.

---
  board/Synology/ds414/cmd_syno.c |  2 +-
  board/Synology/ds414/ds414.c    | 13 +++++++++++++
  configs/ds414_defconfig         |  4 +---
  3 files changed, 15 insertions(+), 4 deletions(-)
board/Synology/ds414/cmd_syno.c +1 -1
index a120c3123ffb3..07bb395da3acc 100644
@@ -22,7 +22,7 @@
  #define SYNO_CHKSUM_TAG		"CHK="
 
 
-static int do_syno_populate(int argc, char *const argv[])
+int do_syno_populate(int argc, char *const argv[])
  {
  	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
  	unsigned int cs = CONFIG_SF_DEFAULT_CS;
board/Synology/ds414/ds414.c +0 -0
index 9c4ce670ddfbd..c2469d6665255 100644

board/Synology/ds414/ds414.c int board_init(void) · line 183

Quoted 5 lines
board/Synology/ds414/ds414.c +2 -0
@@ -179,6 +179,19 @@ int board_init(void)
  	return 0;
  }
 
+#ifndef CONFIG_SPL_BUILD
+int do_syno_populate(int argc, char *const argv[]);

I suspect that this prototype in a C file will trigger at least a checkpatch warning?

Other than that:

Thanks,
Stefan

Quoted 32 lines
board/Synology/ds414/ds414.c +11 -0
+
+int misc_init_r(void)
+{
+	if (!env_get("ethaddr")) {
+		puts("Incomplete environment, populating from SPI flash\n");
+		do_syno_populate(0, NULL);
+	}
+	return 0;
+}
+#endif
+
  int checkboard(void)
  {
  	puts("Board: DS414\n");
configs/ds414_defconfig +1 -2
index fa9366778748c..948b22f3d1f66 100644
@@ -21,10 +21,9 @@ CONFIG_DEBUG_UART=y
  CONFIG_BOOTDELAY=3
  CONFIG_USE_BOOTARGS=y
  CONFIG_BOOTARGS="console=ttyS0,115200 ip=off initrd=0x8000040,8M root=/dev/md0 rw syno_hw_version=DS414r1 ihd_num=4 netif_num=2 flash_size=8 SataLedSpecial=1 HddHotplug=1"
-CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="usb start; sf probe"
  # CONFIG_DISPLAY_BOARDINFO is not set
  CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_MISC_INIT_R=y
  CONFIG_SPL_I2C_SUPPORT=y
  # CONFIG_CMD_FLASH is not set
  CONFIG_CMD_I2C=y

configs/ds414_defconfig CONFIG_ENV_OVERWRITE=y · line 51

Quoted 7 lines
configs/ds414_defconfig +0 -1
@@ -47,7 +46,6 @@ CONFIG_ENV_OVERWRITE=y
  CONFIG_USE_ENV_SPI_MAX_HZ=y
  CONFIG_ENV_SPI_MAX_HZ=50000000
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_SPL_OF_TRANSLATE=y
  CONFIG_BLK=y
  # CONFIG_MMC is not set

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#20 lore raw

PATCH 4/5 ds414: Auto-populate env if appropriate

Quoted 34 lines · Stefan Roese
Quoted 33 lines · Phil Sutter

Define a misc_init_r() which calls "syno populate_env" if the environment seems incomplete (or default), indicated by missing "ethaddr" variable. With this in place, no random MAC address fallback is needed anymore.

---
  board/Synology/ds414/cmd_syno.c |  2 +-
  board/Synology/ds414/ds414.c    | 13 +++++++++++++
  configs/ds414_defconfig         |  4 +---
  3 files changed, 15 insertions(+), 4 deletions(-)
board/Synology/ds414/cmd_syno.c +1 -1
index a120c3123ffb3..07bb395da3acc 100644
@@ -22,7 +22,7 @@
  #define SYNO_CHKSUM_TAG		"CHK="
 
 
-static int do_syno_populate(int argc, char *const argv[])
+int do_syno_populate(int argc, char *const argv[])
  {
  	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
  	unsigned int cs = CONFIG_SF_DEFAULT_CS;
board/Synology/ds414/ds414.c +0 -0
index 9c4ce670ddfbd..c2469d6665255 100644
@@ -179,6 +179,19 @@ int board_init(void)
  	return 0;
  }
 
Quoted 5 lines

board/Synology/ds414/ds414.c int board_init(void) · line 183

Quoted 2 lines
board/Synology/ds414/ds414.c +2 -0
+#ifndef CONFIG_SPL_BUILD
+int do_syno_populate(int argc, char *const argv[]);

I suspect that this prototype in a C file will trigger at least a checkpatch warning?

What is checkpatch? ;)
Mea culpa, sometimes past me's dirty hacks slip my review. I'll go find a checkpatch-compliant way.

Thanks, Phil

#21 lore raw

PATCH 4/5 ds414: Auto-populate env if appropriate

Quoted 35 lines · Phil Sutter
Quoted 34 lines · Stefan Roese
Quoted 33 lines · Phil Sutter

Define a misc_init_r() which calls "syno populate_env" if the environment seems incomplete (or default), indicated by missing "ethaddr" variable. With this in place, no random MAC address fallback is needed anymore.

---
   board/Synology/ds414/cmd_syno.c |  2 +-
   board/Synology/ds414/ds414.c    | 13 +++++++++++++
   configs/ds414_defconfig         |  4 +---
   3 files changed, 15 insertions(+), 4 deletions(-)
board/Synology/ds414/cmd_syno.c +1 -1
index a120c3123ffb3..07bb395da3acc 100644
@@ -22,7 +22,7 @@
   #define SYNO_CHKSUM_TAG		"CHK="
 
 
-static int do_syno_populate(int argc, char *const argv[])
+int do_syno_populate(int argc, char *const argv[])
   {
   	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
   	unsigned int cs = CONFIG_SF_DEFAULT_CS;
board/Synology/ds414/ds414.c +0 -0
index 9c4ce670ddfbd..c2469d6665255 100644
@@ -179,6 +179,19 @@ int board_init(void)
   	return 0;
   }
 
Quoted 7 lines
Quoted 5 lines

board/Synology/ds414/ds414.c int board_init(void) · line 183

Quoted 2 lines
board/Synology/ds414/ds414.c +2 -0
+#ifndef CONFIG_SPL_BUILD
+int do_syno_populate(int argc, char *const argv[]);

I suspect that this prototype in a C file will trigger at least a checkpatch warning?

What is checkpatch? ;)

Provided with Linux and your favorite bootloader: ;)

./scripts/checkpatch.pl

Quoted 2 lines

Mea culpa, sometimes past me's dirty hacks slip my review. I'll go find a checkpatch-compliant way.

NP. Thanks for working on this.

Thanks,
Stefan

#22 lore raw

PATCH v2 4/5 ds414: Auto-populate env if appropriate

In reply to Phil Sutter

Define a misc_init_r() which calls "syno populate_env" if the environment seems incomplete (or default), indicated by missing "ethaddr" variable. With this in place, no random MAC address fallback is needed anymore.

---
Changes since v1:
- Don't drop PREBOOT, it is needed for XHCI functionality
- Introduce cmd_syno.h holding function prototype and defines
- No need to define misc_init_r() conditionally, get rid of surrounding #ifdef.

---
 board/Synology/ds414/cmd_syno.c |  9 +++------
 board/Synology/ds414/cmd_syno.h | 17 +++++++++++++++++
 board/Synology/ds414/ds414.c    | 11 +++++++++++
 configs/ds414_defconfig         |  2 +-
 4 files changed, 32 insertions(+), 7 deletions(-)
 create mode 100644 board/Synology/ds414/cmd_syno.h
board/Synology/ds414/cmd_syno.c +3 -6
index a120c3123ffb3..a62658a2eb6b2 100644
@@ -17,12 +17,9 @@
 #include <asm/io.h>
 #include "../drivers/ddr/marvell/axp/ddr3_init.h"
 
-#define ETHADDR_MAX		4
-#define SYNO_SN_TAG		"SN="
-#define SYNO_CHKSUM_TAG		"CHK="
+#include "cmd_syno.h"
 
-
-static int do_syno_populate(int argc, char *const argv[])
+int do_syno_populate(int argc, char *const argv[])
 {
 	unsigned int bus = CONFIG_SF_DEFAULT_BUS;
 	unsigned int cs = CONFIG_SF_DEFAULT_CS;
@@ -57,7 +54,7 @@ static int do_syno_populate(int argc, char *const argv[])
 		goto out_unmap;
 	}
 
-	for (n = 0; n < ETHADDR_MAX; n++) {
+	for (n = 0; n < SYNO_ETHADDR_MAX; n++) {
 		char ethaddr[ETH_ALEN];
 		int i, sum = 0;
 		unsigned char csum = 0;
board/Synology/ds414/cmd_syno.h new file +17 -0
new file mode 100644
index 0000000000000..42e435c803883
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Commands to deal with Synology specifics.
+ *
+ * Copyright (C) 2021  Phil Sutter <[email protected]>
+ */
+
+#ifndef _CMD_SYNO_H
+#define _CMD_SYNO_H
+
+#define SYNO_ETHADDR_MAX	4
+#define SYNO_SN_TAG		"SN="
+#define SYNO_CHKSUM_TAG		"CHK="
+
+int do_syno_populate(int argc, char *const argv[]);
+
+#endif /* _CMD_SYNO_H */
board/Synology/ds414/ds414.c +11 -0
index 9c4ce670ddfbd..abe6f9eb5e23d 100644
@@ -18,6 +18,8 @@
 #include "../arch/arm/mach-mvebu/serdes/axp/high_speed_env_spec.h"
 #include "../arch/arm/mach-mvebu/serdes/axp/board_env_spec.h"
 
+#include "cmd_syno.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /* GPP and MPP settings as found in mvBoardEnvSpec.c of Synology's U-Boot */
@@ -179,6 +181,15 @@ int board_init(void)
 	return 0;
 }
 
+int misc_init_r(void)
+{
+	if (!env_get("ethaddr")) {
+		puts("Incomplete environment, populating from SPI flash\n");
+		do_syno_populate(0, NULL);
+	}
+	return 0;
+}
+
 int checkboard(void)
 {
 	puts("Board: DS414\n");
configs/ds414_defconfig +1 -1
index 4fb0abee81c58..10657569ba937 100644
@@ -25,6 +25,7 @@ CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="pci enum; usb start"
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_I2C=y
@@ -47,7 +48,6 @@ CONFIG_ENV_OVERWRITE=y
 CONFIG_USE_ENV_SPI_MAX_HZ=y
 CONFIG_ENV_SPI_MAX_HZ=50000000
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SPL_OF_TRANSLATE=y
 CONFIG_BLK=y
 # CONFIG_MMC is not set
Signature · 1 line
2.30.1
#23 lore raw

PATCH 5/5 ds414: Add sample u-boot update command

In reply to Phil Sutter
---
 include/configs/ds414.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
include/configs/ds414.h +6 -1
index a2248cf75ad72..c8b45066cc75a 100644
@@ -88,7 +88,12 @@
 	"initrd_high=0xffffffff\0"				\
 	"ramdisk_addr_r=0x8000000\0"				\
 	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
-	"ethmtu=1500\0eth1mtu=1500\0"
+	"ethmtu=1500\0eth1mtu=1500\0"				\
+	"update_uboot=sf probe; dhcp; "				\
+		"mw.b ${loadaddr} 0x0 0xd0000; "		\
+		"tftpboot ${loadaddr} u-boot-spl.kwb; "		\
+		"sf update ${loadaddr} 0x0 0xd0000\0"
+
 
 /* increase autoneg timeout, my NIC sucks */
 #define PHY_ANEG_TIMEOUT	16000
Signature · 1 line
2.30.1
#24 lore raw

PATCH 5/5 ds414: Add sample u-boot update command

Quoted 1 line · Phil Sutter

It's common practice to add some minimal text in the commit text, even for simple patches.

One short question below...

Quoted 9 lines
---
  include/configs/ds414.h | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
include/configs/ds414.h +0 -0
index a2248cf75ad72..c8b45066cc75a 100644

include/configs/ds414.h line 96

Quoted 10 lines
include/configs/ds414.h +6 -1
@@ -88,7 +88,12 @@
  	"initrd_high=0xffffffff\0"				\
  	"ramdisk_addr_r=0x8000000\0"				\
  	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
-	"ethmtu=1500\0eth1mtu=1500\0"
+	"ethmtu=1500\0eth1mtu=1500\0"				\
+	"update_uboot=sf probe; dhcp; "				\
+		"mw.b ${loadaddr} 0x0 0xd0000; "		\
+		"tftpboot ${loadaddr} u-boot-spl.kwb; "		\
+		"sf update ${loadaddr} 0x0 0xd0000\0"
+

Wouldn't it be better to use ${filesize} instead of 0xd0000 here?

Other than that:

Thanks,
Stefan

#25 lore raw

PATCH 5/5 ds414: Add sample u-boot update command

Quoted 5 lines · Stefan Roese
Quoted 1 line · Phil Sutter

It's common practice to add some minimal text in the commit text, even for simple patches.

I should learn to put less meaningful subjects in those cases so I have an easier time finding something to write about in the description. Then again, your question indicates I just didn't think hard enough.

[...]

Quoted 9 lines
Quoted 9 lines
include/configs/ds414.h +0 -1
index a2248cf75ad72..c8b45066cc75a 100644
@@ -88,7 +88,12 @@
  	"initrd_high=0xffffffff\0"				\
  	"ramdisk_addr_r=0x8000000\0"				\
  	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
-	"ethmtu=1500\0eth1mtu=1500\0"
Quoted 8 lines

include/configs/ds414.h line 96

Quoted 6 lines
include/configs/ds414.h +6 -0
+	"ethmtu=1500\0eth1mtu=1500\0"				\
+	"update_uboot=sf probe; dhcp; "				\
+		"mw.b ${loadaddr} 0x0 0xd0000; "		\
+		"tftpboot ${loadaddr} u-boot-spl.kwb; "		\
+		"sf update ${loadaddr} 0x0 0xd0000\0"
+

Wouldn't it be better to use ${filesize} instead of 0xd0000 here?

U-Boot's "partition" size is fixed and hard-coded in the DTB at least. Putting the destination size as a limit at least avoids the unlikely chance of overwriting data past that partition.

BTW: I spent a while trying to make the DTB-defined partitions available in sf command, but eventually gave up. Seems I need to have this SPI->MTD mapping and still define partitions in environment. Not worth spending cycles on though, I was just curious because 'help sf' mentions partitions as offset alternatives.

Cheers, Phil

#26 lore raw

PATCH 5/5 ds414: Add sample u-boot update command

Quoted 9 lines · Phil Sutter
Quoted 5 lines · Stefan Roese
Quoted 1 line · Phil Sutter

It's common practice to add some minimal text in the commit text, even for simple patches.

I should learn to put less meaningful subjects in those cases so I have an easier time finding something to write about in the description.

;)

Quoted 2 lines

Then
again, your question indicates I just didn't think hard enough.

I agree that this "rule" is sometimes hard to understand. I myself am sometimes finding it stupid to write the same sentence twice.

Quoted 19 lines

[...]

Quoted 9 lines
Quoted 9 lines
include/configs/ds414.h +0 -1
index a2248cf75ad72..c8b45066cc75a 100644
@@ -88,7 +88,12 @@
   	"initrd_high=0xffffffff\0"				\
   	"ramdisk_addr_r=0x8000000\0"				\
   	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
-	"ethmtu=1500\0eth1mtu=1500\0"
Quoted 8 lines

include/configs/ds414.h line 96

Quoted 6 lines
include/configs/ds414.h +6 -0
+	"ethmtu=1500\0eth1mtu=1500\0"				\
+	"update_uboot=sf probe; dhcp; "				\
+		"mw.b ${loadaddr} 0x0 0xd0000; "		\
+		"tftpboot ${loadaddr} u-boot-spl.kwb; "		\
+		"sf update ${loadaddr} 0x0 0xd0000\0"
+

Wouldn't it be better to use ${filesize} instead of 0xd0000 here?

Quoted 3 lines

U-Boot's "partition" size is fixed and hard-coded in the DTB at least. Putting the destination size as a limit at least avoids the unlikely chance of overwriting data past that partition.

Ok, understood.

Quoted 5 lines

BTW: I spent a while trying to make the DTB-defined partitions available in sf command, but eventually gave up. Seems I need to have this SPI->MTD mapping and still define partitions in environment. Not worth spending cycles on though, I was just curious because 'help sf' mentions partitions as offset alternatives.

Not looking to hard into your issue here, but did you take a look at the "mtd" command? It's newer than the other flash related commands and can manage all kind of flash types (SPI NOR, NAND etc) in one place. And also integrated better into the MTD partitions IIRC.

Thanks,
Stefan

#27 lore raw

PATCH 5/5 ds414: Add sample u-boot update command

Quoted 11 lines · Stefan Roese
Quoted 9 lines · Phil Sutter
Quoted 5 lines · Stefan Roese
Quoted 1 line · Phil Sutter

It's common practice to add some minimal text in the commit text, even for simple patches.

I should learn to put less meaningful subjects in those cases so I have an easier time finding something to write about in the description.

Quoted 7 lines

;)

Quoted 2 lines

Then
again, your question indicates I just didn't think hard enough.

I agree that this "rule" is sometimes hard to understand. I myself am sometimes finding it stupid to write the same sentence twice.

I've seen enough projects where one-liners are absolutely acceptable, I'd rather write redundant texts than accepting that coding "style". Nothing worse than confusing code garnished with no description at all. :)

[...]

Quoted 10 lines
Quoted 5 lines

BTW: I spent a while trying to make the DTB-defined partitions available in sf command, but eventually gave up. Seems I need to have this SPI->MTD mapping and still define partitions in environment. Not worth spending cycles on though, I was just curious because 'help sf' mentions partitions as offset alternatives.

Not looking to hard into your issue here, but did you take a look at the "mtd" command? It's newer than the other flash related commands and can manage all kind of flash types (SPI NOR, NAND etc) in one place. And also integrated better into the MTD partitions IIRC.

Hmm, for some reason I assumed 'sf' is the optimal tool for SPI flashes. I'll give it a try, thanks for the hint!

Thanks, Phil

#28 lore raw

PATCH v2 5/5 ds414: Add sample u-boot update command

In reply to Phil Sutter

Call 'run update_uboot' to fetch u-boot-spl.kwb via TFTP and write it into the correct SPI flash location. The latter's size is defined in DS414's DTB file, so hard-coding it should be acceptable here.

Take care to not append garbage from RAM to the written image and to stay within assigned flash boundaries even if an oversized image was fetched.

---
Changes since v1:
- Add a proper commit message.

---
 include/configs/ds414.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
include/configs/ds414.h +6 -1
index a2248cf75ad72..c8b45066cc75a 100644
@@ -88,7 +88,12 @@
 	"initrd_high=0xffffffff\0"				\
 	"ramdisk_addr_r=0x8000000\0"				\
 	"usb0Mode=host\0usb1Mode=host\0usb2Mode=device\0"	\
-	"ethmtu=1500\0eth1mtu=1500\0"
+	"ethmtu=1500\0eth1mtu=1500\0"				\
+	"update_uboot=sf probe; dhcp; "				\
+		"mw.b ${loadaddr} 0x0 0xd0000; "		\
+		"tftpboot ${loadaddr} u-boot-spl.kwb; "		\
+		"sf update ${loadaddr} 0x0 0xd0000\0"
+
 
 /* increase autoneg timeout, my NIC sucks */
 #define PHY_ANEG_TIMEOUT	16000
Signature · 1 line
2.30.1
#29 lore raw

cover Synology DS414 integration mini-review

In reply to Phil Sutter
Quoted 37 lines · Phil Sutter

Board-specific code lacked a Kconfig file defining CONFIG_SYS_BOARD, CONFIG_SYS_VENDOR, etc - patch 1 fixes that.

I was very pleased to notice the recent changes in PCI/USB code fixed xhci-pci functionality on DS414, so patch 2 enables XHCI support in defconfig.

Adjusting DS109 atags code for DS414 allowed to successfully boot vendor Linux, so I went ahead and generalized the code to support both boards in patch 3.

Patch 4 introduces a misc_init_r() routine populating environment from Synology's special flash partition if appropriate - less manual work for users and no need for random MAC address fallback anymore.

Patch 6 extends the default environment by a command to update u-boot via tftp.

Phil Sutter (5):
ds414: Add a Kconfig defining some strings
configs: ds414: Enable XHCI_PCI by default
board/Synology: Unify legacy kernel support
ds414: Auto-populate env if appropriate
ds414: Add sample u-boot update command

  board/Synology/common/Makefile  |  5 +++
  board/Synology/common/legacy.c  | 75 +++++++++++++++++++++++++++++++++
  board/Synology/common/legacy.h  | 33 +++++++++++++++
  board/Synology/ds109/ds109.c    | 32 --------------
  board/Synology/ds109/ds109.h    | 17 --------
  board/Synology/ds414/Kconfig    | 12 ++++++
  board/Synology/ds414/cmd_syno.c |  2 +-
  board/Synology/ds414/ds414.c    | 13 ++++++
  configs/ds414_defconfig         |  7 ++-
  include/configs/ds109.h         |  3 +-
  include/configs/ds414.h         | 20 ++++++++-
  11 files changed, 163 insertions(+), 56 deletions(-)
Quoted 5 lines

create mode 100644 board/Synology/common/Makefile create mode 100644 board/Synology/common/legacy.c create mode 100644 board/Synology/common/legacy.h create mode 100644 board/Synology/ds414/Kconfig

Applied to u-boot-marvell/master (whole series)

Thanks,
Stefan