blob: 347ed621cf149d99ccb569e473ca894287ef5d4c [file] [log] [blame]
Juan Castillo8e55d932015-04-02 09:48:16 +01001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo8e55d932015-04-02 09:48:16 +01005 */
6
7#ifndef __IMG_PARSER_MOD_H__
8#define __IMG_PARSER_MOD_H__
9
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,
47 void *img, unsigned int img_len);
48int img_parser_get_auth_param(img_type_t img_type,
49 const auth_param_type_desc_t *type_desc,
50 void *img, unsigned int img_len,
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 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
64#endif /* __IMG_PARSER_MOD_H__ */