Skip to contentSkip to conversation

Add restart commands for PM8150

PATCH Superseded Elliot Berman 1 participant 5 messages Jul 31, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Add restart commands for PM8150

PM8150 uses reboot-mode framework to set magic values for bootloader to read during next boot. dm-verity wants to use "dm-verity device corrupted" [1] as the restart command, however the reboot-mode framework does not support spaces in the command line as devicetree property names cannot have spaces. This patch series adds two new optional array properties to reboot-mode framework:
reboot-mode-names and reboot-mode-magic. The arrays supply the commands and magic values, respectively.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/md/dm-verity-target.c?h=v5.5#n255

Elliot Berman (4):
dt-bindings: power: reset: Convert reboot-mode to YAML
dt-bindings: power: reset: Add alternate reboot mode format
power: reset: Add support for reboot mode alternate properties
arm64: dts: qcom: pm8150: Add reboot magic

 .../bindings/power/reset/reboot-mode.txt           | 25 ---------
 .../bindings/power/reset/reboot-mode.yaml          | 64 ++++++++++++++++++++++
 arch/arm64/boot/dts/qcom/pm8150.dtsi               |  5 ++
 drivers/power/reset/reboot-mode.c                  | 42 +++++++++++++-
 4 files changed, 110 insertions(+), 26 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/power/reset/reboot-mode.txt
 create mode 100644 Documentation/devicetree/bindings/power/reset/reboot-mode.yaml
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH 1/4 dt-bindings: power: reset: Convert reboot-mode to YAML

Convert reboot-mode bindings to YAML.

---
 .../bindings/power/reset/reboot-mode.txt           | 25 ------------
 .../bindings/power/reset/reboot-mode.yaml          | 47 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 25 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/power/reset/reboot-mode.txt
 create mode 100644 Documentation/devicetree/bindings/power/reset/reboot-mode.yaml
Documentation/devicetree/bindings/power/reset/reboot-mode.txt deleted +0 -25
deleted file mode 100644
index de34f27..0000000
@@ -1,25 +0,0 @@
-Generic reboot mode core map driver
-
-This driver get reboot mode arguments and call the write
-interface to store the magic value in special register
-or ram. Then the bootloader can read it and take different
-action according to the argument stored.
-
-All mode properties are vendor specific, it is a indication to tell
-the bootloader what to do when the system reboots, and should be named
-as mode-xxx = <magic> (xxx is mode name, magic should be a none-zero value).
-
-For example modes common on Android platform:
-- mode-normal: Normal reboot mode, system reboot with command "reboot".
-- mode-recovery: Android Recovery mode, it is a mode to format the device or update a new image.
-- mode-bootloader: Android fastboot mode, it's a mode to re-flash partitions on the Android based device.
-- mode-loader: A bootloader mode, it's a mode used to download image on Rockchip platform,
-	       usually used in development.
-
-Example:
-	reboot-mode {
-		mode-normal = <BOOT_NORMAL>;
-		mode-recovery = <BOOT_RECOVERY>;
-		mode-bootloader = <BOOT_FASTBOOT>;
-		mode-loader = <BOOT_BL_DOWNLOAD>;
-	}
Documentation/devicetree/bindings/power/reset/reboot-mode.yaml new file +47 -0

47 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw

PATCH 2/4 dt-bindings: power: reset: Add alternate reboot mode format

In reply to Elliot Berman

Current reboot-mode device tree schema does not support reboot commands with spaces in them [1]. Add an optional new node "reboot-mode-names" and "reboot-mode-magic" which add an array of strings and u32s, respectively which would permit any string in this framework.

[1]:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/md/dm-verity-target.c?h=v5.5#n255

---
 .../devicetree/bindings/power/reset/reboot-mode.yaml    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/power/reset/reboot-mode.yaml +17 -0
index a6c9102..4ea6b33 100644
@@ -19,6 +19,9 @@ description: |
   the bootloader what to do when the system reboots, and should be named
   as mode-xxx = <magic> (xxx is mode name, magic should be a non-zero value).
 
+  reboot-mode-magic and reboot-mode-names may be used in addition/instead of
+  mode-xxx style.
+
   For example, modes common Android platform are:
     - normal: Normal reboot mode, system reboot with command "reboot".
     - recovery: Android Recovery mode, it is a mode to format the device or update a new image.
