diff options
author | Karel Kočí <cynerd@email.cz> | 2022-08-20 09:25:19 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-09-27 10:21:50 +0200 |
commit | ff1073d03d303d3b15e66d03dc4a5a479a387fa7 (patch) | |
tree | 1bc3c05c905046b372b43cab45369b4c456a8daf /nixos | |
parent | c12a03b8511f4742123959f0cb3c96a441ac2581 (diff) | |
download | nixturris-ff1073d03d303d3b15e66d03dc4a5a479a387fa7.tar.gz nixturris-ff1073d03d303d3b15e66d03dc4a5a479a387fa7.tar.bz2 nixturris-ff1073d03d303d3b15e66d03dc4a5a479a387fa7.zip |
Attempt to fix Omnia's wifi and Mox ethernet
Diffstat (limited to 'nixos')
17 files changed, 931 insertions, 25 deletions
diff --git a/nixos/default.nix b/nixos/default.nix index 50a4ff6..445e078 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -10,6 +10,7 @@ self: let turris-omnia-support = import ./modules/turris-omnia-support.nix; turris-tarball = import ./modules/turris-tarball.nix; + kernel-patches = import ./modules/kernel-patches.nix; armv7l-overlay = import ./modules/armv7l-overlay.nix; hostapd = import ./modules/hostapd.nix; diff --git a/nixos/modules/hostapd.nix b/nixos/modules/hostapd.nix index 0dd5d23..3b2d9e6 100644 --- a/nixos/modules/hostapd.nix +++ b/nixos/modules/hostapd.nix @@ -478,6 +478,7 @@ let ${concatMapStringsSep "\n" (bss: '' bss=${bss} + ssid=${icfg.bss.${bss}.ssid} ${configBss icfg.bss."${bss}"}'') (attrNames icfg.bss)} ${icfg.extraConfig} diff --git a/nixos/modules/kernel-patches.nix b/nixos/modules/kernel-patches.nix new file mode 100644 index 0000000..516508c --- /dev/null +++ b/nixos/modules/kernel-patches.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + # Kernel patches from Turris OS + boot.kernelPatches = [{ + name = "ARM-dts-turris-omnia-enable-LED-controller-node"; + patch = ./kernel-patches/0001-ARM-dts-turris-omnia-enable-LED-controller-node.patch; + }{ + name = "leds-turris-omnia-support-HW-controlled-mode-via-pri"; + patch = ./kernel-patches/0002-leds-turris-omnia-support-HW-controlled-mode-via-pri.patch; + }{ + name = "leds-turris-omnia-initialize-multi-intensity-to-full"; + patch = ./kernel-patches/0003-leds-turris-omnia-initialize-multi-intensity-to-full.patch; + }{ + name = "leds-turris-omnia-change-max-brightness-from-255-to-"; + patch = ./kernel-patches/0004-leds-turris-omnia-change-max-brightness-from-255-to-.patch; + }{ + name = "generic-Mangle-bootloader-s-kernel-arguments"; + patch = ./kernel-patches/0005-generic-Mangle-bootloader-s-kernel-arguments.patch; + }{ + name = "cpuidle-mvebu-indicate-failure-to-enter-deeper-sleep"; + patch = ./kernel-patches/0006-cpuidle-mvebu-indicate-failure-to-enter-deeper-sleep.patch; + }{ + name = "pci-mvebu-time-out-reset-on-link-up"; + patch = ./kernel-patches/0007-pci-mvebu-time-out-reset-on-link-up.patch; + }{ + name = "ARM-dts-mvebu-armada-385-turris-omnia-separate-dts-f"; + patch = ./kernel-patches/0008-ARM-dts-mvebu-armada-385-turris-omnia-separate-dts-f.patch; + }{ + name = "phy-marvell-phy-mvebu-a3700-comphy-Change-2500base-x"; + patch = ./kernel-patches/0009-phy-marvell-phy-mvebu-a3700-comphy-Change-2500base-x.patch; + }{ + name = "Rename-device-tree-for-Omnia-back-as-that-is-what-is"; + patch = ./kernel-patches/0010-Rename-device-tree-for-Omnia-back-as-that-is-what-is.patch; + }]; + }; +} diff --git a/nixos/modules/kernel-patches/0001-ARM-dts-turris-omnia-enable-LED-controller-node.patch b/nixos/modules/kernel-patches/0001-ARM-dts-turris-omnia-enable-LED-controller-node.patch new file mode 100644 index 0000000..a3d421a --- /dev/null +++ b/nixos/modules/kernel-patches/0001-ARM-dts-turris-omnia-enable-LED-controller-node.patch @@ -0,0 +1,53 @@ +From d33a04c156e91d813fc4dae3ffc9f87715b13446 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org> +Date: Mon, 4 Jul 2022 13:36:22 +0200 +Subject: [PATCH 01/10] ARM: dts: turris-omnia: enable LED controller node +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The LED controller node is disabled because the leds-turris-omnia driver +does not support setting the LED blinking to be controlled by the MCU. + +The patches for that have now been sent [1], so let's enable the node. + +[1] https://lore.kernel.org/linux-leds/20220704105955.15474-1-kabel@kernel.org/T/ + +Signed-off-by: Marek Behún <kabel@kernel.org> +--- + arch/arm/boot/dts/armada-385-turris-omnia.dts | 7 ++----- + 1 file changed, 2 insertions(+), 5 deletions(-) + +diff --git a/arch/arm/boot/dts/armada-385-turris-omnia.dts b/arch/arm/boot/dts/armada-385-turris-omnia.dts +index f4878df39753..bcced203c612 100644 +--- a/arch/arm/boot/dts/armada-385-turris-omnia.dts ++++ b/arch/arm/boot/dts/armada-385-turris-omnia.dts +@@ -191,15 +191,13 @@ led-controller@2b { + reg = <0x2b>; + #address-cells = <1>; + #size-cells = <0>; ++ status = "okay"; + + /* + * LEDs are controlled by MCU (STM32F0) at + * address 0x2b. + * +- * The driver does not support HW control mode +- * for the LEDs yet. Disable the LEDs for now. +- * +- * Also LED functions are not stable yet: ++ * LED functions are not stable yet: + * - there are 3 LEDs connected via MCU to PCIe + * ports. One of these ports supports mSATA. + * There is no mSATA nor PCIe function. +@@ -210,7 +208,6 @@ led-controller@2b { + * B. Again there is no such function defined. + * For now we use LED_FUNCTION_INDICATOR + */ +- status = "disabled"; + + multi-led@0 { + reg = <0x0>; +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0002-leds-turris-omnia-support-HW-controlled-mode-via-pri.patch b/nixos/modules/kernel-patches/0002-leds-turris-omnia-support-HW-controlled-mode-via-pri.patch new file mode 100644 index 0000000..1bd6acc --- /dev/null +++ b/nixos/modules/kernel-patches/0002-leds-turris-omnia-support-HW-controlled-mode-via-pri.patch @@ -0,0 +1,125 @@ +From 2760691208ad6ce37503007c0f3596532fd813e3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org> +Date: Mon, 4 Jul 2022 12:59:53 +0200 +Subject: [PATCH 02/10] leds: turris-omnia: support HW controlled mode via + private trigger +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Add support for enabling MCU controlled mode of the Turris Omnia LEDs +via a LED private trigger called "omnia-mcu". + +When in MCU controlled mode, the user can still set LED color, but the +blinking is done by MCU, which does different things for various LEDs: +- WAN LED is blinked according to the LED[0] pin of the WAN PHY +- LAN LEDs are blinked according to the LED[0] output of corresponding + port of the LAN switch +- PCIe LEDs are blinked according to the logical OR of the MiniPCIe port + LED pins + +For a long time I wanted to actually do this differently: I wanted to +make the netdev trigger to transparently offload the blinking to the HW +if user set compatible settings for the netdev trigger. +There was some work on this, and hopefully we will be able to complete +it sometime, but since there are various complications, it will probably +not be soon. + +In the meantime let's support HW controlled mode via this private LED +trigger. If, in the future, we manage to complete the netdev trigger +offloading, we can still keep this private trigger for backwards +compatiblity, if needed. + +We also set "omnia-mcu" to cdev->default_trigger, so that the MCU keeps +control until the user first wants to take over it. If a different +default trigger is specified in device-tree via the +`linux,default-trigger` property, LED class will overwrite +cdev->default_trigger, and so the DT property will be respected. + +Signed-off-by: Marek Behún <kabel@kernel.org> +--- + drivers/leds/Kconfig | 1 + + drivers/leds/leds-turris-omnia.c | 41 ++++++++++++++++++++++++++++++++ + 2 files changed, 42 insertions(+) + +diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig +index a49979f41eee..bc148320416d 100644 +--- a/drivers/leds/Kconfig ++++ b/drivers/leds/Kconfig +@@ -163,6 +163,7 @@ config LEDS_TURRIS_OMNIA + depends on I2C + depends on MACH_ARMADA_38X || COMPILE_TEST + depends on OF ++ select LEDS_TRIGGERS + help + This option enables basic support for the LEDs found on the front + side of CZ.NIC's Turris Omnia router. There are 12 RGB LEDs on the +diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c +index 1adfed1c0619..c2dfb22d3065 100644 +--- a/drivers/leds/leds-turris-omnia.c ++++ b/drivers/leds/leds-turris-omnia.c +@@ -41,6 +41,39 @@ struct omnia_leds { + struct omnia_led leds[]; + }; + ++static struct led_hw_trigger_type omnia_hw_trigger_type; ++ ++static int omnia_hwtrig_activate(struct led_classdev *cdev) ++{ ++ struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); ++ struct omnia_led *led = to_omnia_led(lcdev_to_mccdev(cdev)); ++ ++ /* put the LED into MCU controlled mode */ ++ return i2c_smbus_write_byte_data(leds->client, CMD_LED_MODE, ++ CMD_LED_MODE_LED(led->reg)); ++} ++ ++static void omnia_hwtrig_deactivate(struct led_classdev *cdev) ++{ ++ struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); ++ struct omnia_led *led = to_omnia_led(lcdev_to_mccdev(cdev)); ++ int ret; ++ ++ /* put the LED into software mode */ ++ ret = i2c_smbus_write_byte_data(leds->client, CMD_LED_MODE, ++ CMD_LED_MODE_LED(led->reg) | ++ CMD_LED_MODE_USER); ++ if (ret < 0) ++ dev_err(cdev->dev, "Cannot put to software mode: %i\n", ret); ++} ++ ++static struct led_trigger omnia_hw_trigger = { ++ .name = "omnia-mcu", ++ .activate = omnia_hwtrig_activate, ++ .deactivate = omnia_hwtrig_deactivate, ++ .trigger_type = &omnia_hw_trigger_type, ++}; ++ + static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, + enum led_brightness brightness) + { +@@ -112,6 +145,8 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, + cdev = &led->mc_cdev.led_cdev; + cdev->max_brightness = 255; + cdev->brightness_set_blocking = omnia_led_brightness_set_blocking; ++ cdev->trigger_type = &omnia_hw_trigger_type; ++ cdev->default_trigger = omnia_hw_trigger.name; + + /* put the LED into software mode */ + ret = i2c_smbus_write_byte_data(client, CMD_LED_MODE, +@@ -228,6 +263,12 @@ static int omnia_leds_probe(struct i2c_client *client, + + mutex_init(&leds->lock); + ++ ret = devm_led_trigger_register(dev, &omnia_hw_trigger); ++ if (ret < 0) { ++ dev_err(dev, "Cannot register private LED trigger: %d\n", ret); ++ return ret; ++ } ++ + led = &leds->leds[0]; + for_each_available_child_of_node(np, child) { + ret = omnia_led_register(client, led, child); +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0003-leds-turris-omnia-initialize-multi-intensity-to-full.patch b/nixos/modules/kernel-patches/0003-leds-turris-omnia-initialize-multi-intensity-to-full.patch new file mode 100644 index 0000000..4f9cee4 --- /dev/null +++ b/nixos/modules/kernel-patches/0003-leds-turris-omnia-initialize-multi-intensity-to-full.patch @@ -0,0 +1,38 @@ +From 6ad5109b744e8f10bb14f948b75c38b639f97989 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org> +Date: Mon, 4 Jul 2022 12:59:54 +0200 +Subject: [PATCH 03/10] leds: turris-omnia: initialize multi-intensity to full +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The default color of each LED before driver probe (255, 255, 255). +Initialize multi_intensity to this value, so that it corresponds to the +reality. + +Signed-off-by: Marek Behún <kabel@kernel.org> +--- + drivers/leds/leds-turris-omnia.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c +index c2dfb22d3065..fae155bd119c 100644 +--- a/drivers/leds/leds-turris-omnia.c ++++ b/drivers/leds/leds-turris-omnia.c +@@ -131,10 +131,13 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, + } + + led->subled_info[0].color_index = LED_COLOR_ID_RED; ++ led->subled_info[0].intensity = 255; + led->subled_info[0].channel = 0; + led->subled_info[1].color_index = LED_COLOR_ID_GREEN; ++ led->subled_info[1].intensity = 255; + led->subled_info[1].channel = 1; + led->subled_info[2].color_index = LED_COLOR_ID_BLUE; ++ led->subled_info[2].intensity = 255; + led->subled_info[2].channel = 2; + + led->mc_cdev.subled_info = led->subled_info; +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0004-leds-turris-omnia-change-max-brightness-from-255-to-.patch b/nixos/modules/kernel-patches/0004-leds-turris-omnia-change-max-brightness-from-255-to-.patch new file mode 100644 index 0000000..9f63b79 --- /dev/null +++ b/nixos/modules/kernel-patches/0004-leds-turris-omnia-change-max-brightness-from-255-to-.patch @@ -0,0 +1,36 @@ +From 74951d542c10fbb181454c31d28075170528a14f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org> +Date: Mon, 4 Jul 2022 12:59:55 +0200 +Subject: [PATCH 04/10] leds: turris-omnia: change max brightness from 255 to 1 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Using binary brightness makes more sense for this controller, because +internally in the MCU it works that way: the LED has a color, and a +state whether it is ON or OFF. + +The resulting brightness computation with led_mc_calc_color_components() +will now always result in either (0, 0, 0) or the multi_intensity value. + +Signed-off-by: Marek Behún <kabel@kernel.org> +--- + drivers/leds/leds-turris-omnia.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c +index fae155bd119c..f53bdc3f4cea 100644 +--- a/drivers/leds/leds-turris-omnia.c ++++ b/drivers/leds/leds-turris-omnia.c +@@ -146,7 +146,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, + init_data.fwnode = &np->fwnode; + + cdev = &led->mc_cdev.led_cdev; +- cdev->max_brightness = 255; ++ cdev->max_brightness = 1; + cdev->brightness_set_blocking = omnia_led_brightness_set_blocking; + cdev->trigger_type = &omnia_hw_trigger_type; + cdev->default_trigger = omnia_hw_trigger.name; +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0005-generic-Mangle-bootloader-s-kernel-arguments.patch b/nixos/modules/kernel-patches/0005-generic-Mangle-bootloader-s-kernel-arguments.patch new file mode 100644 index 0000000..4eafb31 --- /dev/null +++ b/nixos/modules/kernel-patches/0005-generic-Mangle-bootloader-s-kernel-arguments.patch @@ -0,0 +1,217 @@ +From 7f478ddf690dfccd8aea406a9697e1448920bf0f Mon Sep 17 00:00:00 2001 +From: Adrian Panella <ianchi74@outlook.com> +Date: Thu, 9 Mar 2017 09:37:17 +0100 +Subject: [PATCH 05/10] generic: Mangle bootloader's kernel arguments + +The command-line arguments provided by the boot loader will be +appended to a new device tree property: bootloader-args. +If there is a property "append-rootblock" in DT under /chosen +and a root= option in bootloaders command line it will be parsed +and added to DT bootargs with the form: <append-rootblock>XX. +Only command line ATAG will be processed, the rest of the ATAGs +sent by bootloader will be ignored. +This is usefull in dual boot systems, to get the current root partition +without afecting the rest of the system. + +Signed-off-by: Adrian Panella <ianchi74@outlook.com> + +This patch has been modified to be mvebu specific. The original patch +did not pass the bootloader cmdline on if no append-rootblock stanza +was found, resulting in blank cmdline and failure to boot. + +Signed-off-by: Michael Gray <michael.gray@lantisproject.com> +--- + arch/arm/Kconfig | 11 ++++ + arch/arm/boot/compressed/atags_to_fdt.c | 85 ++++++++++++++++++++++++- + init/main.c | 16 +++++ + 3 files changed, 111 insertions(+), 1 deletion(-) + +diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig +index 7630ba9cb6cc..dae040cc2a4f 100644 +--- a/arch/arm/Kconfig ++++ b/arch/arm/Kconfig +@@ -1638,6 +1638,17 @@ config ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND + The command-line arguments provided by the boot loader will be + appended to the the device tree bootargs property. + ++config ARM_ATAG_DTB_COMPAT_CMDLINE_MANGLE ++ bool "Append rootblock parsing bootloader's kernel arguments" ++ help ++ The command-line arguments provided by the boot loader will be ++ appended to a new device tree property: bootloader-args. ++ If there is a property "append-rootblock" in DT under /chosen ++ and a root= option in bootloaders command line it will be parsed ++ and added to DT bootargs with the form: <append-rootblock>XX. ++ Only command line ATAG will be processed, the rest of the ATAGs ++ sent by bootloader will be ignored. ++ + endchoice + + config CMDLINE +diff --git a/arch/arm/boot/compressed/atags_to_fdt.c b/arch/arm/boot/compressed/atags_to_fdt.c +index 1feb6b0f7a1f..fb8cd4f07e60 100644 +--- a/arch/arm/boot/compressed/atags_to_fdt.c ++++ b/arch/arm/boot/compressed/atags_to_fdt.c +@@ -5,6 +5,8 @@ + + #if defined(CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND) + #define do_extend_cmdline 1 ++#elif defined(CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_MANGLE) ++#define do_extend_cmdline 1 + #else + #define do_extend_cmdline 0 + #endif +@@ -69,6 +71,72 @@ static uint32_t get_cell_size(const void *fdt) + return cell_size; + } + ++#if defined(CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_MANGLE) ++ ++static char *append_rootblock(char *dest, const char *str, int len, void *fdt) ++{ ++ char *ptr, *end; ++ char *root="root="; ++ int i, l; ++ const char *rootblock; ++ ++ //ARM doesn't have __HAVE_ARCH_STRSTR, so search manually ++ ptr = str - 1; ++ ++ do { ++ //first find an 'r' at the begining or after a space ++ do { ++ ptr++; ++ ptr = strchr(ptr, 'r'); ++ if (!ptr) ++ goto no_append; ++ ++ } while (ptr != str && *(ptr-1) != ' '); ++ ++ //then check for the rest ++ for(i = 1; i <= 4; i++) ++ if(*(ptr+i) != *(root+i)) break; ++ ++ } while (i != 5); ++ ++ end = strchr(ptr, ' '); ++ end = end ? (end - 1) : (strchr(ptr, 0) - 1); ++ ++ //find partition number (assumes format root=/dev/mtdXX | /dev/mtdblockXX | yy:XX ) ++ for( i = 0; end >= ptr && *end >= '0' && *end <= '9'; end--, i++); ++ ptr = end + 1; ++ ++ /* if append-rootblock property is set use it to append to command line */ ++ rootblock = getprop(fdt, "/chosen", "append-rootblock", &l); ++ if (rootblock == NULL) ++ goto no_append; ++ ++ if (*dest != ' ') { ++ *dest = ' '; ++ dest++; ++ len++; ++ } ++ ++ if (len + l + i <= COMMAND_LINE_SIZE) { ++ memcpy(dest, rootblock, l); ++ dest += l - 1; ++ memcpy(dest, ptr, i); ++ dest += i; ++ } ++ ++ return dest; ++ ++no_append: ++ len = strlen(str); ++ if (len + 1 < COMMAND_LINE_SIZE) { ++ memcpy(dest, str, len); ++ dest += len; ++ } ++ ++ return dest; ++} ++#endif ++ + static void merge_fdt_bootargs(void *fdt, const char *fdt_cmdline) + { + char cmdline[COMMAND_LINE_SIZE]; +@@ -88,12 +156,21 @@ static void merge_fdt_bootargs(void *fdt, const char *fdt_cmdline) + + /* and append the ATAG_CMDLINE */ + if (fdt_cmdline) { ++ ++#if defined(CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_MANGLE) ++ //save original bootloader args ++ //and append ubi.mtd with root partition number to current cmdline ++ setprop_string(fdt, "/chosen", "bootloader-args", fdt_cmdline); ++ ptr = append_rootblock(ptr, fdt_cmdline, len, fdt); ++ ++#else + len = strlen(fdt_cmdline); + if (ptr - cmdline + len + 2 < COMMAND_LINE_SIZE) { + *ptr++ = ' '; + memcpy(ptr, fdt_cmdline, len); + ptr += len; + } ++#endif + } + *ptr = '\0'; + +@@ -168,7 +245,9 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) + else + setprop_string(fdt, "/chosen", "bootargs", + atag->u.cmdline.cmdline); +- } else if (atag->hdr.tag == ATAG_MEM) { ++ } ++#ifndef CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_MANGLE ++ else if (atag->hdr.tag == ATAG_MEM) { + if (memcount >= sizeof(mem_reg_property)/4) + continue; + if (!atag->u.mem.size) +@@ -212,6 +291,10 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) + setprop(fdt, "/memory", "reg", mem_reg_property, + 4 * memcount * memsize); + } ++#else ++ ++ } ++#endif + + return fdt_pack(fdt); + } +diff --git a/init/main.c b/init/main.c +index 1fe7942f5d4a..fa08c129d3e1 100644 +--- a/init/main.c ++++ b/init/main.c +@@ -113,6 +113,10 @@ + + #include <kunit/test.h> + ++#if defined(CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_MANGLE) ++#include <linux/of.h> ++#endif ++ + static int kernel_init(void *); + + extern void init_IRQ(void); +@@ -961,6 +965,18 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) + page_alloc_init(); + + pr_notice("Kernel command line: %s\n", saved_command_line); ++ ++#if defined(CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_MANGLE) ++ //Show bootloader's original command line for reference ++ if(of_chosen) { ++ const char *prop = of_get_property(of_chosen, "bootloader-args", NULL); ++ if(prop) ++ pr_notice("Bootloader command line (ignored): %s\n", prop); ++ else ++ pr_notice("Bootloader command line not present\n"); ++ } ++#endif ++ + /* parameters may set static keys */ + jump_label_init(); + parse_early_param(); +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0006-cpuidle-mvebu-indicate-failure-to-enter-deeper-sleep.patch b/nixos/modules/kernel-patches/0006-cpuidle-mvebu-indicate-failure-to-enter-deeper-sleep.patch new file mode 100644 index 0000000..527a4f7 --- /dev/null +++ b/nixos/modules/kernel-patches/0006-cpuidle-mvebu-indicate-failure-to-enter-deeper-sleep.patch @@ -0,0 +1,46 @@ +From 0ac42f2a36490ee410b7c88720652ded4ec6beff Mon Sep 17 00:00:00 2001 +From: Russell King <rmk+kernel@arm.linux.org.uk> +Date: Sat, 3 Oct 2015 09:13:05 +0100 +Subject: [PATCH 06/10] cpuidle: mvebu: indicate failure to enter deeper sleep + states + +The cpuidle ->enter method expects the return value to be the sleep +state we entered. Returning negative numbers or other codes is not +permissible since coupled CPU idle was merged. + +At least some of the mvebu_v7_cpu_suspend() implementations return the +value from cpu_suspend(), which returns zero if the CPU vectors back +into the kernel via cpu_resume() (the success case), or the non-zero +return value of the suspend actor, or one (failure cases). + +We do not want to be returning the failure case value back to CPU idle +as that indicates that we successfully entered one of the deeper idle +states. Always return zero instead, indicating that we slept for the +shortest amount of time. + +Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> +--- + drivers/cpuidle/cpuidle-mvebu-v7.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/drivers/cpuidle/cpuidle-mvebu-v7.c b/drivers/cpuidle/cpuidle-mvebu-v7.c +index 01a856971f05..18ded9e7cb34 100644 +--- a/drivers/cpuidle/cpuidle-mvebu-v7.c ++++ b/drivers/cpuidle/cpuidle-mvebu-v7.c +@@ -39,8 +39,12 @@ static int mvebu_v7_enter_idle(struct cpuidle_device *dev, + ret = mvebu_v7_cpu_suspend(deepidle); + cpu_pm_exit(); + ++ /* ++ * If we failed to enter the desired state, indicate that we ++ * slept lightly. ++ */ + if (ret) +- return ret; ++ return 0; + + return index; + } +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0007-pci-mvebu-time-out-reset-on-link-up.patch b/nixos/modules/kernel-patches/0007-pci-mvebu-time-out-reset-on-link-up.patch new file mode 100644 index 0000000..b163995 --- /dev/null +++ b/nixos/modules/kernel-patches/0007-pci-mvebu-time-out-reset-on-link-up.patch @@ -0,0 +1,65 @@ +From 2793db3bb1f859bde77b40fd27da1452a06daf8d Mon Sep 17 00:00:00 2001 +From: Russell King <rmk+kernel@armlinux.org.uk> +Date: Sat, 9 Jul 2016 10:58:16 +0100 +Subject: [PATCH 07/10] pci: mvebu: time out reset on link up + +If the port reports that the link is up while we are resetting, there's +little point in waiting for the full duration. + +Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> +--- + drivers/pci/controller/pci-mvebu.c | 20 ++++++++++++++------ + 1 file changed, 14 insertions(+), 6 deletions(-) + +diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c +index c1ffdb06c971..b02f8120c24b 100644 +--- a/drivers/pci/controller/pci-mvebu.c ++++ b/drivers/pci/controller/pci-mvebu.c +@@ -1415,6 +1415,7 @@ static int mvebu_pcie_powerup(struct mvebu_pcie_port *port) + + if (port->reset_gpio) { + u32 reset_udelay = PCI_PM_D3COLD_WAIT * 1000; ++ unsigned int i; + + of_property_read_u32(port->dn, "reset-delay-us", + &reset_udelay); +@@ -1422,7 +1423,13 @@ static int mvebu_pcie_powerup(struct mvebu_pcie_port *port) + udelay(100); + + gpiod_set_value_cansleep(port->reset_gpio, 0); +- msleep(reset_udelay / 1000); ++ for (i = 0; i < reset_udelay; i += 1000) { ++ if (mvebu_pcie_link_up(port)) ++ break; ++ msleep(1); ++ } ++ ++ printk("%s: reset completed in %dus\n", port->name, i); + } + + return 0; +@@ -1539,15 +1546,16 @@ static int mvebu_pcie_probe(struct platform_device *pdev) + if (!child) + continue; + +- ret = mvebu_pcie_powerup(port); +- if (ret < 0) +- continue; +- + port->base = mvebu_pcie_map_registers(pdev, child, port); + if (IS_ERR(port->base)) { + dev_err(dev, "%s: cannot map registers\n", port->name); + port->base = NULL; +- mvebu_pcie_powerdown(port); ++ continue; ++ } ++ ++ ret = mvebu_pcie_powerup(port); ++ if (ret < 0) { ++ port->base = NULL; + continue; + } + +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0008-ARM-dts-mvebu-armada-385-turris-omnia-separate-dts-f.patch b/nixos/modules/kernel-patches/0008-ARM-dts-mvebu-armada-385-turris-omnia-separate-dts-f.patch new file mode 100644 index 0000000..a292738 --- /dev/null +++ b/nixos/modules/kernel-patches/0008-ARM-dts-mvebu-armada-385-turris-omnia-separate-dts-f.patch @@ -0,0 +1,213 @@ +From 03ba17e25dd41d414c00ddde855a36464698d2e1 Mon Sep 17 00:00:00 2001 +From: Tomas Hlavacek <tmshlvck@gmail.com> +Date: Tue, 5 May 2020 20:40:24 +0200 +Subject: [PATCH 08/10] ARM: dts: mvebu: armada-385-turris-omnia: separate dts + for SFP and PHY +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The Turris Omnia board contains dual-personality ethernet NIC eth2 with +two operation modes: 1) SFP cage and 2) metalic 1000BASE-X PHY. +The differential pair carrying SGMII/1000BASE-X of eth2 is wired through +a multiplexor driven by the module-detect signal from the SFP cage. +The pin status can be read through I2C GPIO expander chip in userspace +when the sfp driver module is unloaded and / or in U-Boot prior to the +start of the kernel and the proper DTS file can be selected for the +(floolowing) boot. + +Split DTS for Turris Omnia (that does not have any support for SFP cage) +into three files: + armada-385-turris-omnia.dtsi - common base + armada-385-turris-omnia-sfp.dts - DT with the SFP configuration and +PHY disabled + armada-385-turris-omnia-phy.dts - DT with the PHY configuration and +SFP disabled + +Current DSA driver does not allow multiple CPU ports and Turris Omnia +has two RGMII iterfaces wired between CPU and DSA switch. +Disable the second CPU port until there is a suitable driver to use it. + +Signed-off-by: Tomas Hlavacek <tmshlvck@gmail.com> +Signed-off-by: Marek Behún <marek.behun@nic.cz> +--- + arch/arm/boot/dts/Makefile | 3 +- + .../boot/dts/armada-385-turris-omnia-phy.dts | 22 ++++++++++++ + .../boot/dts/armada-385-turris-omnia-sfp.dts | 23 ++++++++++++ + ...omnia.dts => armada-385-turris-omnia.dtsi} | 35 +++++++++++-------- + 4 files changed, 68 insertions(+), 15 deletions(-) + create mode 100644 arch/arm/boot/dts/armada-385-turris-omnia-phy.dts + create mode 100644 arch/arm/boot/dts/armada-385-turris-omnia-sfp.dts + rename arch/arm/boot/dts/{armada-385-turris-omnia.dts => armada-385-turris-omnia.dtsi} (94%) + +diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile +index 27eec8e670ec..f320ee8e2a00 100644 +--- a/arch/arm/boot/dts/Makefile ++++ b/arch/arm/boot/dts/Makefile +@@ -1495,7 +1495,8 @@ dtb-$(CONFIG_MACH_ARMADA_38X) += \ + armada-385-linksys-rango.dtb \ + armada-385-linksys-shelby.dtb \ + armada-385-synology-ds116.dtb \ +- armada-385-turris-omnia.dtb \ ++ armada-385-turris-omnia-phy.dtb \ ++ armada-385-turris-omnia-sfp.dtb \ + armada-388-clearfog.dtb \ + armada-388-clearfog-base.dtb \ + armada-388-clearfog-pro.dtb \ +diff --git a/arch/arm/boot/dts/armada-385-turris-omnia-phy.dts b/arch/arm/boot/dts/armada-385-turris-omnia-phy.dts +new file mode 100644 +index 000000000000..706f6a2f8065 +--- /dev/null ++++ b/arch/arm/boot/dts/armada-385-turris-omnia-phy.dts +@@ -0,0 +1,22 @@ ++// SPDX-License-Identifier: (GPL-2.0 OR MIT) ++/* ++ * Device Tree file for the Turris Omnia ++ * ++ * Copyright (C) 2016 Uwe Kleine-König <uwe@kleine-koenig.org> ++ * Copyright (C) 2016-2019 Tomas Hlavacek <tmshlvkc@gmail.com> ++ * ++ * Schematic available at https://www.turris.cz/doc/_media/rtrom01-schema.pdf ++ */ ++ ++/dts-v1/; ++ ++#include "armada-385-turris-omnia.dtsi" ++ ++&phy1 { ++ status = "okay"; ++}; ++ ++ð2 { ++ phy-mode = "sgmii"; ++ phy = <&phy1>; ++}; +diff --git a/arch/arm/boot/dts/armada-385-turris-omnia-sfp.dts b/arch/arm/boot/dts/armada-385-turris-omnia-sfp.dts +new file mode 100644 +index 000000000000..b9f2b88834be +--- /dev/null ++++ b/arch/arm/boot/dts/armada-385-turris-omnia-sfp.dts +@@ -0,0 +1,23 @@ ++// SPDX-License-Identifier: (GPL-2.0 OR MIT) ++/* ++ * Device Tree file for the Turris Omnia ++ * ++ * Copyright (C) 2016 Uwe Kleine-König <uwe@kleine-koenig.org> ++ * Copyright (C) 2016-2019 Tomas Hlavacek <tmshlvkc@gmail.com> ++ * ++ * Schematic available at https://www.turris.cz/doc/_media/rtrom01-schema.pdf ++ */ ++ ++/dts-v1/; ++ ++#include "armada-385-turris-omnia.dtsi" ++ ++&sfp { ++ status = "okay"; ++}; ++ ++ð2 { ++ phy-mode = "sgmii"; ++ managed = "in-band-status"; ++ sfp = <&sfp>; ++}; +diff --git a/arch/arm/boot/dts/armada-385-turris-omnia.dts b/arch/arm/boot/dts/armada-385-turris-omnia.dtsi +similarity index 94% +rename from arch/arm/boot/dts/armada-385-turris-omnia.dts +rename to arch/arm/boot/dts/armada-385-turris-omnia.dtsi +index bcced203c612..58e3d86771db 100644 +--- a/arch/arm/boot/dts/armada-385-turris-omnia.dts ++++ b/arch/arm/boot/dts/armada-385-turris-omnia.dtsi +@@ -8,8 +8,6 @@ + * Schematic available at https://www.turris.cz/doc/_media/rtrom01-schema.pdf + */ + +-/dts-v1/; +- + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/input/input.h> + #include <dt-bindings/leds/common.h> +@@ -91,11 +89,11 @@ pcie@3,0 { + sfp: sfp { + compatible = "sff,sfp"; + i2c-bus = <&sfp_i2c>; +- tx-fault-gpios = <&pcawan 0 GPIO_ACTIVE_HIGH>; +- tx-disable-gpios = <&pcawan 1 GPIO_ACTIVE_HIGH>; +- rate-select0-gpios = <&pcawan 2 GPIO_ACTIVE_HIGH>; +- los-gpios = <&pcawan 3 GPIO_ACTIVE_HIGH>; +- mod-def0-gpios = <&pcawan 4 GPIO_ACTIVE_LOW>; ++ tx-fault-gpios = <&sfpgpio 0 GPIO_ACTIVE_HIGH>; ++ tx-disable-gpios = <&sfpgpio 1 GPIO_ACTIVE_HIGH>; ++ rate-select0-gpios = <&sfpgpio 2 GPIO_ACTIVE_HIGH>; ++ los-gpios = <&sfpgpio 3 GPIO_ACTIVE_HIGH>; ++ mod-def0-gpios = <&sfpgpio 4 GPIO_ACTIVE_LOW>; + maximum-power-milliwatt = <3000>; + + /* +@@ -147,7 +145,7 @@ fixed-link { + }; + }; + +-/* WAN port */ ++/* WAN dual-personality port */ + ð2 { + /* + * eth2 is connected via a multiplexor to both the SFP cage and to +@@ -158,9 +156,8 @@ ð2 { + * is present, U-Boot has to enable the sfp node above, remove phy + * handle and add managed = "in-band-status" property. + */ ++ phys = <&comphy5 2>; + status = "okay"; +- phy-mode = "sgmii"; +- phy-handle = <&phy1>; + phys = <&comphy5 2>; + sfp = <&sfp>; + buffer-manager = <&bm>; +@@ -365,7 +362,7 @@ i2c@7 { + #size-cells = <0>; + reg = <7>; + +- pcawan: gpio@71 { ++ sfpgpio: gpio@71 { + /* + * GPIO expander for SFP+ signals and + * and phy irq +@@ -374,7 +371,7 @@ pcawan: gpio@71 { + reg = <0x71>; + + pinctrl-names = "default"; +- pinctrl-0 = <&pcawan_pins>; ++ pinctrl-0 = <&wanint_pins>; + + interrupt-parent = <&gpio1>; + interrupts = <14 IRQ_TYPE_LEVEL_LOW>; +@@ -454,13 +451,23 @@ fixed-link { + }; + }; + +- /* port 6 is connected to eth0 */ ++ ports@6 { ++ reg = <6>; ++ label = "cpu"; ++ ethernet = <ð0>; ++ phy-mode = "rgmii-id"; ++ ++ fixed-link { ++ speed = <1000>; ++ full-duplex; ++ }; ++ }; + }; + }; + }; + + &pinctrl { +- pcawan_pins: pcawan-pins { ++ wanint_pins: wanint-pins { + marvell,pins = "mpp46"; + marvell,function = "gpio"; + }; +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0009-phy-marvell-phy-mvebu-a3700-comphy-Change-2500base-x.patch b/nixos/modules/kernel-patches/0009-phy-marvell-phy-mvebu-a3700-comphy-Change-2500base-x.patch new file mode 100644 index 0000000..bd094d1 --- /dev/null +++ b/nixos/modules/kernel-patches/0009-phy-marvell-phy-mvebu-a3700-comphy-Change-2500base-x.patch @@ -0,0 +1,63 @@ +From dba4f89292a08c3b1ab1bcdb87a0e9b9eb3af0ad Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org> +Date: Wed, 17 Aug 2022 14:35:59 +0200 +Subject: [PATCH 09/10] phy: marvell: phy-mvebu-a3700-comphy: Change 2500base-x + transmit amplitude +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Change transmit amplitude to 1025 mV for 2500base-x mode. + +This fixes issue wherein if the 8b/10b encoded packet contains a long +enough alternating sequence of bits (010101... or 101010...), which +happens if the packet contains a sequence of 'J' or '\xb5' bytes, the +packet may be lost due to FCS error. The probability of loss grows with +the number of 'J's with default transmit amplitude setting - with 114 +'J's the probability is about 50%, with 125 'J's almost 100% of packets +are lost. + +Signed-off-by: Marek Behún <kabel@kernel.org> +--- + drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 18 ++++++++++++++++++ + 1 file changed, 18 insertions(+) + +diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c +index a4d7d9bd100d..4a18f9ca6d25 100644 +--- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c ++++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c +@@ -68,6 +68,12 @@ + #define SPEED_PLL_MASK GENMASK(7, 2) + #define SPEED_PLL_VALUE_16 FIELD_PREP(SPEED_PLL_MASK, 0x10) + ++#define COMPHY_GEN3_SET0 0x0d ++#define Gx_TX_AMP_MASK GENMASK(5, 1) ++#define Gx_TX_AMP_VALUE(x) FIELD_PREP(Gx_TX_AMP_MASK, x) ++#define Gx_TX_AMP_ADJ BIT(6) ++#define Gx_TX_AMP_1025MV (Gx_TX_AMP_VALUE(0x12) | Gx_TX_AMP_ADJ) ++ + #define COMPHY_DIG_LOOPBACK_EN 0x23 + #define SEL_DATA_WIDTH_MASK GENMASK(11, 10) + #define DATA_WIDTH_10BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x0) +@@ -746,6 +752,18 @@ mvebu_a3700_comphy_ethernet_power_on(struct mvebu_a3700_comphy_lane *lane) + comphy_gbe_phy_init(lane, + lane->submode != PHY_INTERFACE_MODE_2500BASEX); + ++ /* ++ * Fix issue wherein a packet may be lost if it contains a long enough ++ * sequence of 'J' or '\xb5' bytes. ++ * This only happens with 2500base-x mode. Fix this by changing transmit ++ * amplitude to 1025 mV. ++ */ ++ if (lane->submode == PHY_INTERFACE_MODE_2500BASEX) { ++ data = Gx_TX_AMP_1025MV; ++ mask = Gx_TX_AMP_MASK | Gx_TX_AMP_ADJ; ++ comphy_lane_reg_set(lane, COMPHY_GEN3_SET0, data, mask); ++ } ++ + /* + * 14. Check the PHY Polarity invert bit + */ +-- +2.37.2 + diff --git a/nixos/modules/kernel-patches/0010-Rename-device-tree-for-Omnia-back-as-that-is-what-is.patch b/nixos/modules/kernel-patches/0010-Rename-device-tree-for-Omnia-back-as-that-is-what-is.patch new file mode 100644 index 0000000..befe186 --- /dev/null +++ b/nixos/modules/kernel-patches/0010-Rename-device-tree-for-Omnia-back-as-that-is-what-is.patch @@ -0,0 +1,32 @@ +From 0aa8841f0a0580490003204fb3cacb5043de6876 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <cynerd@email.cz> +Date: Tue, 27 Sep 2022 10:19:39 +0200 +Subject: [PATCH 10/10] Rename device tree for Omnia back as that is what is + expected by U-Boot + +--- + arch/arm/boot/dts/Makefile | 2 +- + ...ada-385-turris-omnia-phy.dts => armada-385-turris-omnia.dts} | 0 + 2 files changed, 1 insertion(+), 1 deletion(-) + rename arch/arm/boot/dts/{armada-385-turris-omnia-phy.dts => armada-385-turris-omnia.dts} (100%) + +diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile +index f320ee8e2a00..5d82687e3b88 100644 +--- a/arch/arm/boot/dts/Makefile ++++ b/arch/arm/boot/dts/Makefile +@@ -1495,7 +1495,7 @@ dtb-$(CONFIG_MACH_ARMADA_38X) += \ + armada-385-linksys-rango.dtb \ + armada-385-linksys-shelby.dtb \ + armada-385-synology-ds116.dtb \ +- armada-385-turris-omnia-phy.dtb \ ++ armada-385-turris-omnia.dtb \ + armada-385-turris-omnia-sfp.dtb \ + armada-388-clearfog.dtb \ + armada-388-clearfog-base.dtb \ +diff --git a/arch/arm/boot/dts/armada-385-turris-omnia-phy.dts b/arch/arm/boot/dts/armada-385-turris-omnia.dts +similarity index 100% +rename from arch/arm/boot/dts/armada-385-turris-omnia-phy.dts +rename to arch/arm/boot/dts/armada-385-turris-omnia.dts +-- +2.37.2 + diff --git a/nixos/modules/turris-board.nix b/nixos/modules/turris-board.nix index 02b6dae..1c52de0 100644 --- a/nixos/modules/turris-board.nix +++ b/nixos/modules/turris-board.nix @@ -17,12 +17,6 @@ with lib; message = "Turris board has to be specified"; }]; - # Enable flakes for nix as we are using that instead of legacy setup - nix = { - package = pkgs.nixFlakes; - extraOptions = "experimental-features = nix-command flakes"; - }; - environment.systemPackages = with pkgs; [ # As we override the nix package we have to override nixos-rebuild as well (pkgs.nixos-rebuild.override { nix = config.nix.package.out; }) diff --git a/nixos/modules/turris-defaults.nix b/nixos/modules/turris-defaults.nix index bba3d18..84b2963 100644 --- a/nixos/modules/turris-defaults.nix +++ b/nixos/modules/turris-defaults.nix @@ -64,7 +64,7 @@ in { # The additional administration packages environment.systemPackages = with pkgs; [ - htop + htop iw ]; # No need for installer tools in standard system diff --git a/nixos/modules/turris-mox-support.nix b/nixos/modules/turris-mox-support.nix index 9596b15..578e467 100644 --- a/nixos/modules/turris-mox-support.nix +++ b/nixos/modules/turris-mox-support.nix @@ -10,15 +10,6 @@ with lib; "earlycon=ar3700_uart,0xd0012000" "console=ttyMV0,115200" "pcie_aspm=off" # Fix for crashes due to SError Interrupt on ath10k load ]; - # Custom kernel config - boot.kernelPatches = [{ - name = "rwtm"; - patch = null; - extraConfig = '' - TURRIS_MOX_RWTM y - ARMADA_37XX_RWTM_MBOX y - ''; - }]; # The additional administration packages environment.systemPackages = with pkgs; [ diff --git a/nixos/modules/turris-omnia-support.nix b/nixos/modules/turris-omnia-support.nix index b68affc..2479f34 100644 --- a/nixos/modules/turris-omnia-support.nix +++ b/nixos/modules/turris-omnia-support.nix @@ -9,15 +9,6 @@ with lib; boot.kernelParams = [ "earlyprintk" "console=ttyS0,115200" ]; - # Custom kernel config - boot.kernelPatches = [{ - name = "omnia"; - patch = null; - extraConfig = '' - LEDS_CLASS_MULTICOLOR y - LEDS_TURRIS_OMNIA y - ''; - }]; # The additional administration packages environment.systemPackages = with pkgs; [ |