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