Skip to contentSkip to conversation

ATF and OP-TEE Firewalling for K3 devices.

RFC PATCH Superseded Manorit Chawdhry 3 participants 19 messages Sep 26, 2023 – Oct 4, 2023 Arm (32-bit)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover ATF and OP-TEE Firewalling for K3 devices.

K3 devices have firewalls that are used to prevent illegal accesses to memory regions that are deemed secure. The series prevents the illegal accesses to ATF and OP-TEE regions that are present in different K3 devices.

AM62AX and AM64X are currently in hold due to some firewall configurations that our System Controller (TIFS) needs to handle.

---
Changes in v2:

Andrew:
- Make the firewall DTS more readable with CONSTANTS

Neha:
- Move GetHexOctet to dtoc for common usage
- Update the documentation in ti-secure
- s/indentifier/identifier/
- Add firewall binman test

- Remove slave firewall multiple background regions
( Single firewall region works fine )
- Add a check in the subnodes to check for the node.name 'firewall'
- Change firewall indexing with id and region number so that it is easy
to purge out firewalls and we don't need to redo the numbering.
- Add information for all the firewalls.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
Manorit Chawdhry (8):
dtoc: openssl: Add GetHexOctet method
binman: ti-secure: Add support for firewalling entities
binman: ftest: Add test for ti-secure firewall node
binman: k3: add k3-security.h and include it in k3-binman.dtsi
binman: j721e: Add firewall configurations for atf
binman: am62x: Add firewalling configurations
binman: j721s2: Add firewall configurations
binman: j7200: Add firewall configurations

 arch/arm/dts/k3-am625-sk-binman.dtsi         |  49 +++++++
 arch/arm/dts/k3-binman.dtsi                  |   2 +
 arch/arm/dts/k3-j7200-binman.dtsi            | 137 ++++++++++++++++++
 arch/arm/dts/k3-j721e-binman.dtsi            | 183 ++++++++++++++++++++++++
 arch/arm/dts/k3-j721s2-binman.dtsi           | 206 +++++++++++++++++++++++++++
 arch/arm/dts/k3-security.h                   |  58 ++++++++
 tools/binman/btool/openssl.py                |  16 ++-
 tools/binman/etype/ti_secure.py              |  85 +++++++++++
 tools/binman/etype/x509_cert.py              |   3 +-
 tools/binman/ftest.py                        |  12 ++
 tools/binman/test/311_ti_secure_firewall.dts |  28 ++++
 tools/dtoc/fdt_util.py                       |  20 +++
 12 files changed, 796 insertions(+), 3 deletions(-)

---
base-commit: 2fe4b54556ea6271237b35de68dc458bfceab94c
change-id: 20230724-binman-firewalling-65ecdb23ec0a

Best regards,

Signature · 1 line
Manorit Chawdhry <[email protected]>
#1 lore raw

RFC PATCH v2 1/8 dtoc: openssl: Add GetHexOctet method

HexOctet format is used by openssl for FORMAT:HEX,OCT property in x509 certificates. Add a helper function to extract the integer numbers in HEX,OCT format to pass to openssl directly.

---
 tools/dtoc/fdt_util.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/dtoc/fdt_util.py +20 -0
index f1f70568cfef..d51dbf5633d0 100644
@@ -100,6 +100,26 @@ def EnsureCompiled(fname, tmpdir=None, capture_stderr=False):
     command.run(dtc, *args, capture_stderr=capture_stderr)
     return dtb_output
 
+def GetHexOctet(node, propname, default=None):
+    """Get an integer from a property in hex octet form required by openssl
+
+    Args:
+        node: Node object to read from
+        propname: property name to read
+        default: Default value to use if the node/property do not exist
+
+    Returns:
+        Integer value read as a String in Hex Octet Form
+    """
+    prop = node.props.get(propname)
+    if not isinstance(prop.value, list) or len(prop.value) != 2:
+        value = GetInt(node, propname)
+    elif isinstance(prop.value, list) and len(prop.value) == 2:
+        value = GetInt64(node, propname)
+
+    hex_value = '%x' % (value)
+    return ('0' * (len(hex_value) & 1)) + hex_value
+
 def GetInt(node, propname, default=None):
     """Get an integer from a property
 
Signature · 1 line
2.41.0
#2 lore raw

Re: [RFC PATCH v2 1/8] dtoc: openssl: Add GetHexOctet method

Hi Manorit,

Quoted 15 lines · Manorit Chawdhry

HexOctet format is used by openssl for FORMAT:HEX,OCT property in x509 certificates. Add a helper function to extract the integer numbers in HEX,OCT format to pass to openssl directly.

---
 tools/dtoc/fdt_util.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/dtoc/fdt_util.py +0 -0
index f1f70568cfef..d51dbf5633d0 100644

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 103

Quoted 4 lines
tools/dtoc/fdt_util.py +1 -0
@@ -100,6 +100,26 @@ def EnsureCompiled(fname, tmpdir=None, capture_stderr=False):
     command.run(dtc, *args, capture_stderr=capture_stderr)
     return dtb_output
 
+def GetHexOctet(node, propname, default=None):

What is a hex octet?

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 105

Quoted 2 lines
tools/dtoc/fdt_util.py +2 -0
+    """Get an integer from a property in hex octet form required by openssl
+

You should mention what size property is permitted.

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 118

Quoted 13 lines
tools/dtoc/fdt_util.py +13 -0
+    Args:
+        node: Node object to read from
+        propname: property name to read
+        default: Default value to use if the node/property do not exist
+
+    Returns:
+        Integer value read as a String in Hex Octet Form
+    """
+    prop = node.props.get(propname)
+    if not isinstance(prop.value, list) or len(prop.value) != 2:
+        value = GetInt(node, propname)
+    elif isinstance(prop.value, list) and len(prop.value) == 2:
+        value = GetInt64(node, propname)

What if it is neither of those?

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 121

Quoted 3 lines
tools/dtoc/fdt_util.py +3 -0
+
+    hex_value = '%x' % (value)
+    return ('0' * (len(hex_value) & 1)) + hex_value

Can you do:

return f'{value:02x}'

?

Quoted 8 lines
tools/dtoc/fdt_util.py +1 -1
+
 def GetInt(node, propname, default=None):
     """Get an integer from a property
 
 
