fpga: Add flag to indicate bitstream needs decrypting
Subsystems (2)
[email protected]
maintainerPATCH 1/2 fpga: Add flag to indicate bitstream needs decrypting
From: Moritz Fischer <[email protected]>
Add a flag that is passed to the write_init() callback, indicating that the bitstream is encrypted.
The low-level driver will deal with the flag, or return an error, if encrypted bitstreams are not supported.
--- include/linux/fpga/fpga-mgr.h | 1 + 1 file changed, 1 insertion(+)
include/linux/fpga/fpga-mgr.h +1 -0
@@ -70,6 +70,7 @@ enum fpga_mgr_states {*/ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1) +#define FPGA_MGR_DECRYPT_BITSTREAM BIT(2)/** * struct fpga_image_info - information specific to a FPGA image
Signature · 1 line
2.7.4
[email protected]
maintainerPATCH 2/2 fpga: zynq: Add support for encrypted bitstreams
From: Moritz Fischer <[email protected]>
Add support for encrypted bitstreams. For this to work the system must be booted in secure mode.
In order for on-the-fly decryption to work, the PCAP clock rate needs to be lowered via the PCAP_RATE_EN bit.
--- drivers/fpga/zynq-fpga.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
drivers/fpga/zynq-fpga.c +25 -3
@@ -72,6 +72,10 @@#define CTRL_PCAP_PR_MASK BIT(27)/* Enable PCAP */ #define CTRL_PCAP_MODE_MASK BIT(26) +/* Lower rate to allow decrypt on the fly */ +#define CTRL_PCAP_RATE_EN_MASK BIT(25) +/* System booted in secure mode */ +#define CTRL_SEC_EN_MASK BIT(7)/* Miscellaneous Control Register bit definitions */ /* Internal PCAP loopback */
@@ -264,6 +268,17 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr,if (err)return err; +/* check if bitstream is encrypted & and system's still secure */ +if (info->flags &FPGA_MGR_DECRYPT_BITSTREAM ) { + ctrl =zynq_fpga_read (priv,CTRL_OFFSET ); +if (!(ctrl &CTRL_SEC_EN_MASK )) { +dev_err (&mgr->dev, +"System not secure, can't use crypted bitstreams\n" ); + err = -EINVAL ; + goto out_err; + } + } +/* don't globally reset PL if we're doing partial reconfig */ if (!(info->flags &FPGA_MGR_PARTIAL_RECONFIG )) {if (!zynq_fpga_has_sync (buf, count)) {
@@ -335,12 +350,19 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr,/* set configuration register with following options: * - enable PCAP interface -* - set throughput for maximum speed +* - set throughput for maximum speed (if bistream not crypted) * - set CPU in user mode */ ctrl =zynq_fpga_read (priv,CTRL_OFFSET ); -zynq_fpga_write (priv,CTRL_OFFSET , - (CTRL_PCAP_PR_MASK |CTRL_PCAP_MODE_MASK | ctrl)); +if (info->flags &FPGA_MGR_DECRYPT_BITSTREAM ) +zynq_fpga_write (priv,CTRL_OFFSET , + (CTRL_PCAP_PR_MASK |CTRL_PCAP_MODE_MASK + |CTRL_PCAP_RATE_EN_MASK | ctrl)); +else +zynq_fpga_write (priv,CTRL_OFFSET , + (CTRL_PCAP_PR_MASK |CTRL_PCAP_MODE_MASK + | ctrl)); +/* We expect that the command queue is empty right now. */ status =zynq_fpga_read (priv,STATUS_OFFSET );
Signature · 1 line
2.7.4
Quoted 24 lines · On 15.2.2017 01:31, [email protected] wrote:
From: Moritz Fischer <[email protected]>
Add a flag that is passed to the
write_init()callback, indicating that the bitstream is encrypted.The low-level driver will deal with the flag, or return an error, if encrypted bitstreams are not supported.
Signed-off-by Moritz Fischer <[email protected]>Cc Alan Tull <[email protected]>Cc Michal Simek <[email protected]>Cc Sören Brinkmann <[email protected]>--- include/linux/fpga/fpga-mgr.h | 1 + 1 file changed, 1 insertion(+)include/linux/fpga/fpga-mgr.h +0
-0
include/linux/fpga/fpga-mgr.h enum fpga_mgr_states { · line 76
Quoted 7 lines
include/linux/fpga/fpga-mgr.h +1
-0@@ -70,6 +70,7 @@ enum fpga_mgr_states {*/ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1) +#define FPGA_MGR_DECRYPT_BITSTREAM BIT(2)/** * struct fpga_image_info - information specific to a FPGA image
Isn't it better to state that bitstream is encrypted instead of saying that bitstream requires decryption?
Your second patch is saying add support for encrypted bitstreams.
M
Quoted 29 lines · Michal Simek
Quoted 28 lines · On 15.2.2017 01:31, [email protected] wrote:
From: Moritz Fischer <[email protected]>
Add a flag that is passed to the
write_init()callback, indicating that the bitstream is encrypted.The low-level driver will deal with the flag, or return an error, if encrypted bitstreams are not supported.
Signed-off-by Moritz Fischer <[email protected]>Cc Alan Tull <[email protected]>Cc Michal Simek <[email protected]>Cc Sören Brinkmann <[email protected]>--- include/linux/fpga/fpga-mgr.h | 1 + 1 file changed, 1 insertion(+)include/linux/fpga/fpga-mgr.h +1
-0@@ -70,6 +70,7 @@ enum fpga_mgr_states {*/ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1) +#define FPGA_MGR_DECRYPT_BITSTREAM BIT(2)
Quoted 6 lines
include/linux/fpga/fpga-mgr.h enum fpga_mgr_states { · line 76
Quoted 3 lines
include/linux/fpga/fpga-mgr.h +0
-0/** * struct fpga_image_info - information specific to a FPGA image Isn't it better to state that bitstream is encrypted instead of saying that bitstream requires decryption?
Such as FPGA_MGR_ENCRYPTED_BITSTREAM ?
Also please consider adding a DT property such that the FPGA region code will set this flag similar to how the DTO sets up other FPGA image info.
Alan
Quoted 9 lines
Your second patch is saying add support for encrypted bitstreams.
M
--
To unsubscribe from this list: send the line "unsubscribe linux-fpga" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Alan Tull
Quoted 4 lines · Michal Simek
Quoted 4 lines
#define FPGA_MGR_PARTIAL_RECONFIG BIT(0) #define FPGA_MGR_EXTERNAL_CONFIG BIT(1) +#define FPGA_MGR_DECRYPT_BITSTREAM BIT(2)
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
/**
* structfpga_image_info- information specific to a FPGA imageIsn't it better to state that bitstream is encrypted instead of saying that bitstream requires decryption?
Such as
FPGA_MGR_ENCRYPTED_BITSTREAM?
Yeah, can do. This was basically a 'redo' of my earlier 'capability' based patchset. There it made more sense to have a 'can decrypt' capability.
Quoted 3 lines
Also please consider adding a DT property such that the FPGA region code will set this flag similar to how the DTO sets up other FPGA image info.
Yeah, had that on my list. Can add that to v3.
Cheers,
Moritz
Quoted 11 lines · Moritz Fischer
Quoted 10 lines · Alan Tull
Quoted 8 lines · Michal Simek
Quoted 7 lines
#define FPGA_MGR_PARTIAL_RECONFIG BIT(0) #define FPGA_MGR_EXTERNAL_CONFIG BIT(1) +#define FPGA_MGR_DECRYPT_BITSTREAM BIT(2)/**
* structfpga_image_info- information specific to a FPGA image
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Isn't it better to state that bitstream is encrypted instead of saying that bitstream requires decryption?
Such as
FPGA_MGR_ENCRYPTED_BITSTREAM?Yeah, can do. This was basically a 'redo' of my earlier 'capability' based patchset. There it made more sense to have a 'can decrypt' capability.
Just keep in your mind that there are use cases where you also need to pass keys.
Thanks,
Michal