Add ACE HW support for SHA 256
Subsystems (2)
cover Add ACE HW support for SHA 256
This patch set adds hardware acceleration for SHA 256 with the help of ACE.
Akshay Saraswat (4):
Exynos: Add hardware accelerated SHA 256
Exynos: config: Enable ACE HW for SHA 256 for Exynos
gen: Add sha256 command
Exynos: Flush memory region before starting SHA DMA operation
arch/arm/cpu/armv7/exynos/Makefile | 4 + arch/arm/cpu/armv7/exynos/ace_sha.c | 123 ++++++++++++ arch/arm/include/asm/arch-exynos/ace_sfr.h | 310 +++++++++++++++++++++++++++++ arch/arm/include/asm/arch-exynos/ace_sha.h | 41 ++++ arch/arm/include/asm/arch-exynos/cpu.h | 4 + common/Makefile | 1 + common/cmd_sha256.c | 69 +++++++ include/configs/exynos5250-dt.h | 3 + 8 files changed, 555 insertions(+) create mode 100644 arch/arm/cpu/armv7/exynos/ace_sha.c create mode 100644 arch/arm/include/asm/arch-exynos/ace_sfr.h create mode 100644 arch/arm/include/asm/arch-exynos/ace_sha.h create mode 100644 common/cmd_sha256.c
Signature · 1 line
1.8.0
PATCH 1/4 Exynos: Add hardware accelerated SHA 256
SHA-256 and SHA-1 accelerated using ACE hardware.
TEST=sha256 0x40008000 0x2B 0x40009000
Used mm and md to write a standard string to memory location 0x40008000 and ran the above command to verify the output.
--- arch/arm/cpu/armv7/exynos/Makefile | 4 + arch/arm/cpu/armv7/exynos/ace_sha.c | 118 +++++++++++ arch/arm/include/asm/arch-exynos/ace_sfr.h | 310 +++++++++++++++++++++++++++++ arch/arm/include/asm/arch-exynos/ace_sha.h | 41 ++++ arch/arm/include/asm/arch-exynos/cpu.h | 4 + 5 files changed, 477 insertions(+) create mode 100644 arch/arm/cpu/armv7/exynos/ace_sha.c create mode 100644 arch/arm/include/asm/arch-exynos/ace_sfr.h create mode 100644 arch/arm/include/asm/arch-exynos/ace_sha.h
arch/arm/cpu/armv7/exynos/Makefile +4 -0
@@ -24,6 +24,10 @@ LIB = $(obj)lib$(SOC).o COBJS += clock.o power.o soc.o system.o pinmux.o +ifdef CONFIG_EXYNOS_ACE_SHA +COBJS += ace_sha.o +endif + SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(COBJS) $(SOBJS))
arch/arm/cpu/armv7/exynos/ace_sha.c new file +118 -0
118 lines not on this page · raw message
arch/arm/include/asm/arch-exynos/ace_sfr.h new file +310 -0
310 lines not on this page · raw message
arch/arm/include/asm/arch-exynos/ace_sha.h new file +41 -0
41 lines not on this page · raw message
arch/arm/include/asm/arch-exynos/cpu.h +4 -0
@@ -62,6 +62,7 @@#define EXYNOS4_GPIO_PART4_BASE DEVICE_NOT_AVAILABLE#define EXYNOS4_DP_BASE DEVICE_NOT_AVAILABLE#define EXYNOS4_SPI_ISP_BASE DEVICE_NOT_AVAILABLE +#define EXYNOS4_ACE_SFR_BASE DEVICE_NOT_AVAILABLE/* EXYNOS4X12 */ #define EXYNOS4X12_GPIO_PART3_BASE 0x03860000
@@ -95,6 +96,7 @@#define EXYNOS4X12_I2S_BASE DEVICE_NOT_AVAILABLE#define EXYNOS4X12_SPI_BASE DEVICE_NOT_AVAILABLE#define EXYNOS4X12_SPI_ISP_BASE DEVICE_NOT_AVAILABLE +#define EXYNOS4X12_ACE_SFR_BASE DEVICE_NOT_AVAILABLE/* EXYNOS5 Common*/ #define EXYNOS5_I2C_SPACING 0x10000
@@ -106,6 +108,7 @@#define EXYNOS5_SWRESET 0x10040400#define EXYNOS5_SYSREG_BASE 0x10050000#define EXYNOS5_WATCHDOG_BASE 0x101D0000 +#define EXYNOS5_ACE_SFR_BASE 0x10830000#define EXYNOS5_DMC_PHY0_BASE 0x10C00000#define EXYNOS5_DMC_PHY1_BASE 0x10C10000#define EXYNOS5_GPIO_PART3_BASE 0x10D10000
@@ -205,6 +208,7 @@ static inline unsigned int samsung_get_base_##device(void) \ SAMSUNG_BASE(adc, ADC_BASE) SAMSUNG_BASE(clock, CLOCK_BASE) +SAMSUNG_BASE(ace_sfr, ACE_SFR_BASE) SAMSUNG_BASE(dp, DP_BASE) SAMSUNG_BASE(sysreg, SYSREG_BASE)SAMSUNG_BASE (fimd,FIMD_BASE )
Signature · 1 line
1.8.0
PATCH 1/4 Exynos: Add hardware accelerated SHA 256
Quoted 5 lines · On Wed, 27 Feb 2013 10:24:39 -0500 Akshay Saraswat <[email protected]> wrote:
SHA-256 and SHA-1 accelerated using ACE hardware.
TEST=sha256
0x400080000x2B0x40009000
Used mm and md to write a standard string to memory location0x40008000and ran the above command to verify the output.
can we get rid of this TEST= infrastructure format? It's not used on upstream u-boot.
Quoted 12 lines
Signed-off-by ARUN MANKUZHI <[email protected]>Signed-off-by Akshay Saraswat <[email protected]>--- arch/arm/cpu/armv7/exynos/Makefile | 4 + arch/arm/cpu/armv7/exynos/ace_sha.c | 118 +++++++++++ arch/arm/include/asm/arch-exynos/ace_sfr.h | 310 +++++++++++++++++++++++++++++ arch/arm/include/asm/arch-exynos/ace_sha.h | 41 ++++ arch/arm/include/asm/arch-exynos/cpu.h | 4 + 5 files changed, 477 insertions(+) create mode 100644 arch/arm/cpu/armv7/exynos/ace_sha.c create mode 100644 arch/arm/include/asm/arch-exynos/ace_sfr.h create mode 100644 arch/arm/include/asm/arch-exynos/ace_sha.h
I doubt there's anything binding this to arch-exynos, and I bet the h/w is going to be available - if not already - on some other parts, so it probably belongs in a new drivers/crypto directory.
arch/arm/cpu/armv7/exynos/ace_sha.c line 26
Quoted 2 lines
arch/arm/cpu/armv7/exynos/ace_sha.c new file +2
-0+/* Maximum input data size is 8 MB. Timeout observed for data size above 8MB */ +#define TIMEOUT_MS 100
So if there's a drop in processor frequency, the driver times out too early? Not good.
arch/arm/cpu/armv7/exynos/ace_sha.c line 29
Quoted 2 lines
arch/arm/cpu/armv7/exynos/ace_sha.c new file +2
-0+#define SHA1_DIGEST_LEN 20 +#define SHA256_DIGEST_LEN 32
don't duplicate definitions that already exist in include/sha*.h.
arch/arm/cpu/armv7/exynos/ace_sha.c line 61
Quoted 8 lines
arch/arm/cpu/armv7/exynos/ace_sha.c new file +8
-0+if (buf_len ==0 ) { +/* ACE H/W cannot compute hash value for empty string */ +if (hash_type ==ACE_SHA_TYPE_SHA1 ) +memcpy (pout, sha1_digest_emptymsg,SHA1_DIGEST_LEN ); +else +memcpy (pout, sha256_digest_emptymsg,SHA256_DIGEST_LEN ); +return 0 ; + }
there's no protection from buf_len going over the h/w 8MB limit mentioned above - why not fall back to the s/w implementation in both those cases? Or, if the h/w can be programmed to perform multiple hash updates in 8MB data chunks, add support to do that.
arch/arm/cpu/armv7/exynos/ace_sha.c line 109
Quoted 3 lines
arch/arm/cpu/armv7/exynos/ace_sha.c new file +3
-0+/* Read hash result */ + pdigest = (unsigned int *)pout; + len = (hash_type ==ACE_SHA_TYPE_SHA1 ) ?5 :8 ;
magic numbers - use SHAx_SUM_LEN / 4.
Kim
PATCH 2/4 Exynos: config: Enable ACE HW for SHA 256 for Exynos
In reply to Akshay SaraswatThis enables SHA 256 for exynos.
TEST=sha256 0x40008000 0x2B 0x40009000
Used mm and md to write a standard string to memory location 0x40008000 and ran the above command to verify the output.
--- include/configs/exynos5250-dt.h | 3 +++ 1 file changed, 3 insertions(+)
include/configs/exynos5250-dt.h +3 -0
@@ -45,6 +45,9 @@/* Keep L2 Cache Disabled */ #define CONFIG_SYS_DCACHE_OFF +#define CONFIG_CMD_SHA256 +#define CONFIG_EXYNOS_ACE_SHA +#define CONFIG_SYS_SDRAM_BASE 0x40000000#define CONFIG_SYS_TEXT_BASE 0x43E00000
Signature · 1 line
1.8.0
PATCH 2/4 Exynos: config: Enable ACE HW for SHA 256 for Exynos
Hi Akshay,
Quoted 17 lines · Akshay Saraswat
This enables SHA 256 for exynos.
TEST=sha256
0x400080000x2B0x40009000
Used mm and md to write a standard string to memory location0x40008000and ran the above command to verify the output.Signed-off-by ARUN MANKUZHI <[email protected]>Signed-off-by Akshay Saraswat <[email protected]>--- include/configs/exynos5250-dt.h | 3 +++ 1 file changed, 3 insertions(+)include/configs/exynos5250-dt.h +0
-0
include/configs/exynos5250-dt.h line 48
Quoted 4 lines
include/configs/exynos5250-dt.h +1
-0@@ -45,6 +45,9 @@/* Keep L2 Cache Disabled */ #define CONFIG_SYS_DCACHE_OFF +#define CONFIG_CMD_SHA256
This should not be needed, you can use CONFIG_CMD_HASH instead.
Quoted 8 lines
include/configs/exynos5250-dt.h +2
-1+#define CONFIG_EXYNOS_ACE_SHA +#define CONFIG_SYS_SDRAM_BASE 0x40000000#define CONFIG_SYS_TEXT_BASE 0x43E00000 --1.8.0
Regards,
Simon
PATCH 3/4 gen: Add sha256 command
In reply to Akshay Saraswatsha256 command is added which can be used to test SHA 256 hash algorithm.
TEST=sha256 0x40008000 0x2B 0x40009000
Used mm and md to write a standard string to memory location 0x40008000 and ran the above command to verify the output.
--- common/Makefile | 1 + common/cmd_sha256.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 common/cmd_sha256.c
common/Makefile +1 -0
@@ -201,6 +201,7 @@ COBJS-$(CONFIG_MENU) += menu.o COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o COBJS-$(CONFIG_UPDATE_TFTP) += update.o COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o +COBJS-$(CONFIG_CMD_SHA256) += cmd_sha256.o COBJS-$(CONFIG_CMD_DFU) += cmd_dfu.o COBJS-$(CONFIG_CMD_GPT) += cmd_gpt.o endif
common/cmd_sha256.c new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 3/4 gen: Add sha256 command
Hi Akshay,
Quoted 7 lines · Akshay Saraswat
sha256 command is added which can be used to test SHA 256 hash algorithm.
TEST=sha256
0x400080000x2B0x40009000
Used mm and md to write a standard string to memory location0x40008000and ran the above command to verify the output.
Quoted 7 lines
Signed-off-by ARUN MANKUZHI <[email protected]>Signed-off-by Akshay Saraswat <[email protected]>--- common/Makefile | 1 + common/cmd_sha256.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 common/cmd_sha256.c
Rather than adding this command, can you please use 'hash sha256' instead? This is in common/hash.c.
Regards,
Simon
Quoted 91 lines
common/Makefile +1
-0@@ -201,6 +201,7 @@ COBJS-$(CONFIG_MENU) += menu.o COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o COBJS-$(CONFIG_UPDATE_TFTP) += update.o COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o +COBJS-$(CONFIG_CMD_SHA256) += cmd_sha256.o COBJS-$(CONFIG_CMD_DFU) += cmd_dfu.o COBJS-$(CONFIG_CMD_GPT) += cmd_gpt.o endifcommon/cmd_sha256.c new file +69
-1@@ -0,0 +1,69 @@ +/* +* Copyright 2000-2009 +* Wolfgang Denk, DENX Software Engineering, wd at denx.de. +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <common.h> +#include <command.h> +#ifdef CONFIG_EXYNOS_ACE_SHA +#include <asm/arch/ace_sha.h> +#else +#include <sha256.h> +#endif + +int do_sha256 (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +unsigned long inlen; +unsigned char *input, *out; +int i; +#ifndef CONFIG_EXYNOS_ACE_SHA +sha256_context sha_cnxt; +#endif +if (argc <4 ) { +printf ("usage: sha256 <input> <input length> <output>\n" ); +return 0 ; + } + input = (unsigned char *)simple_strtoul (argv[1 ],NULL ,16 ); + inlen =simple_strtoul (argv[2 ],NULL ,16 ); + out = (unsigned char *)simple_strtoul (argv[3 ],NULL ,16 ); + +#ifdef CONFIG_EXYNOS_ACE_SHA +ace_sha_hash_digest (out, input, inlen,2 ); +#else +sha256_starts (&sha_cnxt); + +sha256_update (&sha_cnxt, input, inlen); + +sha256_finish (&sha_cnxt, out); +#endif + +for (i =0 ; i <32 ; i++) +printf ("0x%02X " , out[i]); +printf ("\n" ); + +return 0 ; +} + +U_BOOT_CMD ( + sha256,4 ,1 , do_sha256, +"print hash result" , +"<input> <inputlength> <output>" +); --1.8.0
PATCH 3/4 gen: Add sha256 command
Hi Akshay,
Quoted 18 lines · Simon Glass
Hi Akshay,
Quoted 7 lines · Akshay Saraswat
sha256 command is added which can be used to test SHA 256 hash algorithm.
TEST=sha256
0x400080000x2B0x40009000
Used mm and md to write a standard string to memory location0x40008000and ran the above command to verify the output.Quoted 7 lines
Signed-off-by ARUN MANKUZHI <[email protected]>Signed-off-by Akshay Saraswat <[email protected]>--- common/Makefile | 1 + common/cmd_sha256.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 common/cmd_sha256.c
Quoted 2 lines
Rather than adding this command, can you please use 'hash sha256' instead? This is in
common/hash.c.
And to be a bit more clear, if you plumb in your sha256 implementation into the list of implementations at the top of hash.c, and put it earlier than the software implementation, then it will get priority.
Regards,
Simon
Quoted 95 lines
Regards,
SimonQuoted 91 lines
common/Makefile +1
-0@@ -201,6 +201,7 @@ COBJS-$(CONFIG_MENU) += menu.o COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o COBJS-$(CONFIG_UPDATE_TFTP) += update.o COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o +COBJS-$(CONFIG_CMD_SHA256) += cmd_sha256.o COBJS-$(CONFIG_CMD_DFU) += cmd_dfu.o COBJS-$(CONFIG_CMD_GPT) += cmd_gpt.o endifcommon/cmd_sha256.c new file +69
-1@@ -0,0 +1,69 @@ +/* +* Copyright 2000-2009 +* Wolfgang Denk, DENX Software Engineering, wd at denx.de. +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <common.h> +#include <command.h> +#ifdef CONFIG_EXYNOS_ACE_SHA +#include <asm/arch/ace_sha.h> +#else +#include <sha256.h> +#endif + +int do_sha256 (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +unsigned long inlen; +unsigned char *input, *out; +int i; +#ifndef CONFIG_EXYNOS_ACE_SHA +sha256_context sha_cnxt; +#endif +if (argc <4 ) { +printf ("usage: sha256 <input> <input length> <output>\n" ); +return 0 ; + } + input = (unsigned char *)simple_strtoul (argv[1 ],NULL ,16 ); + inlen =simple_strtoul (argv[2 ],NULL ,16 ); + out = (unsigned char *)simple_strtoul (argv[3 ],NULL ,16 ); + +#ifdef CONFIG_EXYNOS_ACE_SHA +ace_sha_hash_digest (out, input, inlen,2 ); +#else +sha256_starts (&sha_cnxt); + +sha256_update (&sha_cnxt, input, inlen); + +sha256_finish (&sha_cnxt, out); +#endif + +for (i =0 ; i <32 ; i++) +printf ("0x%02X " , out[i]); +printf ("\n" ); + +return 0 ; +} + +U_BOOT_CMD ( + sha256,4 ,1 , do_sha256, +"print hash result" , +"<input> <inputlength> <output>" +); --1.8.0
PATCH 4/4 Exynos: Flush memory region before starting SHA DMA operation
In reply to Akshay SaraswatSHA256 commands weren't giving desired output since the data we set in the memory addresses through mw.l commands was not getting updated in actual memory. Adding this patch resolves the issue.
TEST=sha256 0x40008000 0x2B 0x40009000
Used mm and md to write a standard string to memory location 0x40008000 and ran the above command to verify the output.
--- arch/arm/cpu/armv7/exynos/ace_sha.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/cpu/armv7/exynos/ace_sha.c +5 -0
@@ -51,6 +51,11 @@ int ace_sha_hash_digest(struct exynos_ace_sfr *ace_sha_reg = (struct exynos_ace_sfr *)samsung_get_base_ace_sfr (); +/* Flush input and output memory buffers berore starting DMA */ +flush_dcache_range ((unsigned long ) pout, (unsigned long )(pout +0x20 )); +flush_dcache_range ((unsigned long ) pbuf, + (unsigned long )(pbuf + buf_len)); +if (buf_len ==0 ) {/* ACE H/W cannot compute hash value for empty string */ if (hash_type ==ACE_SHA_TYPE_SHA1 )
Signature · 1 line
1.8.0
PATCH 4/4 Exynos: Flush memory region before starting SHA DMA operation
Quoted 3 lines · On Wed, 27 Feb 2013 10:24:42 -0500 Akshay Saraswat <[email protected]> wrote:
SHA256 commands weren't giving desired output since the data we set in the memory addresses through mw.l commands was not getting updated in actual memory. Adding this patch resolves the issue.
why not use the dcache flush command instead?
Kim