--

2.41.0

#3 lore raw

Re: [RFC PATCH v2 1/8] dtoc: openssl: Add GetHexOctet method

Hi Simon,

Quoted 21 lines · Simon Glass

Hi Manorit,

Quoted 18 lines · Manorit Chawdhry

HexOctet format is used by openssl for FORMAT:HEX,OCT property in x509 certificates. Add a helper function to extract the integer numbers in HEX,OCT format to pass to openssl directly.

---
 tools/dtoc/fdt_util.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/dtoc/fdt_util.py +0 -0
index f1f70568cfef..d51dbf5633d0 100644
@@ -100,6 +100,26 @@ def EnsureCompiled(fname, tmpdir=None, capture_stderr=False):
     command.run(dtc, *args, capture_stderr=capture_stderr)
     return dtb_output
 
Quoted 4 lines

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 103

Quoted 1 line
tools/dtoc/fdt_util.py +1 -0
+def GetHexOctet(node, propname, default=None):

What is a hex octet?

It is actually a Hex number in Octet form, basically using 0x0a instead of 0xa type of thing.

OpenSSL has complained when we use FORMAT:HEX,OCT:0 type of string instead of FORMAT:HEX,OCT:00. Tbvh I still haven't been able to find a clear documentation for this but this is what I have been able to figure out based on my tests.

Quoted 21 lines

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 105

Quoted 2 lines
tools/dtoc/fdt_util.py +2 -0
+    """Get an integer from a property in hex octet form required by openssl
+

You should mention what size property is permitted.

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 118

Quoted 13 lines
tools/dtoc/fdt_util.py +13 -0
+    Args:
+        node: Node object to read from
+        propname: property name to read
+        default: Default value to use if the node/property do not exist
+
+    Returns:
+        Integer value read as a String in Hex Octet Form
+    """
+    prop = node.props.get(propname)
+    if not isinstance(prop.value, list) or len(prop.value) != 2:
+        value = GetInt(node, propname)
+    elif isinstance(prop.value, list) and len(prop.value) == 2:
+        value = GetInt64(node, propname)

What if it is neither of those?

Quoted 8 lines

tools/dtoc/fdt_util.py def EnsureCompiled(fname, tmpdir=None, capture_stderr=False): · line 121

Quoted 3 lines
tools/dtoc/fdt_util.py +3 -0
+
+    hex_value = '%x' % (value)
+    return ('0' * (len(hex_value) & 1)) + hex_value

Can you do:

return f'{value:02x}'

With the following suggestion I don't think I need the patch at all anymore given that no one else seems to be requiring this HEX,OCT just yet and am still in the process of finding a clear documentation for it.

Will be dropping that patch after testing if not required to be generic. Thanks!

Regards,
Manorit

Quoted 11 lines

?

Quoted 8 lines
tools/dtoc/fdt_util.py +1 -1
+
 def GetInt(node, propname, default=None):
     """Get an integer from a property
 
 
--

2.41.0

#4 lore raw

RFC PATCH v2 2/8 binman: ti-secure: Add support for firewalling entities

In reply to Manorit Chawdhry

We can now firewall entities while loading them through our secure entity TIFS, the required information should be present in the certificate that is being parsed by TIFS.

The following commit adds the support to enable the certificates to be generated if the firewall configurations are present in the binman dtsi nodes.

---
 tools/binman/btool/openssl.py   | 16 +++++++-
 tools/binman/etype/ti_secure.py | 85 +++++++++++++++++++++++++++++++++++++++++
 tools/binman/etype/x509_cert.py |  3 +-
 3 files changed, 101 insertions(+), 3 deletions(-)
tools/binman/btool/openssl.py +14 -2
index aad3b61ae27c..dff439df211f 100644
@@ -82,7 +82,7 @@ imageSize              = INTEGER:{len(indata)}
         return self.run_cmd(*args)
 
     def x509_cert_sysfw(self, cert_fname, input_fname, key_fname, sw_rev,
-                  config_fname, req_dist_name_dict):
+                  config_fname, req_dist_name_dict, firewall_cert_data):
         """Create a certificate to be booted by system firmware
 
         Args:
@@ -94,6 +94,13 @@ imageSize              = INTEGER:{len(indata)}
             req_dist_name_dict (dict): Dictionary containing key-value pairs of
             req_distinguished_name section extensions, must contain extensions for
             C, ST, L, O, OU, CN and emailAddress
+            firewall_cert_data (dict):
+              - auth_in_place (int): The Priv ID for copying as the
+                specific host in firewall protected region
+              - num_firewalls (int): The number of firewalls in the
+                extended certificate
+              - certificate (str): Extended firewall certificate with
+                the information for the firewall configurations.
 
         Returns:
             str: Tool output
@@ -121,6 +128,7 @@ basicConstraints       = CA:true
 1.3.6.1.4.1.294.1.3    = ASN1:SEQUENCE:swrv
 1.3.6.1.4.1.294.1.34   = ASN1:SEQUENCE:sysfw_image_integrity
 1.3.6.1.4.1.294.1.35   = ASN1:SEQUENCE:sysfw_image_load
+1.3.6.1.4.1.294.1.37   = ASN1:SEQUENCE:firewall
 
 [ swrv ]
 swrv = INTEGER:{sw_rev}
@@ -132,7 +140,11 @@ imageSize              = INTEGER:{len(indata)}
 
 [ sysfw_image_load ]
 destAddr = FORMAT:HEX,OCT:00000000
