2021-05-19 19:28:50

by Emmanuel Gil Peyrot

[permalink] [raw]
Subject: [PATCH v2 0/4] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP

The OTP is a read-only memory area which contains various keys and
signatures used to decrypt, encrypt or verify various pieces of storage.

Its size depends on the console, it is 128 bytes on the Wii and
1024 bytes on the Wii U (split into eight 128 bytes banks).

It can be used directly by writing into one register and reading from
the other one, without any additional synchronisation.

This series has only been tested on the Wii U so far, using the
downstream 4.19 branch from linux-wiiu[1], but it should also work on
the Wii on mainline.

[1] https://gitlab.com/linux-wiiu/linux-wiiu

Changes since v1:
- Fixed the commit messages so they can be accepted by other email
servers, sorry about that.

Emmanuel Gil Peyrot (4):
nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP
dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support
powerpc: wii.dts: Expose the OTP on this platform
powerpc: wii_defconfig: Enable OTP by default

.../bindings/nvmem/nintendo-otp.txt | 14 +++
arch/powerpc/boot/dts/wii.dts | 5 +
arch/powerpc/configs/wii_defconfig | 1 +
drivers/nvmem/Kconfig | 11 ++
drivers/nvmem/Makefile | 2 +
drivers/nvmem/nintendo-otp.c | 115 ++++++++++++++++++
6 files changed, 148 insertions(+)
create mode 100644 Documentation/devicetree/bindings/nvmem/nintendo-otp.txt
create mode 100644 drivers/nvmem/nintendo-otp.c

--
2.31.1



2021-07-01 23:24:24

by Emmanuel Gil Peyrot

[permalink] [raw]
Subject: [PATCH v3 0/5] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP

The OTP is a read-only memory area which contains various keys and
signatures used to decrypt, encrypt or verify various pieces of storage.

Its size depends on the console, it is 128 bytes on the Wii and
1024 bytes on the Wii U (split into eight 128 bytes banks).

It can be used directly by writing into one register and reading from
the other one, without any additional synchronisation.

This series has been tested on both the Wii U (using my downstream
master-wiiu branch[1]), as well as on the Wii on mainline.

[1] https://gitlab.com/linkmauve/linux-wiiu/-/commits/master-wiiu

Changes since v1:
- Fixed the commit messages so they can be accepted by other email
servers, sorry about that.

Changes since v2:
- Switched the dt binding documentation to YAML.
- Used more obvious register arithmetic, and tested that gcc (at -O1 and
above) outputs the exact same rlwinm instructions for them.
- Use more #defines to make the code easier to read.
- Include some links to the reversed documentation.
- Avoid overlapping dt regions by changing the existing control@d800100
node to end before the OTP registers, with some bigger dt refactoring
left for a future series.

Emmanuel Gil Peyrot (5):
nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP
dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support
powerpc: wii.dts: Reduce the size of the control area
powerpc: wii.dts: Expose the OTP on this platform
powerpc: wii_defconfig: Enable OTP by default

.../bindings/nvmem/nintendo-otp.yaml | 44 +++++++
arch/powerpc/boot/dts/wii.dts | 13 +-
arch/powerpc/configs/wii_defconfig | 1 +
drivers/nvmem/Kconfig | 11 ++
drivers/nvmem/Makefile | 2 +
drivers/nvmem/nintendo-otp.c | 124 ++++++++++++++++++
6 files changed, 194 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml
create mode 100644 drivers/nvmem/nintendo-otp.c

--
2.32.0

2021-08-01 07:39:32

by Emmanuel Gil Peyrot

[permalink] [raw]
Subject: [PATCH v4 0/5] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP

The OTP is a read-only memory area which contains various keys and
signatures used to decrypt, encrypt or verify various pieces of storage.

Its size depends on the console, it is 128 bytes on the Wii and
1024 bytes on the Wii U (split into eight 128 bytes banks).

It can be used directly by writing into one register and reading from
the other one, without any additional synchronisation.

This series has been tested on both the Wii U (using my downstream
master-wiiu branch[1]), as well as on the Wii on mainline.

[1] https://gitlab.com/linkmauve/linux-wiiu/-/commits/master-wiiu

Changes since v1:
- Fixed the commit messages so they can be accepted by other email
servers, sorry about that.

Changes since v2:
- Switched the dt binding documentation to YAML.
- Used more obvious register arithmetic, and tested that gcc (at -O1 and
above) outputs the exact same rlwinm instructions for them.
- Use more #defines to make the code easier to read.
- Include some links to the reversed documentation.
- Avoid overlapping dt regions by changing the existing control@d800100
node to end before the OTP registers, with some bigger dt refactoring
left for a future series.

