| 1 |
/* |
| 2 |
* Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <stdint.h> |
| 8 |
|
| 9 |
#include <lib/mmio.h> |
| 10 |
|
| 11 |
#include "rcar_def.h" |
| 12 |
#include "rom_api.h" |
| 13 |
|
| 14 |
typedef uint32_t(*rom_secure_boot_api_f) (uint32_t key, uint32_t cert, |
| 15 |
rom_read_flash_f pFuncReadFlash); |
| 16 |
|
| 17 |
typedef uint32_t(*rom_get_lcs_api_f) (uint32_t *lcs); |
| 18 |
|
| 19 |
#define OLD_API_TABLE1 (0U) /* H3 Ver.1.0/Ver.1.1 */ |
| 20 |
#define OLD_API_TABLE2 (1U) /* H3 Ver.2.0 */ |
| 21 |
#define OLD_API_TABLE3 (2U) /* M3 Ver.1.0 */ |
| 22 |
#define NEW_API_TABLE (3U) /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */ |
| 23 |
#define NEW_API_TABLE2 (4U) /* V3M WS1.0 */ |
| 24 |
#define API_TABLE_MAX (5U) /* table max */ |
| 25 |
/* Later than H3 Ver.2.0 */ |
| 26 |
|
| 27 |
static uint32_t get_table_index(void) |
| 28 |
{ |
| 29 |
uint32_t product; |
| 30 |
uint32_t cut_ver; |
| 31 |
uint32_t index; |
| 32 |
|
| 33 |
product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK; |
| 34 |
cut_ver = mmio_read_32(RCAR_PRR) & PRR_CUT_MASK; |
| 35 |
|
| 36 |
switch (product) { |
| 37 |
case PRR_PRODUCT_H3: |
| 38 |
if (cut_ver == PRR_PRODUCT_10) |
| 39 |
index = OLD_API_TABLE1; |
| 40 |
else if (cut_ver == PRR_PRODUCT_11) |
| 41 |
index = OLD_API_TABLE1; |
| 42 |
else if (cut_ver == PRR_PRODUCT_20) |
| 43 |
index = OLD_API_TABLE2; |
| 44 |
else |
| 45 |
/* Later than H3 Ver.2.0 */ |
| 46 |
index = NEW_API_TABLE; |
| 47 |
break; |
| 48 |
case PRR_PRODUCT_M3: |
| 49 |
if (cut_ver == PRR_PRODUCT_10) |
| 50 |
index = OLD_API_TABLE3; |
| 51 |
else |
| 52 |
/* M3 Ver.1.1 or later */ |
| 53 |
index = NEW_API_TABLE; |
| 54 |
break; |
| 55 |
case PRR_PRODUCT_V3M: |
| 56 |
if (cut_ver == PRR_PRODUCT_10) |
| 57 |
/* V3M WS1.0 */ |
| 58 |
index = NEW_API_TABLE2; |
| 59 |
else |
| 60 |
/* V3M WS2.0 or later */ |
| 61 |
index = NEW_API_TABLE; |
| 62 |
break; |
| 63 |
default: |
| 64 |
index = NEW_API_TABLE; |
| 65 |
break; |
| 66 |
} |
| 67 |
|
| 68 |
return index; |
| 69 |
} |
| 70 |
|
| 71 |
uint32_t rcar_rom_secure_boot_api(uint32_t key, uint32_t cert, |
| 72 |
rom_read_flash_f read_flash) |
| 73 |
{ |
| 74 |
static const uintptr_t rom_api_table[API_TABLE_MAX] = { |
| 75 |
0xEB10DD64U, /* H3 Ver.1.0/Ver.1.1 */ |
| 76 |
0xEB116ED4U, /* H3 Ver.2.0 */ |
| 77 |
0xEB1102FCU, /* M3 Ver.1.0 */ |
| 78 |
0xEB100180U, /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */ |
| 79 |
0xEB110128U, /* V3M WS1.0 */ |
| 80 |
}; |
| 81 |
rom_secure_boot_api_f secure_boot; |
| 82 |
uint32_t index; |
| 83 |
|
| 84 |
index = get_table_index(); |
| 85 |
secure_boot = (rom_secure_boot_api_f) rom_api_table[index]; |
| 86 |
|
| 87 |
return secure_boot(key, cert, read_flash); |
| 88 |
} |
| 89 |
|
| 90 |
uint32_t rcar_rom_get_lcs(uint32_t *lcs) |
| 91 |
{ |
| 92 |
static const uintptr_t rom_get_lcs_table[API_TABLE_MAX] = { |
| 93 |
0xEB10DFE0U, /* H3 Ver.1.0/Ver.1.1 */ |
| 94 |
0xEB117150U, /* H3 Ver.2.0 */ |
| 95 |
0xEB110578U, /* M3 Ver.1.0 */ |
| 96 |
0xEB10018CU, /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */ |
| 97 |
0xEB1103A4U, /* V3M WS1.0 */ |
| 98 |
}; |
| 99 |
rom_get_lcs_api_f get_lcs; |
| 100 |
uint32_t index; |
| 101 |
|
| 102 |
index = get_table_index(); |
| 103 |
get_lcs = (rom_get_lcs_api_f) rom_get_lcs_table[index]; |
| 104 |
|
| 105 |
return get_lcs(lcs); |
| 106 |
} |