@@ -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;
@@ -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,18 @@ 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_bool(overlay, "encrypted-user-key-fpga-config")) {
+ 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,
@@ -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;
This patch adds user-key encrypted FPGA Image loading support to the framework. Signed-off-by: Nava kishore Manne <nava.manne@xilinx.com> --- drivers/fpga/fpga-mgr.c | 15 +++++++++++++++ drivers/fpga/of-fpga-region.c | 13 +++++++++++++ include/linux/fpga/fpga-mgr.h | 7 +++++++ 3 files changed, 35 insertions(+)