Fpga: adds support to load the user-key encrypted FPGA Image loading
Subsystems (3)
v2 cover Fpga: adds support to load the user-key encrypted FPGA Image loading
This patch series adds supports user-key encrypted FPGA Image loading using FPGA Manager framework.
Nava kishore Manne (4):
drivers: firmware: Add user encrypted key load API support
fpga: Add new property to support user-key encrypted bitstream loading
drivers: fpga: Add user-key encrypted FPGA Image loading support
fpga: zynqmp: Add user-key encrypted FPGA Image loading support
.../devicetree/bindings/fpga/fpga-region.txt | 3 +++ drivers/firmware/xilinx/zynqmp.c | 17 +++++++++++++ drivers/fpga/fpga-mgr.c | 15 ++++++++++++ drivers/fpga/of-fpga-region.c | 11 +++++++++ drivers/fpga/zynqmp-fpga.c | 24 +++++++++++++++++-- include/linux/firmware/xlnx-zynqmp.h | 9 +++++++ include/linux/fpga/fpga-mgr.h | 7 ++++++ 7 files changed, 84 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
RFC v2 1/4 drivers: firmware: Add user encrypted key load API support
This patch adds user encrypted key load API to support User key encrypted images loading use cases from Linux.
---
Changes for v2:
-None.
drivers/firmware/xilinx/zynqmp.c | 17 +++++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 7 +++++++ 2 files changed, 24 insertions(+)
drivers/firmware/xilinx/zynqmp.c +17 -0
@@ -787,6 +787,23 @@ int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags) }EXPORT_SYMBOL_GPL (zynqmp_pm_fpga_load); +/** +* zynqmp_pm_fpga_key_load - Perform to load the bitstream encrypted key +* @address: Address to write +* @size: encrypted key size +* +* This function provides access to pmufw. To transfer +* the required encrypted key. +* +* Return: Returns status, either success or error+reason +*/ +int zynqmp_pm_fpga_enc_key_load (const u64 address,const u32 size) +{ +return zynqmp_pm_invoke_fn (PM_ENC_KEY_LOAD ,lower_32_bits (address), +upper_32_bits (address), size,0 ,NULL ); +} +EXPORT_SYMBOL_GPL (zynqmp_pm_fpga_enc_key_load); +/** * zynqmp_pm_fpga_get_status - Read value from PCAP status register * @value: Value to read
include/linux/firmware/xlnx-zynqmp.h +7 -0
@@ -91,6 +91,7 @@ enum pm_api_id {PM_CLOCK_GETPARENT =44 ,PM_SECURE_AES =47 ,PM_FEATURE_CHECK =63 , + PM_ENC_KEY_LOAD = 64, };/* PMU-FW return status codes */
@@ -411,6 +412,7 @@ int zynqmp_pm_pinctrl_get_config(const u32 pin, const u32 param, u32 *value);int zynqmp_pm_pinctrl_set_config (const u32 pin,const u32 param,u32 value); +int zynqmp_pm_fpga_enc_key_load (const u64 address,const u32 size);#else static inline int zynqmp_pm_get_api_version (u32 *version) {
@@ -622,6 +624,11 @@ static inline int zynqmp_pm_pinctrl_set_config(const u32 pin, const u32 param, {return -ENODEV ; } + +static inline int zynqmp_pm_fpga_enc_key_load (const u64 address,const u32 size) +{ +return -ENODEV ; +}#endif #endif /* __FIRMWARE_ZYNQMP_H__ */
Signature · 1 line
2.17.1
Re: [RFC v2 1/4] drivers: firmware: Add user encrypted key load API support
Quoted 2 lines · Nava kishore Manne
This patch adds user encrypted key load API to support User key encrypted images loading use cases from Linux.
What is "user key encrypted images"? Do we need more documentation here for what this is and how to use it?
And why is "User" capitalized?
thanks,
greg k-h
RE: [RFC v2 1/4] drivers: firmware: Add user encrypted key load API support
Hi Greg,
Thanks for providing the review comments.
Please find my response inline.
Quoted 16 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Wednesday, June 9, 2021 3:25 PM
To: Nava kishore Manne <[email protected]>
Cc: [email protected]; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]; Rajan Vaja <[email protected]>; Amit Sunil Dhamne <[email protected]>; Tejas Patel <[email protected]>; [email protected]; Sai Krishna Potthuri <[email protected]>; Ravi Patel <[email protected]>; [email protected]; Jiaying Liang <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; git <[email protected]>; [email protected]
Subject: Re: [RFC v2 1/4] drivers: firmware: Add user encrypted key load API support
Quoted 7 lines
Quoted 2 lines · Nava kishore Manne
This patch adds user encrypted key load API to support User key encrypted images loading use cases from Linux.
What is "user key encrypted images"? Do we need more documentation here for what this is and how to use it?
Xilinx bitstream writer, using AES, encrypts the bitstream. This feature allows user to encrypt bitstream using 256-bit AES encryption in cipher block chaining (CBC) mode. User can supply a 128-bit Initial Vector and 256-bit key(user key).
For more info please refer here:
https://www.xilinx.com/support/documentation/application_notes/xapp1239-fpga-bitstream-encryption.pdf
Quoted 2 lines
And why is "User" capitalized?
Will fix.
Regards,
Navakishore.
Re: [RFC v2 1/4] drivers: firmware: Add user encrypted key load API support
Quoted 25 lines · Nava kishore Manne
Hi Greg,
Thanks for providing the review comments.
Please find my response inline.Quoted 20 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Wednesday, June 9, 2021 3:25 PM
To: Nava kishore Manne <[email protected]>
Cc: [email protected]; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]; Rajan Vaja <[email protected]>; Amit Sunil Dhamne <[email protected]>; Tejas Patel <[email protected]>; [email protected]; Sai Krishna Potthuri <[email protected]>; Ravi Patel <[email protected]>; [email protected]; Jiaying Liang <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; git <[email protected]>; [email protected]
Subject: Re: [RFC v2 1/4] drivers: firmware: Add user encrypted key load API supportQuoted 2 lines · Nava kishore Manne
This patch adds user encrypted key load API to support User key encrypted images loading use cases from Linux.
Quoted 6 lines
Quoted 3 lines
What is "user key encrypted images"? Do we need more documentation here for what this is and how to use it?
Xilinx bitstream writer, using AES, encrypts the bitstream. This feature allows user to encrypt bitstream using 256-bit AES encryption in cipher block chaining (CBC) mode. User can supply a 128-bit Initial Vector and 256-bit key(user key).
Please provide the needed information in the changelog comment.
Quoted 2 lines
For more info please refer here:
https://www.xilinx.com/support/documentation/application_notes/xapp1239-fpga-bitstream-encryption.pdf
External links always grow stale.
thanks,
greg k-h
RFC v2 2/4 fpga: Add new property to support user-key encrypted bitstream loading
In reply to Nava kishore ManneThis patch Adds ‘encrypted-key-name’ property to
support user-key encrypted bitstream loading
use case.
---
Changes for v2:
-Both DT properties ie; encrypted-key-name and encrypted-user-key-fpga-config
are targeted to use for the same use cases but ideally encrypted-key-name is enough to serve the purpose so updated the file to remove the unwanted encrypted-user-key-fpga-config property as suggested by Rob.
Documentation/devicetree/bindings/fpga/fpga-region.txt | 3 +++ 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/fpga/fpga-region.txt +3 -0
@@ -177,6 +177,9 @@ Optional properties: it indicates that the FPGA has already been programmed with this image. If this property is in an overlay targeting a FPGA region, it is a request to program the FPGA with that image. +- encrypted-key-name : should contain the name of an encrypted key file located + on the firmware search path. It will be used to decrypt the FPGA image + file with user-key. - fpga-bridges : should contain a list of phandles to FPGA Bridges that must be controlled during FPGA programming along with the parent FPGA bridge. This property is optional if the FPGA Manager handles the bridges.
Signature · 1 line
2.17.1
Re: [RFC v2 2/4] fpga: Add new property to support user-key encrypted bitstream loading
Quoted 20 lines · Nava kishore Manne
This patch Adds ‘encrypted-key-name’ property to
support user-key encrypted bitstream loading
use case.Signed-off-by Nava kishore Manne <[email protected]>---
Changes for v2:
-Both DT properties ie; encrypted-key-name and encrypted-user-key-fpga-config
are targeted to use for the same use cases but ideally encrypted-key-name is enough to serve the purpose so updated the file to remove the unwanted encrypted-user-key-fpga-config property as suggested by Rob.Documentation/devicetree/bindings/fpga/fpga-region.txt | 3 +++ 1 file changed, 3 insertions(+)Documentation/devicetree/bindings/fpga/fpga-region.txt +0
-0
Documentation/devicetree/bindings/fpga/fpga-region.txt Optional properties: · line 182
Quoted 6 lines
Documentation/devicetree/bindings/fpga/fpga-region.txt +3
-0@@ -177,6 +177,9 @@ Optional properties: it indicates that the FPGA has already been programmed with this image. If this property is in an overlay targeting a FPGA region, it is a request to program the FPGA with that image. +- encrypted-key-name : should contain the name of an encrypted key file located + on the firmware search path. It will be used to decrypt the FPGA image + file with user-key.
What is the format this "user-key" is in? Where is the documentation for how to use this type of thing?
thanks,
greg k-h
RE: [RFC v2 2/4] fpga: Add new property to support user-key encrypted bitstream loading
Hi Greg,
Thanks for providing the review comments.
Please find my response inline.
Quoted 45 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Wednesday, June 9, 2021 3:26 PM
To: Nava kishore Manne <[email protected]>
Cc: [email protected]; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]; Rajan Vaja <[email protected]>; Amit Sunil Dhamne <[email protected]>; Tejas Patel <[email protected]>; [email protected]; Sai Krishna Potthuri <[email protected]>; Ravi Patel <[email protected]>; [email protected]; Jiaying Liang <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; git <[email protected]>; [email protected]
Subject: Re: [RFC v2 2/4] fpga: Add new property to support user-key encrypted bitstream loadingQuoted 7 lines · Nava kishore Manne
This patch Adds ‘encrypted-key-name’ property to support user-key encrypted bitstream loading use case.
Signed-off-by Nava kishore Manne <[email protected]>---
Changes for v2:
-Both DT properties ie; encrypted-key-name and encrypted-user-key-fpga-config
Quoted 1 line
are targeted to use for the same use cases but ideally encrypted-
key-name
Quoted 1 line
is enough to serve the purpose so updated the file to remove the
unwanted
Documentation/devicetree/bindings/fpga/fpga-region.txt Optional properties: · line 177
Quoted 12 lines
encrypted-user-key-fpga-config property as suggested by Rob.
Documentation/devicetree/bindings/fpga/fpga-region.txt | 3 +++ 1 file changed, 3 insertions(+)Documentation/devicetree/bindings/fpga/fpga-region.txt +0
-0@@ -177,6 +177,9 @@ Optional properties: it indicates that the FPGA has already been programmed with thisimage.
Documentation/devicetree/bindings/fpga/fpga-region.txt Optional properties:
Quoted 3 lines
Documentation/devicetree/bindings/fpga/fpga-region.txt +1
-0If this property is in an overlay targeting a FPGA region, it is a request to program the FPGA with that image. +- encrypted-key-name : should contain the name of an encrypted key file
Quoted 8 lines
located
Documentation/devicetree/bindings/fpga/fpga-region.txt Optional properties: · line 181
Quoted 1 line
Documentation/devicetree/bindings/fpga/fpga-region.txt +1
-0+ on the firmware search path. It will be used to decrypt the FPGAimage
Documentation/devicetree/bindings/fpga/fpga-region.txt Optional properties: · line 182
Quoted 1 line
Documentation/devicetree/bindings/fpga/fpga-region.txt +1
-0+ file with user-key.What is the format this "user-key" is in? Where is the documentation for how to use this type of thing?
Will fix user key format issues in v3.
Will update this binding doc with user key encrypted bitstream loading use case info.
Use case info:
Reconfiguration with encrypted image using AES key
In this case, the FPGA Manager will decrypt the configuration data and placed it into the programmable logic. To decrypt the configuration data it uses AES key provided by the user.
DT Overlay contains:
/dts-v1/;
/plugin/;
&fpga_region0 {
#address-cells = <1>;
#size-cells = <1>;
firmware-name = "versal-gpio.bin";
encrypted-key-name = “Aes-key.nky”
gpio1: gpio@40000000 {
compatible = "xlnx,xps-gpio-1.00.a";
reg = <0x40000000 0x10000>;
gpio-controller;
#gpio-cells = <0x2>;
xlnx,gpio-width= <0x6>;
};
};Regards,
Navakishore.
RFC v2 3/4 drivers: fpga: Add user-key encrypted FPGA Image loading support
In reply to Nava kishore ManneThis patch adds user-key encrypted FPGA Image loading support to the framework.
---
Changes for v2:
-Both DT properties ie; encrypted-key-name and encrypted-user-key-fpga-config
are targeted to use for the same use cases but ideally encrypted-key-name is enough to serve the purpose so updated the code to remove the unwanted encrypted-user-key-fpga-config property dependency as suggested by Rob
drivers/fpga/fpga-mgr.c | 15 +++++++++++++++ drivers/fpga/of-fpga-region.c | 11 +++++++++++ include/linux/fpga/fpga-mgr.h | 7 +++++++ 3 files changed, 33 insertions(+)
drivers/fpga/fpga-mgr.c +15 -0
@@ -325,6 +325,7 @@ static int fpga_mgr_firmware_load(struct fpga_manager *mgr, const char *image_name) {struct device *dev = &mgr->dev; +const struct firmware *enc_fw;const struct firmware *fw;int ret;
@@ -339,8 +340,22 @@ static int fpga_mgr_firmware_load(struct fpga_manager *mgr,return ret; } +if (info->encrypted_key_name) { + ret =request_firmware (&enc_fw, info->encrypted_key_name, dev); +if (ret) { + mgr->state =FPGA_MGR_STATE_FIRMWARE_REQ_ERR ; +dev_err (dev,"Error requesting firmware %s\n" , + info->encrypted_key_name); +return ret; + } + info->enc_key_buf = enc_fw->data; + info->enc_key_buf_size = enc_fw->size; + } + ret =fpga_mgr_buf_load (mgr, info, fw->data, fw->size); +if (info->encrypted_key_name) +release_firmware (enc_fw);release_firmware (fw);return ret;
drivers/fpga/of-fpga-region.c +11 -0
@@ -195,6 +195,7 @@ static struct fpga_image_info *of_fpga_region_parse_ov( {struct device *dev = ®ion->dev;struct fpga_image_info *info; +const char *encrypted_key_name;const char *firmware_name;int ret;
@@ -228,6 +229,16 @@ static struct fpga_image_info *of_fpga_region_parse_ov(if (of_property_read_bool (overlay,"encrypted-fpga-config" )) info->flags |=FPGA_MGR_ENCRYPTED_BITSTREAM ; +if (!of_property_read_string (overlay,"encrypted-key-name" , + &encrypted_key_name)) { + info->encrypted_key_name = +devm_kstrdup (dev, encrypted_key_name,GFP_KERNEL ); +if (!info->encrypted_key_name) +return ERR_PTR (-ENOMEM ); + + info->flags |=FPGA_MGR_ENCRYPTED_USER_KEY_BITSTREAM ; + } +if (!of_property_read_string (overlay,"firmware-name" , &firmware_name)) { info->firmware_name = devm_kstrdup(dev, firmware_name,
include/linux/fpga/fpga-mgr.h +7 -0
@@ -67,12 +67,15 @@ enum fpga_mgr_states {* %FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first * * %FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed +* %FPGA_MGR_ENCRYPTED_USER_KEY_BITSTREAM: indicates bitstream is encrypted +* with user-key */ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)#define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2)#define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3)#define FPGA_MGR_COMPRESSED_BITSTREAM BIT(4) +#define FPGA_MGR_ENCRYPTED_USER_KEY_BITSTREAM BIT(5)/** * struct fpga_image_info - information specific to a FPGA image
@@ -82,6 +85,7 @@ enum fpga_mgr_states {* @config_complete_timeout_us: maximum time for FPGA to switch to operating * status in the write_complete op. * @firmware_name: name of FPGA image firmware file +* @encrypted_key_name: name of the FPGA image encrypted user-key file * @sgt: scatter/gather table containing FPGA image * @buf: contiguous buffer containing FPGA image * @count: size of buf
@@ -95,8 +99,11 @@ struct fpga_image_info {u32 disable_timeout_us;u32 config_complete_timeout_us;char *firmware_name; +char *encrypted_key_name;struct sg_table *sgt; +const char *enc_key_buf;const char *buf; +size_t enc_key_buf_size;size_t count;int region_id;struct device *dev;
Signature · 1 line
2.17.1
RFC v2 4/4 fpga: zynqmp: Add user-key encrypted FPGA Image loading support
In reply to Nava kishore ManneThis patch adds support to load the user-key encrypted FPGA Image loading to the Xilinx ZynqMP Soc.
---
Changes for v2:
-None.
drivers/fpga/zynqmp-fpga.c | 24 ++++++++++++++++++++++-- include/linux/firmware/xlnx-zynqmp.h | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-)
drivers/fpga/zynqmp-fpga.c +22 -2
@@ -22,6 +22,8 @@*/ struct zynqmp_fpga_priv {struct device *dev; +const char *key_buf; +size_t key_size;u32 flags; };
@@ -33,6 +35,8 @@ static int zynqmp_fpga_ops_write_init(struct fpga_manager *mgr, priv = mgr->priv; priv->flags = info->flags; + priv->key_buf = info->enc_key_buf; + priv->key_size = info->enc_key_buf_size;return 0 ; }
@@ -41,9 +45,9 @@ static int zynqmp_fpga_ops_write(struct fpga_manager *mgr, const char *buf, size_t size) {struct zynqmp_fpga_priv *priv; -dma_addr_t dma_addr; +dma_addr_t dma_addr, key_addr;u32 eemi_flags =0 ; -char *kbuf; +char *kbuf, *key_kbuf;int ret; priv = mgr->priv;
@@ -54,13 +58,29 @@ static int zynqmp_fpga_ops_write(struct fpga_manager *mgr,memcpy (kbuf, buf, size); +if (priv->flags &FPGA_MGR_ENCRYPTED_USER_KEY_BITSTREAM ) { + eemi_flags |=XILINX_ZYNQMP_PM_FPGA_ENC_USER_KEY ; + key_kbuf =dma_alloc_coherent (priv->dev, size, &key_addr, +GFP_KERNEL ); +if (!key_kbuf) +return -ENOMEM ; +memcpy (key_kbuf, priv->key_buf, priv->key_size); + } +wmb ();/* ensure all writes are done before initiate FW call */ if (priv->flags &FPGA_MGR_PARTIAL_RECONFIG ) eemi_flags |=XILINX_ZYNQMP_PM_FPGA_PARTIAL ; +if (priv->flags &FPGA_MGR_ENCRYPTED_USER_KEY_BITSTREAM ) + ret =zynqmp_pm_fpga_enc_key_load (key_addr, priv->key_size); + ret =zynqmp_pm_fpga_load (dma_addr, size, eemi_flags); +if (priv->flags &FPGA_MGR_ENCRYPTED_USER_KEY_BITSTREAM ) +dma_free_coherent (priv->dev, priv->key_size, + key_kbuf, key_addr); +dma_free_coherent (priv->dev, size, kbuf, dma_addr);return ret;
include/linux/firmware/xlnx-zynqmp.h +2 -0
@@ -56,9 +56,11 @@* Firmware FPGA Manager flags * XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration * XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration +* XILINX_ZYNQMP_PM_FPGA_ENC_USER_KEY: User-key Encrypted FPGA reconfiguration */ #define XILINX_ZYNQMP_PM_FPGA_FULL 0x0U#define XILINX_ZYNQMP_PM_FPGA_PARTIAL BIT(0) +#define XILINX_ZYNQMP_PM_FPGA_ENC_USER_KEY BIT(3)enum pm_api_id {PM_GET_API_VERSION =1 ,
Signature · 1 line
2.17.1
Quoted 2 lines · Nava kishore Manne
This patch series adds supports user-key encrypted FPGA Image loading using FPGA Manager framework.
Why is this series "RFC"? Do you not think it is good enough to be merged?
thanks,
greg k-h
Hi Greg,
Thanks for providing the review comments.
Please find my response inline.
Quoted 16 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Wednesday, June 9, 2021 3:25 PM
To: Nava kishore Manne <[email protected]>
Cc: [email protected]; Michal Simek <[email protected]>; [email protected]; [email protected]; [email protected]; Rajan Vaja <[email protected]>; Amit Sunil Dhamne <[email protected]>; Tejas Patel <[email protected]>; [email protected]; Sai Krishna Potthuri <[email protected]>; Ravi Patel <[email protected]>; [email protected]; Jiaying Liang <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; git <[email protected]>; [email protected]
Subject: Re: [RFC v2 0/4]Fpga: adds support to load the user-key encrypted FPGA Image loading
Quoted 6 lines
Quoted 2 lines · Nava kishore Manne
This patch series adds supports user-key encrypted FPGA Image loading using FPGA Manager framework.
Why is this series "RFC"? Do you not think it is good enough to be merged?
As it's a new feature to the fpga manager subsystem. So i have posted it as RFC to get the inputs.
Regards,
Navakishore.