source: svn/trunk/newcon3bcm2_21bu/dta/src/bootloader/sharf/sharf.c @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2011, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description: SHA1 computation using SHARF block
15 *
16 * Revision History:
17 *
18 * $brcm_Log: $
19 *
20 *
21 ***************************************************************************/
22
23//#include "cache_util.h"
24
25#include "sha1o.h"
26
27
28extern void clear_all_d_cache(void);
29
30struct dma_desc_t {
31    uint32 word[8];
32};
33
34#define REG(x) ((volatile uint32 *)(0xB0000000 | (x)))
35#define RWRITE(addr, value) if(1){ *(REG(addr)) = (value); } else
36#define RREAD(addr) (*REG(addr))
37
38
39void SHA1Compute_ram( uint8 * image_ptr, int len, uint32 * digest )
40{
41    uint32 value;
42    uint32 sha1_output;
43    uint32 i;
44    struct dma_desc_t * pdesc;
45    uint32 data[16];
46   
47    pdesc = (0 == ((uint32)&data & 0x1f)) ? (struct dma_desc_t *)&data : (struct dma_desc_t *)(((uint32)&data[8]) & ~0x1f);
48
49    for(i = 0; i < 8; i++){
50        pdesc[0].word[i] = 0;
51    };
52
53    len >>= 3;                  /* divide by 8 as we need lenght in bytes */
54
55    pdesc[0].word[0] = ((uint32)image_ptr & (~0xA0000000));
56    /* field is ignored in sha1 mode */
57    pdesc[0].word[1] = ((uint32)0 & (~0xA0000000));
58    pdesc[0].word[2] = 0x40000000 | (len);
59    /* 4 le, 0 be endian may change */
60    pdesc[0].word[3] = 0x0;
61    pdesc[0].word[4] = 0x00000010; /* sha-160 */
62
63    clear_all_d_cache();
64
65//    flush_dcache((unsigned int)image_ptr, (unsigned int)image_ptr + len);
66//    flush_dcache((unsigned int)pdesc, (unsigned int)pdesc + 8*4);
67
68    value = RREAD(0x00340004);
69    RWRITE(0x00340004, 0x00000000);
70    RWRITE(0x00340008, 0x00000003);
71    RWRITE(0x00340800, 0x00000001);
72    RWRITE(0x00340100, (((uint32)pdesc) & (~0xA0000000)));
73    RWRITE(0x00340104, 0x00000001);
74    do{
75        value = RREAD(0x00340110);
76    }while (value != 2);
77    RWRITE(0x00340104, 0x00000000);
78
79    sha1_output = 0x340018;     /* end address of sha1 value */
80    for(i=0; i < 5; i++){
81        digest[i] = RREAD(sha1_output);
82        sha1_output -= 4;
83    }
84}
Note: See TracBrowser for help on using the repository browser.