-authInPlace = INTEGER:2
+authInPlace = INTEGER:{hex(firewall_cert_data['auth_in_place'])}
+
+[ firewall ]
+numFirewallRegions = INTEGER:{firewall_cert_data['num_firewalls']}
+{firewall_cert_data['certificate']}
 ''', file=outf)
         args = ['req', '-new', '-x509', '-key', key_fname, '-nodes',
                 '-outform', 'DER', '-out', cert_fname, '-config', config_fname,
tools/binman/etype/ti_secure.py +85 -0

123 lines not on this page · raw message

tools/binman/etype/x509_cert.py +2 -1
index d028cfe38cd9..9e1cf479023b 100644
@@ -98,7 +98,8 @@ class Entry_x509_cert(Entry_collection):
                 key_fname=self.key_fname,
                 config_fname=config_fname,
                 sw_rev=self.sw_rev,
-                req_dist_name_dict=self.req_dist_name)
+                req_dist_name_dict=self.req_dist_name,
+                firewall_cert_data=self.firewall_cert_data)
         elif type == 'rom':
             stdout = self.openssl.x509_cert_rom(
                 cert_fname=output_fname,
Signature · 1 line
2.41.0
#5 lore raw

Re: [RFC PATCH v2 2/8] binman: ti-secure: Add support for firewalling entities

Hi Manorit,

Quoted 9 lines · Manorit Chawdhry

We can now firewall entities while loading them through our secure entity TIFS, the required information should be present in the certificate that is being parsed by TIFS.

The following commit adds the support to enable the certificates to be generated if the firewall configurations are present in the binman dtsi nodes.

Quoted 7 lines
---
 tools/binman/btool/openssl.py   | 16 +++++++-
 tools/binman/etype/ti_secure.py | 85 +++++++++++++++++++++++++++++++++++++++++
 tools/binman/etype/x509_cert.py |  3 +-
 3 files changed, 101 insertions(+), 3 deletions(-)

Please do check that you have 100% test coverage here (binman test -T)

Regards,
Simon

#6 lore raw

Re: [RFC PATCH v2 2/8] binman: ti-secure: Add support for firewalling entities

Hi Simon,

Quoted 20 lines · Simon Glass

Hi Manorit,

Quoted 9 lines · Manorit Chawdhry

We can now firewall entities while loading them through our secure entity TIFS, the required information should be present in the certificate that is being parsed by TIFS.

The following commit adds the support to enable the certificates to be generated if the firewall configurations are present in the binman dtsi nodes.

Quoted 7 lines
---
 tools/binman/btool/openssl.py   | 16 +++++++-
 tools/binman/etype/ti_secure.py | 85 +++++++++++++++++++++++++++++++++++++++++
 tools/binman/etype/x509_cert.py |  3 +-
 3 files changed, 101 insertions(+), 3 deletions(-)
Quoted 2 lines

Please do check that you have 100% test coverage here (binman test -T)

Name Stmts Miss Cover
---------------------------------------------------------------------------
[snip]

tools/binman/btool/openssl.py                              42      0   100%
tools/binman/etype/ti_secure.py                            57      0   100%
tools/binman/etype/x509_cert.py                            70      0   100%

[snip]
---------------------------------------------------------------------------
TOTAL 5588 134 98%

I did check that, did you notice something else that I might've missed? I just checked for the files that I have changed, I am not sure if there are any dependencies that I also have to keep in mind. Do let me know if I missed something.

Regards,
Manorit

Quoted 2 lines

Regards,
Simon

#7 lore raw

Re: [RFC PATCH v2 2/8] binman: ti-secure: Add support for firewalling entities

Hi Manorit,

Quoted 33 lines · Manorit Chawdhry

Hi Simon,

Quoted 20 lines · Simon Glass

Hi Manorit,

Quoted 9 lines · Manorit Chawdhry

We can now firewall entities while loading them through our secure entity TIFS, the required information should be present in the certificate that is being parsed by TIFS.

The following commit adds the support to enable the certificates to be generated if the firewall configurations are present in the binman dtsi nodes.

Quoted 7 lines
---
 tools/binman/btool/openssl.py   | 16 +++++++-
 tools/binman/etype/ti_secure.py | 85 +++++++++++++++++++++++++++++++++++++++++
 tools/binman/etype/x509_cert.py |  3 +-
 3 files changed, 101 insertions(+), 3 deletions(-)
Quoted 2 lines

Please do check that you have 100% test coverage here (binman test -T)

Name Stmts Miss Cover
---------------------------------------------------------------------------
[snip]

tools/binman/btool/openssl.py                              42      0   100%
tools/binman/etype/ti_secure.py                            57      0   100%
tools/binman/etype/x509_cert.py                            70      0   100%
Quoted 8 lines

[snip]
---------------------------------------------------------------------------
TOTAL 5588 134 98%

I did check that, did you notice something else that I might've missed? I just checked for the files that I have changed, I am not sure if there are any dependencies that I also have to keep in mind. Do let me know if I missed something.

Yes it seems to be a problem with a Xilinx tool. I sent an email about it, so don't worry about this.

Regards,
iSimon

#8 lore raw

RFC PATCH v2 3/8 binman: ftest: Add test for ti-secure firewall node

In reply to Manorit Chawdhry

Add test for TI firewalling node in ti-secure.

---
 tools/binman/ftest.py                        | 12 ++++++++++++
 tools/binman/test/311_ti_secure_firewall.dts | 28 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
tools/binman/ftest.py +12 -0
index 8e419645a6d5..a3e49149d0d7 100644
@@ -7030,6 +7030,18 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
                                    entry_args=entry_args)[0]
         self.assertGreater(len(data), len(TI_UNSECURE_DATA))
 
+    def testPackTiSecureFirewall(self):
+        """Test that an image with a TI secured binary can be created"""
+        keyfile = self.TestFile('key.key')
+        entry_args = {
+            'keyfile': keyfile,
+        }
+        data_no_firewall = self._DoReadFileDtb('296_ti_secure.dts',
+                                   entry_args=entry_args)[0]
+        data_firewall = self._DoReadFileDtb('311_ti_secure_firewall.dts',
+                                   entry_args=entry_args)[0]
+        self.assertGreater(len(data_firewall),len(data_no_firewall))
+
     def testPackTiSecureMissingTool(self):
         """Test that an image with a TI secured binary (non-functional) can be created
         when openssl is missing"""
tools/binman/test/311_ti_secure_firewall.dts new file +28 -0
new file mode 100644
index 000000000000..b392d9ad4cbc
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		ti-secure {
+			content = <&unsecure_binary>;
+            auth_in_place = <0xa02>;
+
+            firewall-0-2 {
+                id = <0>;
+                region = <2>;
+                control = <0x31a>;
+                permissions = <0xc3ffff>;
+                start_address = <0x0 0x9e800000>;
+                end_address = <0x0 0x9fffffff>;
+            };
+
+		};
+		unsecure_binary: blob-ext {
+			filename = "ti_unsecure.bin";
+		};
+	};
+};
Signature · 1 line
2.41.0
Reviewed-by on v2 3/8
#9 lore raw

Re: [RFC PATCH v2 3/8] binman: ftest: Add test for ti-secure firewall node

Quoted 9 lines · Manorit Chawdhry

Add test for TI firewalling node in ti-secure.

---
 tools/binman/ftest.py                        | 12 ++++++++++++
 tools/binman/test/311_ti_secure_firewall.dts | 28 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
#10 lore raw

RFC PATCH v2 4/8 binman: k3: add k3-security.h and include it in k3-binman.dtsi

In reply to Manorit Chawdhry

For readability during configuring firewalls, adding k3-security.h file and including it in k3-binman.dtsi to be accessible across K3 SoCs

---
 arch/arm/dts/k3-binman.dtsi |  2 ++
 arch/arm/dts/k3-security.h  | 58 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
arch/arm/dts/k3-binman.dtsi +2 -0
index 2ea2dd18a12b..71ffa998a59f 100644
@@ -3,6 +3,8 @@
  * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
  */
 
+#include "k3-security.h"
+
 / {
 	binman: binman {
 		multiple-images;
arch/arm/dts/k3-security.h new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.41.0
Reviewed-by on v2 4/8
#11 lore raw

Re: [RFC PATCH v2 4/8] binman: k3: add k3-security.h and include it in k3-binman.dtsi

Hi Manorit,

Quoted 10 lines · Manorit Chawdhry

For readability during configuring firewalls, adding k3-security.h file and including it in k3-binman.dtsi to be accessible across K3 SoCs

---
 arch/arm/dts/k3-binman.dtsi |  2 ++
 arch/arm/dts/k3-security.h  | 58 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

nits below

Quoted 20 lines
arch/arm/dts/k3-binman.dtsi +2 -0
index 2ea2dd18a12b..71ffa998a59f 100644
@@ -3,6 +3,8 @@
  * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
  */
 
+#include "k3-security.h"
+
 / {
        binman: binman {
                multiple-images;
arch/arm/dts/k3-security.h new file +1 -0
new file mode 100644
index 000000000000..e012b7afaf94
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0

arch/arm/dts/k3-security.h line 11

Quoted 10 lines
arch/arm/dts/k3-security.h new file +10 -0
+/*
+ * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef DTS_ARM64_TI_K3_FIREWALL_H
+#define DTS_ARM64_TI_K3_FIREWALL_H
+
+#define FWPRIVID_ALL    (0xc3)
+#define FWPRIVID_ARMV8  (1)
+#define FWPRIVID_SHIFT  (16)

drop () on those three and the next one

Quoted 49 lines
arch/arm/dts/k3-security.h new file +47 -1
+
+#define FWCTRL_EN     (0xA)
+#define FWCTRL_LOCK   (1 << 4)
+#define FWCTRL_BG     (1 << 8)
+#define FWCTRL_CACHE  (1 << 9)
+
+#define FWPERM_SECURE_PRIV_WRITE      (1 << 0)
+#define FWPERM_SECURE_PRIV_READ       (1 << 1)
+#define FWPERM_SECURE_PRIV_CACHEABLE  (1 << 2)
+#define FWPERM_SECURE_PRIV_DEBUG      (1 << 3)
+
+#define FWPERM_SECURE_PRIV_RWCD       (FWPERM_SECURE_PRIV_READ | \
+                                       FWPERM_SECURE_PRIV_WRITE | \
+                                       FWPERM_SECURE_PRIV_CACHEABLE | \
+                                       FWPERM_SECURE_PRIV_DEBUG)
+
+#define FWPERM_SECURE_USER_WRITE      (1 << 4)
+#define FWPERM_SECURE_USER_READ       (1 << 5)
+#define FWPERM_SECURE_USER_CACHEABLE  (1 << 6)
+#define FWPERM_SECURE_USER_DEBUG      (1 << 7)
+
+#define FWPERM_SECURE_USER_RWCD       (FWPERM_SECURE_USER_READ | \
+                                       FWPERM_SECURE_USER_WRITE | \
+                                       FWPERM_SECURE_USER_CACHEABLE | \
+                                       FWPERM_SECURE_USER_DEBUG)
+
+#define FWPERM_NON_SECURE_PRIV_WRITE      (1 << 8)
+#define FWPERM_NON_SECURE_PRIV_READ       (1 << 9)
+#define FWPERM_NON_SECURE_PRIV_CACHEABLE  (1 << 10)
+#define FWPERM_NON_SECURE_PRIV_DEBUG      (1 << 11)
+
+#define FWPERM_NON_SECURE_PRIV_RWCD       (FWPERM_NON_SECURE_PRIV_READ | \
+                                           FWPERM_NON_SECURE_PRIV_WRITE | \
+                                           FWPERM_NON_SECURE_PRIV_CACHEABLE | \
+                                           FWPERM_NON_SECURE_PRIV_DEBUG)
+
+#define FWPERM_NON_SECURE_USER_WRITE      (1 << 12)
+#define FWPERM_NON_SECURE_USER_READ       (1 << 13)
+#define FWPERM_NON_SECURE_USER_CACHEABLE  (1 << 14)
+#define FWPERM_NON_SECURE_USER_DEBUG      (1 << 15)
+
+#define FWPERM_NON_SECURE_USER_RWCD       (FWPERM_NON_SECURE_USER_READ | \
+                                           FWPERM_NON_SECURE_USER_WRITE | \
+                                           FWPERM_NON_SECURE_USER_CACHEABLE | \
+                                           FWPERM_NON_SECURE_USER_DEBUG)
+
+#endif
 
--
Quoted 2 lines

2.41.0

Regards,
Simon

#12 lore raw

Re: [RFC PATCH v2 4/8] binman: k3: add k3-security.h and include it in k3-binman.dtsi

Hi Simon,

Quoted 42 lines · Simon Glass

Hi Manorit,

Quoted 10 lines · Manorit Chawdhry

For readability during configuring firewalls, adding k3-security.h file and including it in k3-binman.dtsi to be accessible across K3 SoCs

---
 arch/arm/dts/k3-binman.dtsi |  2 ++
 arch/arm/dts/k3-security.h  | 58 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

nits below

Quoted 24 lines
arch/arm/dts/k3-binman.dtsi +2 -0
index 2ea2dd18a12b..71ffa998a59f 100644
@@ -3,6 +3,8 @@
  * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
  */
 
+#include "k3-security.h"
+
 / {
        binman: binman {
                multiple-images;
arch/arm/dts/k3-security.h new file +5 -0
new file mode 100644
index 000000000000..e012b7afaf94
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
Quoted 9 lines

arch/arm/dts/k3-security.h line 11

Quoted 6 lines
arch/arm/dts/k3-security.h new file +6 -0
+#ifndef DTS_ARM64_TI_K3_FIREWALL_H
+#define DTS_ARM64_TI_K3_FIREWALL_H
+
+#define FWPRIVID_ALL    (0xc3)
+#define FWPRIVID_ARMV8  (1)
+#define FWPRIVID_SHIFT  (16)

drop () on those three and the next one

Would fix those in next revision. Thanks for the reviews!

Regards,
Manorit

Quoted 54 lines
Quoted 49 lines
arch/arm/dts/k3-security.h new file +47 -1
+
+#define FWCTRL_EN     (0xA)
+#define FWCTRL_LOCK   (1 << 4)
+#define FWCTRL_BG     (1 << 8)
+#define FWCTRL_CACHE  (1 << 9)
+
+#define FWPERM_SECURE_PRIV_WRITE      (1 << 0)
+#define FWPERM_SECURE_PRIV_READ       (1 << 1)
+#define FWPERM_SECURE_PRIV_CACHEABLE  (1 << 2)
+#define FWPERM_SECURE_PRIV_DEBUG      (1 << 3)
+
+#define FWPERM_SECURE_PRIV_RWCD       (FWPERM_SECURE_PRIV_READ | \
+                                       FWPERM_SECURE_PRIV_WRITE | \
+                                       FWPERM_SECURE_PRIV_CACHEABLE | \
+                                       FWPERM_SECURE_PRIV_DEBUG)
+
+#define FWPERM_SECURE_USER_WRITE      (1 << 4)
+#define FWPERM_SECURE_USER_READ       (1 << 5)
+#define FWPERM_SECURE_USER_CACHEABLE  (1 << 6)
+#define FWPERM_SECURE_USER_DEBUG      (1 << 7)
+
+#define FWPERM_SECURE_USER_RWCD       (FWPERM_SECURE_USER_READ | \
+                                       FWPERM_SECURE_USER_WRITE | \
+                                       FWPERM_SECURE_USER_CACHEABLE | \
+                                       FWPERM_SECURE_USER_DEBUG)
+
+#define FWPERM_NON_SECURE_PRIV_WRITE      (1 << 8)
+#define FWPERM_NON_SECURE_PRIV_READ       (1 << 9)
+#define FWPERM_NON_SECURE_PRIV_CACHEABLE  (1 << 10)
+#define FWPERM_NON_SECURE_PRIV_DEBUG      (1 << 11)
+
+#define FWPERM_NON_SECURE_PRIV_RWCD       (FWPERM_NON_SECURE_PRIV_READ | \
+                                           FWPERM_NON_SECURE_PRIV_WRITE | \
+                                           FWPERM_NON_SECURE_PRIV_CACHEABLE | \
+                                           FWPERM_NON_SECURE_PRIV_DEBUG)
+
+#define FWPERM_NON_SECURE_USER_WRITE      (1 << 12)
+#define FWPERM_NON_SECURE_USER_READ       (1 << 13)
+#define FWPERM_NON_SECURE_USER_CACHEABLE  (1 << 14)
+#define FWPERM_NON_SECURE_USER_DEBUG      (1 << 15)
+
+#define FWPERM_NON_SECURE_USER_RWCD       (FWPERM_NON_SECURE_USER_READ | \
+                                           FWPERM_NON_SECURE_USER_WRITE | \
+                                           FWPERM_NON_SECURE_USER_CACHEABLE | \
+                                           FWPERM_NON_SECURE_USER_DEBUG)
+
+#endif
 
--
Quoted 2 lines

2.41.0

Regards,
Simon

#13 lore raw

RFC PATCH v2 5/8 binman: j721e: Add firewall configurations for atf

In reply to Manorit Chawdhry

The following commits adds the configuration of firewalls required to protect ATF and OP-TEE memory region from non-secure reads and writes using master and slave firewalls present in our K3 SOCs.

---
 arch/arm/dts/k3-j721e-binman.dtsi | 183 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 183 insertions(+)
arch/arm/dts/k3-j721e-binman.dtsi +183 -0
index 4f566c21a9af..15fd5c857452 100644
@@ -330,6 +330,100 @@
 					ti-secure {
 						content = <&atf>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						firewall-257-0 {
+							/* cpu_0_cpu_0_msmc Background Firewall */
+							id = <257>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-257-1 {
+							/* cpu_0_cpu_0_msmc Foreground Firewall */
+							id = <257>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+						firewall-284-0 {
+							/* dru_0_msmc Background Firewall */
+							id = <284>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-284-1 {
+							/* dru_0_msmc Foreground Firewall */
+							id = <284>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+						/* firewall-4760-0 {
+							nb_slv0__mem0 Background Firewall
+							Already configured by the secure entity
+						}; */
+
+						firewall-4760-1 {
+							/* nb_slv0__mem0 Foreground Firewall */
+							id = <4760>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+						/* firewall-4761-0 {
+							nb_slv1__mem0 Background Firewall
+							Already configured by the secure entity
+						}; */
+
+						firewall-4761-1 {
+							/* nb_slv1__mem0 Foreground Firewall */
+							id = <4761>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
 					};
 					atf: atf-bl31 {
 					};
@@ -346,6 +440,95 @@
 					ti-secure {
 						content = <&tee>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						/* cpu_0_cpu_0_msmc region 0 and 1 configured
+						   during ATF Firewalling */
+
+						firewall-257-2 {
+							/* cpu_0_cpu_0_msmc Foreground Firewall */
+							id = <257>;
+							region = <2>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
+						/* dru_0_msmc region 0 and 1 configured
+						   during ATF Firewalling */
+
+                        firewall-284-2 {
+                            /* dru_0_msmc Foreground Firewall */
+                            id = <284>;
+                            region = <2>;
+                            control = <(FWCTRL_EN | FWCTRL_LOCK |
+                                        FWCTRL_CACHE)>;
+                            permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+                                            FWPERM_SECURE_PRIV_RWCD |
+                                            FWPERM_SECURE_USER_RWCD)>;
+                            start_address = <0x0 0x9e800000>;
+                            end_address = <0x0 0x9fffffff>;
+                        };
+
+                        firewall-4762-0 {
+                            /* nb_slv2__mem0 Background Firewall */
+                            id = <4762>;
+                            region = <0>;
+                            control = <(FWCTRL_EN | FWCTRL_LOCK |
+                                        FWCTRL_BG | FWCTRL_CACHE)>;
+                            permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+                                            FWPERM_SECURE_PRIV_RWCD |
+                                            FWPERM_SECURE_USER_RWCD |
+                                            FWPERM_NON_SECURE_PRIV_RWCD |
+                                            FWPERM_NON_SECURE_USER_RWCD)>;
+                            start_address = <0x0 0x0>;
+                            end_address = <0xff 0xffffffff>;
+                        };
+
+                        firewall-4762-1 {
+                            /* nb_slv2__mem0 Foreground Firewall */
+                            id = <4762>;
+                            region = <1>;
+                            control = <(FWCTRL_EN | FWCTRL_LOCK |
+                                        FWCTRL_CACHE)>;
+                            permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+                                            FWPERM_SECURE_PRIV_RWCD |
+                                            FWPERM_SECURE_USER_RWCD)>;
+                            start_address = <0x0 0x9e800000>;
+                            end_address = <0x0 0x9fffffff>;
+                        };
+
+                        firewall-4763-0 {
+                            /* nb_slv3__mem0 Background Firewall */
+                            id = <4763>;
+                            region = <0>;
+                            control = <(FWCTRL_EN | FWCTRL_LOCK |
+                                        FWCTRL_BG | FWCTRL_CACHE)>;
+                            permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+                                            FWPERM_SECURE_PRIV_RWCD |
+                                            FWPERM_SECURE_USER_RWCD |
+                                            FWPERM_NON_SECURE_PRIV_RWCD |
+                                            FWPERM_NON_SECURE_USER_RWCD)>;
+                            start_address = <0x0 0x0>;
+                            end_address = <0xff 0xffffffff>;
+                        };
+
+                        firewall-4763-1 {
+                            /* nb_slv3__mem0 Foreground Firewall */
+                            id = <4763>;
+                            region = <1>;
+                            control = <(FWCTRL_EN | FWCTRL_LOCK |
+                                        FWCTRL_CACHE)>;
+                            permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+                                            FWPERM_SECURE_PRIV_RWCD |
+                                            FWPERM_SECURE_USER_RWCD)>;
+                            start_address = <0x0 0x9e800000>;
+                            end_address = <0x0 0x9fffffff>;
+                        };
 					};
 					tee: tee-os {
 					};
Signature · 1 line
2.41.0
#14 lore raw

RFC PATCH v2 6/8 binman: am62x: Add firewalling configurations

In reply to Manorit Chawdhry

The following commits adds the configuration of firewalls required to protect ATF and OP-TEE memory region from non-secure reads and writes using master and slave firewalls present in our K3 SOCs.

---
 arch/arm/dts/k3-am625-sk-binman.dtsi | 49 ++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
arch/arm/dts/k3-am625-sk-binman.dtsi +49 -0
index 41277bf4bfdb..bb5341aaae8e 100644
@@ -175,6 +175,36 @@
 					ti-secure {
 						content = <&atf>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						firewall-1-0 {
+							/* sdram Background Firewall - 0 */
+							id = <1>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-1-1 {
+							/* sdram Foreground Firewall */
+							id = <1>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e780000>;
+							end_address = <0x0 0x9e7fffff>;
+						};
+
 					};
 					atf: atf-bl31 {
 					};
@@ -191,8 +221,27 @@
 					ti-secure {
 						content = <&tee>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						/* sdram region 0 and 1 configured during
+						   ATF Firewalling */
+
+						firewall-1-2 {
+							/* sdram Foreground Firewall */
+							id = <1>;
+							region = <2>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
 					};
 					tee: tee-os {
+
 					};
 				};
 
Signature · 1 line
2.41.0
#15 lore raw

RFC PATCH v2 7/8 binman: j721s2: Add firewall configurations

In reply to Manorit Chawdhry

The following commits adds the configuration of firewalls required to protect ATF and OP-TEE memory region from non-secure reads and writes using master and slave firewalls present in our K3 SOCs.

---
 arch/arm/dts/k3-j721s2-binman.dtsi | 206 +++++++++++++++++++++++++++++++++++++
 1 file changed, 206 insertions(+)
arch/arm/dts/k3-j721s2-binman.dtsi +206 -0
index 5bca4e94ecf9..40205fb8655e 100644
@@ -177,6 +177,100 @@
 					ti-secure {
 						content = <&atf>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						firewall-257-0 {
+							/* cpu_0_cpu_0_msmc Background Firewall */
+							id = <257>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-257-1 {
+							/* cpu_0_cpu_0_msmc Foreground Firewall */
+							id = <257>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+						firewall-284-0 {
+							/* dru_0_msmc Background Firewall */
+							id = <284>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-284-1 {
+							/* dru_0_msmc Foreground Firewall */
+							id = <284>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+						/* firewall-5140-0 {
+							nb_slv0__mem0 Background Firewall
+							Already configured by the secure entity
+						}; */
+
+						firewall-5140-1 {
+							/* nb_slv0__mem0 Foreground Firewall */
+							id = <5140>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+                        /* firewall-5140-0 {
+							nb_slv1__mem0 Background Firewall
+							Already configured by the secure entity
+						}; */
+
+						firewall-5141-1 {
+							/* nb_slv1__mem0 Foreground Firewall */
+							id = <5141>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
 					};
 					atf: atf-bl31 {
 					};
@@ -193,6 +287,118 @@
 					ti-secure {
 						content = <&tee>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						firewall-257-2 {
+							/* cpu_0_cpu_0_msmc Foreground Firewall */
+							id = <257>;
+							region = <2>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
+						firewall-284-2 {
+							/* dru_0_msmc Foreground Firewall */
+							id = <284>;
+							region = <2>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
+						firewall-5142-0 {
+							/* nb_slv2__mem0 Background Firewall - 0 */
+							id = <5142>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-5142-1 {
+							/* nb_slv2__mem0 Foreground Firewall */
+							id = <5142>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
+						firewall-5143-0 {
+							/* nb_slv3__mem0 Background Firewall - 0 */
+							id = <5143>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-5143-1 {
+							/* nb_slv3__mem0 Foreground Firewall */
+							id = <5143>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
+						firewall-5144-0 {
+							/* nb_slv4__mem0 Background Firewall - 0 */
+							id = <5144>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-5144-1 {
+							/* nb_slv4__mem0 Foreground Firewall */
+							id = <5144>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
 					};
 					tee: tee-os {
 					};
Signature · 1 line
2.41.0
#16 lore raw

RFC PATCH v2 8/8 binman: j7200: Add firewall configurations

In reply to Manorit Chawdhry

The following commits adds the configuration of firewalls required to protect ATF and OP-TEE memory region from non-secure reads and writes using master and slave firewalls present in our K3 SOCs.

---
 arch/arm/dts/k3-j7200-binman.dtsi | 137 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)
arch/arm/dts/k3-j7200-binman.dtsi +137 -0
index 14f7dea65ee3..c5a2cc065294 100644
@@ -214,6 +214,72 @@
 					ti-secure {
 						content = <&atf>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						firewall-257-0 {
+							/* cpu_0_cpu_0_msmc Background Firewall */
+							id = <257>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-257-1 {
+							/* cpu_0_cpu_0_msmc Foreground Firewall */
+							id = <257>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+						/* firewall-4760-0 {
+							nb_slv0__mem0 Background Firewall
+							Already configured by the secure entity
+						}; */
+
+						firewall-4760-1 {
+							/* nb_slv0__mem0 Foreground Firewall */
+							id = <4760>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
+						/* firewall-4761-0 {
+							nb_slv1__mem0 Background Firewall
+							Already configured by the secure entity
+						}; */
+
+						firewall-4761-1 {
+							/* nb_slv1__mem0 Foreground Firewall */
+							id = <4761>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x70000000>;
+							end_address = <0x0 0x7001ffff>;
+						};
+
 					};
 					atf: atf-bl31 {
 					};
@@ -230,6 +296,77 @@
 					ti-secure {
 						content = <&tee>;
 						keyfile = "custMpk.pem";
+						auth_in_place = <0xa02>;
+
+						firewall-257-2 {
+							/* cpu_0_cpu_0_msmc Foreground Firewall */
+							id = <257>;
+							region = <2>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
+						firewall-4762-0 {
+							/* nb_slv2__mem0 Background Firewall - 0 */
+							id = <4762>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-4762-1 {
+							/* nb_slv2__mem0 Foreground Firewall */
+							id = <4762>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
+						firewall-4763-0 {
+							/* nb_slv3__mem0 Background Firewall - 0 */
+							id = <4763>;
+							region = <0>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_BG | FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ALL << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD |
+											FWPERM_NON_SECURE_PRIV_RWCD |
+											FWPERM_NON_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x0>;
+							end_address = <0xff 0xffffffff>;
+						};
+
+						firewall-4763-1 {
+							/* nb_slv3__mem0 Foreground Firewall */
+							id = <4763>;
+							region = <1>;
+							control = <(FWCTRL_EN | FWCTRL_LOCK |
+										FWCTRL_CACHE)>;
+							permissions = <((FWPRIVID_ARMV8 << FWPRIVID_SHIFT) |
+											FWPERM_SECURE_PRIV_RWCD |
+											FWPERM_SECURE_USER_RWCD)>;
+							start_address = <0x0 0x9e800000>;
+							end_address = <0x0 0x9fffffff>;
+						};
+
 					};
 					tee: tee-os {
 					};
Signature · 1 line
2.41.0
#17 lore raw
In reply to Manorit Chawdhry
Quoted 10 lines · Manorit Chawdhry

K3 devices have firewalls that are used to prevent illegal accesses to memory regions that are deemed secure. The series prevents the illegal accesses to ATF and OP-TEE regions that are present in different K3 devices.

AM62AX and AM64X are currently in hold due to some firewall configurations that our System Controller (TIFS) needs to handle.

---

You have mixed tabs and spaces in the .dtsi patches.

Andrew

Quoted 48 lines

Changes in v2:

Andrew:
- Make the firewall DTS more readable with CONSTANTS

Neha:
- Move GetHexOctet to dtoc for common usage
- Update the documentation in ti-secure
- s/indentifier/identifier/
- Add firewall binman test

- Remove slave firewall multiple background regions
( Single firewall region works fine )
- Add a check in the subnodes to check for the node.name 'firewall'
- Change firewall indexing with id and region number so that it is easy
to purge out firewalls and we don't need to redo the numbering.
- Add information for all the firewalls.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
Manorit Chawdhry (8):
dtoc: openssl: Add GetHexOctet method
binman: ti-secure: Add support for firewalling entities
binman: ftest: Add test for ti-secure firewall node
binman: k3: add k3-security.h and include it in k3-binman.dtsi
binman: j721e: Add firewall configurations for atf
binman: am62x: Add firewalling configurations
binman: j721s2: Add firewall configurations
binman: j7200: Add firewall configurations

  arch/arm/dts/k3-am625-sk-binman.dtsi         |  49 +++++++
  arch/arm/dts/k3-binman.dtsi                  |   2 +
  arch/arm/dts/k3-j7200-binman.dtsi            | 137 ++++++++++++++++++
  arch/arm/dts/k3-j721e-binman.dtsi            | 183 ++++++++++++++++++++++++
  arch/arm/dts/k3-j721s2-binman.dtsi           | 206 +++++++++++++++++++++++++++
  arch/arm/dts/k3-security.h                   |  58 ++++++++
  tools/binman/btool/openssl.py                |  16 ++-
  tools/binman/etype/ti_secure.py              |  85 +++++++++++
  tools/binman/etype/x509_cert.py              |   3 +-
  tools/binman/ftest.py                        |  12 ++
  tools/binman/test/311_ti_secure_firewall.dts |  28 ++++
  tools/dtoc/fdt_util.py                       |  20 +++
  12 files changed, 796 insertions(+), 3 deletions(-)

---
base-commit: 2fe4b54556ea6271237b35de68dc458bfceab94c
change-id: 20230724-binman-firewalling-65ecdb23ec0a

Best regards,

#18 lore raw

Hi Andrew,

Quoted 6 lines · Andrew Davis
Quoted 5 lines · Manorit Chawdhry

K3 devices have firewalls that are used to prevent illegal accesses to memory regions that are deemed secure. The series prevents the illegal accesses to ATF and OP-TEE regions that are present in different K3 devices.

Quoted 7 lines
Quoted 5 lines

AM62AX and AM64X are currently in hold due to some firewall configurations that our System Controller (TIFS) needs to handle.

---

You have mixed tabs and spaces in the .dtsi patches.

Thanks for this, would be sending a v3 with the fixes.

Regards,
Manorit

Quoted 51 lines

Andrew

Quoted 48 lines

Changes in v2:

Andrew:
- Make the firewall DTS more readable with CONSTANTS

Neha:
- Move GetHexOctet to dtoc for common usage
- Update the documentation in ti-secure
- s/indentifier/identifier/
- Add firewall binman test

- Remove slave firewall multiple background regions
( Single firewall region works fine )
- Add a check in the subnodes to check for the node.name 'firewall'
- Change firewall indexing with id and region number so that it is easy
to purge out firewalls and we don't need to redo the numbering.
- Add information for all the firewalls.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
Manorit Chawdhry (8):
dtoc: openssl: Add GetHexOctet method
binman: ti-secure: Add support for firewalling entities
binman: ftest: Add test for ti-secure firewall node
binman: k3: add k3-security.h and include it in k3-binman.dtsi
binman: j721e: Add firewall configurations for atf
binman: am62x: Add firewalling configurations
binman: j721s2: Add firewall configurations
binman: j7200: Add firewall configurations

  arch/arm/dts/k3-am625-sk-binman.dtsi         |  49 +++++++
  arch/arm/dts/k3-binman.dtsi                  |   2 +
  arch/arm/dts/k3-j7200-binman.dtsi            | 137 ++++++++++++++++++
  arch/arm/dts/k3-j721e-binman.dtsi            | 183 ++++++++++++++++++++++++
  arch/arm/dts/k3-j721s2-binman.dtsi           | 206 +++++++++++++++++++++++++++
  arch/arm/dts/k3-security.h                   |  58 ++++++++
  tools/binman/btool/openssl.py                |  16 ++-
  tools/binman/etype/ti_secure.py              |  85 +++++++++++
  tools/binman/etype/x509_cert.py              |   3 +-
  tools/binman/ftest.py                        |  12 ++
  tools/binman/test/311_ti_secure_firewall.dts |  28 ++++
  tools/dtoc/fdt_util.py                       |  20 +++
  12 files changed, 796 insertions(+), 3 deletions(-)

---
base-commit: 2fe4b54556ea6271237b35de68dc458bfceab94c
change-id: 20230724-binman-firewalling-65ecdb23ec0a

Best regards,