Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <lib/mmio.h> |
| 10 | |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 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 */ |
Marek Vasut | 29da69b | 2019-01-05 14:07:55 +0100 | [diff] [blame] | 22 | #define NEW_API_TABLE (3U) /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3 */ |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 23 | #define API_TABLE_MAX (4U) /* table max */ |
| 24 | /* Later than H3 Ver.2.0 */ |
| 25 | |
| 26 | static uint32_t get_table_index(void) |
| 27 | { |
| 28 | uint32_t product; |
| 29 | uint32_t cut_ver; |
| 30 | uint32_t index; |
| 31 | |
| 32 | product = mmio_read_32(RCAR_PRR) & RCAR_PRODUCT_MASK; |
| 33 | cut_ver = mmio_read_32(RCAR_PRR) & RCAR_CUT_MASK; |
| 34 | |
| 35 | switch (product) { |
| 36 | case RCAR_PRODUCT_H3: |
| 37 | if (cut_ver == RCAR_CUT_VER10) |
| 38 | index = OLD_API_TABLE1; |
| 39 | else if (cut_ver == RCAR_CUT_VER11) |
| 40 | index = OLD_API_TABLE1; |
| 41 | else if (cut_ver == RCAR_CUT_VER20) |
| 42 | index = OLD_API_TABLE2; |
| 43 | else |
| 44 | /* Later than H3 Ver.2.0 */ |
| 45 | index = NEW_API_TABLE; |
| 46 | break; |
| 47 | case RCAR_PRODUCT_M3: |
| 48 | if (cut_ver == RCAR_CUT_VER10) |
| 49 | index = OLD_API_TABLE3; |
| 50 | else |
| 51 | /* M3 Ver.1.1 or later */ |
| 52 | index = NEW_API_TABLE; |
| 53 | break; |
| 54 | default: |
| 55 | index = NEW_API_TABLE; |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | return index; |
| 60 | } |
| 61 | |
| 62 | uint32_t rcar_rom_secure_boot_api(uint32_t *key, uint32_t *cert, |
| 63 | rom_read_flash_f read_flash) |
| 64 | { |
| 65 | static const uintptr_t rom_api_table[API_TABLE_MAX] = { |
| 66 | 0xEB10DD64U, /* H3 Ver.1.0/Ver.1.1 */ |
| 67 | 0xEB116ED4U, /* H3 Ver.2.0 */ |
| 68 | 0xEB1102FCU, /* M3 Ver.1.0 */ |
Marek Vasut | 29da69b | 2019-01-05 14:07:55 +0100 | [diff] [blame] | 69 | 0xEB100180U /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3 */ |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 70 | }; |
| 71 | rom_secure_boot_api_f secure_boot; |
| 72 | uint32_t index; |
| 73 | |
| 74 | index = get_table_index(); |
| 75 | secure_boot = (rom_secure_boot_api_f) rom_api_table[index]; |
| 76 | |
| 77 | return secure_boot(key, cert, read_flash); |
| 78 | } |
| 79 | |
| 80 | uint32_t rcar_rom_get_lcs(uint32_t *lcs) |
| 81 | { |
| 82 | static const uintptr_t rom_get_lcs_table[API_TABLE_MAX] = { |
| 83 | 0xEB10DFE0U, /* H3 Ver.1.0/Ver.1.1 */ |
| 84 | 0xEB117150U, /* H3 Ver.2.0 */ |
| 85 | 0xEB110578U, /* M3 Ver.1.0 */ |
Marek Vasut | 29da69b | 2019-01-05 14:07:55 +0100 | [diff] [blame] | 86 | 0xEB10018CU /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3 */ |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 87 | }; |
| 88 | rom_get_lcs_api_f get_lcs; |
| 89 | uint32_t index; |
| 90 | |
| 91 | index = get_table_index(); |
| 92 | get_lcs = (rom_get_lcs_api_f) rom_get_lcs_table[index]; |
| 93 | |
| 94 | return get_lcs(lcs); |
| 95 | } |