Changes since v3:
- Relicense the dt-binding documentation under GPLv2-only or
BSD-2-clauses.

Emmanuel Gil Peyrot (5):
nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP
dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support
powerpc: wii.dts: Reduce the size of the control area
powerpc: wii.dts: Expose the OTP on this platform
powerpc: wii_defconfig: Enable OTP by default

.../bindings/nvmem/nintendo-otp.yaml | 44 +++++++
arch/powerpc/boot/dts/wii.dts | 13 +-
arch/powerpc/configs/wii_defconfig | 1 +
drivers/nvmem/Kconfig | 11 ++
drivers/nvmem/Makefile | 2 +
drivers/nvmem/nintendo-otp.c | 124 ++++++++++++++++++
6 files changed, 194 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml
create mode 100644 drivers/nvmem/nintendo-otp.c

--
2.32.0


2021-08-01 07:40:05

by Emmanuel Gil Peyrot

[permalink] [raw]
Subject: [PATCH v4 4/5] powerpc: wii.dts: Expose the OTP on this platform

This can be used by the newly-added nintendo-otp nvmem module.

Signed-off-by: Emmanuel Gil Peyrot <[email protected]>
---
arch/powerpc/boot/dts/wii.dts | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/boot/dts/wii.dts b/arch/powerpc/boot/dts/wii.dts
index c5fb54f8cc02..e9c945b123c6 100644
--- a/arch/powerpc/boot/dts/wii.dts
+++ b/arch/powerpc/boot/dts/wii.dts
@@ -219,12 +219,17 @@ control@d800100 {
/*
* Both the address and length are wrong, according to
* Wiibrew this should be <0x0d800000 0x400>, but it
- * requires refactoring the PIC1 and GPIO nodes before
- * changing that.
+ * requires refactoring the PIC1, GPIO and OTP nodes
+ * before changing that.
*/
reg = <0x0d800100 0xa0>;
};

