blob: 43796935a65e9fa09e982f2660ff21b1e3b0bc5a [file] [log] [blame]
Juan Castillo8e55d932015-04-02 09:48:16 +01001/*
Roberto Vargasbe126ed2018-02-12 12:36:17 +00002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Juan Castillo8e55d932015-04-02 09:48:16 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo8e55d932015-04-02 09:48:16 +01005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef IMG_PARSER_MOD_H
8#define IMG_PARSER_MOD_H
Juan Castillo8e55d932015-04-02 09:48:16 +01009
10#include <auth_common.h>
11
12/*
13 * Return values
14 */
15enum 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 */
25typedef 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 */
33typedef 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 */
45void img_parser_init(void);
46int img_parser_check_integrity(img_type_t img_type,
Roberto Vargasbe126ed2018-02-12 12:36:17 +000047 void *img_ptr, unsigned int img_len);
Juan Castillo8e55d932015-04-02 09:48:16 +010048int img_parser_get_auth_param(img_type_t img_type,
49 const auth_param_type_desc_t *type_desc,
Roberto Vargasbe126ed2018-02-12 12:36:17 +000050 void *img_ptr, unsigned int img_len,
Juan Castillo8e55d932015-04-02 09:48:16 +010051 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 Brinkmann46dd1702016-01-14 10:11:05 -080056 __section(".img_parser_lib_descs") __used = { \
Juan Castillo8e55d932015-04-02 09:48:16 +010057 .img_type = _type, \
58 .name = _name, \
59 .init = _init, \
60 .check_integrity = _check_int, \
61 .get_auth_param = _get_param \
62 }
63
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000064#endif /* IMG_PARSER_MOD_H */