Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 1 | /* |
Roberto Vargas | be126ed | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef IMG_PARSER_MOD_H |
| 8 | #define IMG_PARSER_MOD_H |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 9 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <drivers/auth/auth_common.h> |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | * Return values |
| 14 | */ |
| 15 | enum img_parser_ret_value { |
| 16 | IMG_PARSER_OK, |
| 17 | IMG_PARSER_ERR, /* Parser internal error */ |
| 18 | IMG_PARSER_ERR_FORMAT, /* Malformed image */ |
| 19 | IMG_PARSER_ERR_NOT_FOUND /* Authentication data not found */ |
| 20 | }; |
| 21 | |
| 22 | /* |
| 23 | * Image types. A parser should be instantiated and registered for each type |
| 24 | */ |
| 25 | typedef enum img_type_enum { |
| 26 | IMG_RAW, /* Binary image */ |
| 27 | IMG_PLAT, /* Platform specific format */ |
| 28 | IMG_CERT, /* X509v3 certificate */ |
| 29 | IMG_MAX_TYPES, |
| 30 | } img_type_t; |
| 31 | |
| 32 | /* Image parser library structure */ |
| 33 | typedef struct img_parser_lib_desc_s { |
| 34 | img_type_t img_type; |
| 35 | const char *name; |
| 36 | |
| 37 | void (*init)(void); |
| 38 | int (*check_integrity)(void *img, unsigned int img_len); |
| 39 | int (*get_auth_param)(const auth_param_type_desc_t *type_desc, |
| 40 | void *img, unsigned int img_len, |
| 41 | void **param, unsigned int *param_len); |
| 42 | } img_parser_lib_desc_t; |
| 43 | |
| 44 | /* Exported functions */ |
| 45 | void img_parser_init(void); |
| 46 | int img_parser_check_integrity(img_type_t img_type, |
Roberto Vargas | be126ed | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 47 | void *img_ptr, unsigned int img_len); |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 48 | int img_parser_get_auth_param(img_type_t img_type, |
| 49 | const auth_param_type_desc_t *type_desc, |
Roberto Vargas | be126ed | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 50 | void *img_ptr, unsigned int img_len, |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 51 | void **param_ptr, unsigned int *param_len); |
| 52 | |
| 53 | /* Macro to register an image parser library */ |
| 54 | #define REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param) \ |
| 55 | static const img_parser_lib_desc_t __img_parser_lib_desc_##_type \ |
Soren Brinkmann | 46dd170 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 56 | __section(".img_parser_lib_descs") __used = { \ |
Juan Castillo | 8e55d93 | 2015-04-02 09:48:16 +0100 | [diff] [blame] | 57 | .img_type = _type, \ |
| 58 | .name = _name, \ |
| 59 | .init = _init, \ |
| 60 | .check_integrity = _check_int, \ |
| 61 | .get_auth_param = _get_param \ |
| 62 | } |
| 63 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 64 | #endif /* IMG_PARSER_MOD_H */ |