+ otp@d8001ec {
+ compatible = "nintendo,hollywood-otp";
+ reg = <0x0d8001ec 0x8>;
+ };
+
disk@d806000 {
compatible = "nintendo,hollywood-di";
reg = <0x0d806000 0x40>;
--
2.32.0


2021-08-01 07:40:53

by Emmanuel Gil Peyrot

[permalink] [raw]
Subject: [PATCH v4 3/5] powerpc: wii.dts: Reduce the size of the control area

This is wrong, but needed in order to avoid overlapping ranges with the
OTP area added in the next commit. A refactor of this part of the
device tree is needed: according to Wiibrew[1], this area starts at
0x0d800000 and spans 0x400 bytes (that is, 0x100 32-bit registers),
encompassing PIC and GPIO registers, amongst the ones already exposed in
this device tree, which should become children of the control@d800000
node.

[1] https://wiibrew.org/wiki/Hardware/Hollywood_Registers

Signed-off-by: Emmanuel Gil Peyrot <[email protected]>
---
arch/powerpc/boot/dts/wii.dts | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/boot/dts/wii.dts b/arch/powerpc/boot/dts/wii.dts
index aaa381da1906..c5fb54f8cc02 100644
--- a/arch/powerpc/boot/dts/wii.dts
+++ b/arch/powerpc/boot/dts/wii.dts
@@ -216,7 +216,13 @@ AVE: audio-video-encoder@70 {

control@d800100 {
compatible = "nintendo,hollywood-control";
- reg = <0x0d800100 0x300>;
+ /*
+ * Both the address and length are wrong, according to
+ * Wiibrew this should be <0x0d800000 0x400>, but it
+ * requires refactoring the PIC1 and GPIO nodes before
+ * changing that.
+ */
+ reg = <0x0d800100 0xa0>;
};

disk@d806000 {
--
2.32.0


2021-08-01 07:40:57

by Emmanuel Gil Peyrot

[permalink] [raw]
Subject: [PATCH v4 5/5] powerpc: wii_defconfig: Enable OTP by default

This selects the nintendo-otp module when building for this platform.

Signed-off-by: Emmanuel Gil Peyrot <[email protected]>
---
arch/powerpc/configs/wii_defconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/configs/wii_defconfig b/arch/powerpc/configs/wii_defconfig
index 379c171f3ddd..a0c45bf2bfb1 100644
--- a/arch/powerpc/configs/wii_defconfig
+++ b/arch/powerpc/configs/wii_defconfig
@@ -99,6 +99,7 @@ CONFIG_LEDS_TRIGGER_HEARTBEAT=y
CONFIG_LEDS_TRIGGER_PANIC=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_GENERIC=y
+CONFIG_NVMEM_NINTENDO_OTP=y
CONFIG_EXT2_FS=y
CONFIG_EXT4_FS=y
CONFIG_FUSE_FS=m
--
2.32.0


2021-08-01 07:41:19

by Emmanuel Gil Peyrot

[permalink] [raw]
Subject: [PATCH v4 2/5] dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support

Both of these consoles use the exact same two registers, even at the
same address, but the Wii U has eight banks of 128 bytes memory while
the Wii only has one, hence the two compatible strings.

Signed-off-by: Emmanuel Gil Peyrot <[email protected]>
---
.../bindings/nvmem/nintendo-otp.yaml | 44 +++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml

diff --git a/Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml b/Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml
new file mode 100644
index 000000000000..dbe4ffdd644c
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/nintendo-otp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nintendo Wii and Wii U OTP Device Tree Bindings
+
+description: |
+ This binding represents the OTP memory as found on a Nintendo Wii or Wii U,
+ which contains common and per-console keys, signatures and related data
+ required to access peripherals.
+
+ See https://wiiubrew.org/wiki/Hardware/OTP
+
+maintainers:
+ - Emmanuel Gil Peyrot <[email protected]>
+
+allOf:
+ - $ref: "nvmem.yaml#"
+
+properties:
+ compatible:
+ enum:
+ - nintendo,hollywood-otp
+ - nintendo,latte-otp
+
+ reg:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ otp@d8001ec {
+ compatible = "nintendo,latte-otp";
+ reg = <0x0d8001ec 0x8>;
+ };
+
+...
--
2.32.0


2021-08-07 00:14:32

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v4 2/5] dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support

On Sun, 01 Aug 2021 09:38:19 +0200, Emmanuel Gil Peyrot wrote:
> Both of these consoles use the exact same two registers, even at the
> same address, but the Wii?U has eight banks of 128?bytes memory while
> the Wii only has one, hence the two compatible strings.
>
> Signed-off-by: Emmanuel Gil Peyrot <[email protected]>
> ---
> .../bindings/nvmem/nintendo-otp.yaml | 44 +++++++++++++++++++
> 1 file changed, 44 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml
>

Reviewed-by: Rob Herring <[email protected]>

2021-08-10 16:23:37

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH v4 0/5] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP



On 01/08/2021 08:38, Emmanuel Gil Peyrot wrote:
> The OTP is a read-only memory area which contains various keys and
> signatures used to decrypt, encrypt or verify various pieces of storage.
>
> Its size depends on the console, it is 128 bytes on the Wii and
> 1024 bytes on the Wii U (split into eight 128 bytes banks).
>
> It can be used directly by writing into one register and reading from
> the other one, without any additional synchronisation.
>
> This series has been tested on both the Wii U (using my downstream
> master-wiiu branch[1]), as well as on the Wii on mainline.
>
> [1] https://gitlab.com/linkmauve/linux-wiiu/-/commits/master-wiiu
>
> Changes since v1:
> - Fixed the commit messages so they can be accepted by other email
> servers, sorry about that.
>
> Changes since v2:
> - Switched the dt binding documentation to YAML.
> - Used more obvious register arithmetic, and tested that gcc (at -O1 and
> above) outputs the exact same rlwinm instructions for them.
> - Use more #defines to make the code easier to read.
> - Include some links to the reversed documentation.
> - Avoid overlapping dt regions by changing the existing control@d800100
> node to end before the OTP registers, with some bigger dt refactoring
> left for a future series.
>
> Changes since v3:
> - Relicense the dt-binding documentation under GPLv2-only or
> BSD-2-clauses.
>
> Emmanuel Gil Peyrot (5):
> nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP
> dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support


Applied 1/5 and 2/5 to nvmem next,
rest of the patches should go via powerpc dts tree.

thanks,
--srini
> powerpc: wii.dts: Reduce the size of the control area
> powerpc: wii.dts: Expose the OTP on this platform
> powerpc: wii_defconfig: Enable OTP by default
>
> .../bindings/nvmem/nintendo-otp.yaml | 44 +++++++
> arch/powerpc/boot/dts/wii.dts | 13 +-
> arch/powerpc/configs/wii_defconfig | 1 +
> drivers/nvmem/Kconfig | 11 ++
> drivers/nvmem/Makefile | 2 +
> drivers/nvmem/nintendo-otp.c | 124 ++++++++++++++++++
> 6 files changed, 194 insertions(+), 1 deletion(-)
> create mode 100644 Documentation/devicetree/bindings/nvmem/nintendo-otp.yaml
> create mode 100644 drivers/nvmem/nintendo-otp.c
>