@@ -32,6 +35,14 @@ properties:
       description: |
         Default value to set on a reboot if no command was provided.
 
+  reboot-mode-names:
+    $ref: /schemas/types.yaml#/definitions/string-array
+    description: List of reboot commands, paired with reboot-mode-magic by index
+
+  reboot-mode-magic:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    description: List of reboot magic, paired with reboot-mode-names by index
+
 patternProperties:
   "^mode-.*$":
     $ref: /schemas/types.yaml#/definitions/uint32
@@ -44,4 +55,10 @@ examples:
       mode-bootloader = <2>;
       mode-loader = <3>;
     };
+
+  - |
+    reboot-mode {
+      reboot-mode-names = "normal", "bootloader", "dm-verity device corrupted";
+      reboot-mode-magic = <0x0>, <0x1>, <0xf>;
+    };
 ...
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

PATCH 3/4 power: reset: Add support for reboot mode alternate properties

In reply to Elliot Berman

Reboot mode driver does not currently support reboot commands with spaces in them [1]. Add an optional new node "reboot-mode-names" and "reboot-mode-magic" which add an array of strings and u32s, respectively which would permit any string in this framework.

---
 drivers/power/reset/reboot-mode.c | 42 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
drivers/power/reset/reboot-mode.c +41 -1
index b4076b1..363734d 100644
@@ -64,8 +64,9 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
 	struct mode_info *info;
 	struct property *prop;
 	struct device_node *np = reboot->dev->of_node;
+	const char *mode_name;
 	size_t len = strlen(PREFIX);
-	int ret;
+	int ret, count, i;
 
 	INIT_LIST_HEAD(&reboot->head);
 
@@ -101,6 +102,45 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
 		list_add_tail(&info->list, &reboot->head);
 	}
 
+	count = of_property_count_u32_elems(np, "reboot-mode-magic");
+	for (i = 0; i < count; i++) {
+		info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
+		if (!info) {
+			ret = -ENOMEM;
+			goto error;
+		}
+
+		if (of_property_read_string_index(np, "reboot-mode-names", i,
+						  &mode_name)) {
+			dev_err(reboot->dev, "unable to read reboot-mode-names[%d]\n",
+				i);
+			ret = -EINVAL;
+			goto error;
+		}
+		info->mode = kstrdup_const(mode_name, GFP_KERNEL);
+		if (!info->mode) {
+			ret = -ENOMEM;
+			goto error;
+		} else if (info->mode[0] == '\0') {
+			dev_err(reboot->dev, "invalid reboot-mode-names[%d]: too short!\n",
+				i);
+			kfree_const(info->mode);
+			ret = -EINVAL;
+			goto error;
+		}
+
+		if (of_property_read_u32_index(np, "reboot-mode-magic", i,
+					       &info->magic)) {
+			dev_err(reboot->dev, "unable to read reboot-mode-magic[%d]\n",
+				i);
+			kfree_const(info->mode);
+			ret = -EINVAL;
+			goto error;
+		}
+
+		list_add_tail(&info->list, &reboot->head);
+	}
+
 	reboot->reboot_notifier.notifier_call = reboot_mode_notify;
 	register_reboot_notifier(&reboot->reboot_notifier);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

PATCH 4/4 arm64: dts: qcom: pm8150: Add reboot magic

In reply to Elliot Berman

Add reboot command magic values for pon device.

---
 arch/arm64/boot/dts/qcom/pm8150.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/boot/dts/qcom/pm8150.dtsi +5 -0
index 1b64069..afd6231 100644
@@ -50,6 +50,11 @@
 		pon: power-on@800 {
 			compatible = "qcom,pm8916-pon";
 			reg = <0x0800>;
+
+			reboot-mode-names = "bootloader", "recovery",
+					    "dm-verity device corrupted";
+			reboot-mode-magic = <0x1>, <0x2>, <0x4>;
+
 			pwrkey {
 				compatible = "qcom,pm8941-pwrkey";
 				interrupts = <0x0 0x8 0x0 IRQ_TYPE_EDGE_BOTH>;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project