xref: /rk3399_ARM-atf/include/drivers/auth/img_parser_mod.h (revision 9a207532f8216bf83fed0891fed9ed0bc72ca450)
105799ae0SJuan Castillo /*
2735181b6SRoberto Vargas  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
305799ae0SJuan Castillo  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
505799ae0SJuan Castillo  */
605799ae0SJuan Castillo 
7c3cf06f1SAntonio Nino Diaz #ifndef IMG_PARSER_MOD_H
8c3cf06f1SAntonio Nino Diaz #define IMG_PARSER_MOD_H
905799ae0SJuan Castillo 
10*09d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_common.h>
1105799ae0SJuan Castillo 
1205799ae0SJuan Castillo /*
1305799ae0SJuan Castillo  * Return values
1405799ae0SJuan Castillo  */
1505799ae0SJuan Castillo enum img_parser_ret_value {
1605799ae0SJuan Castillo 	IMG_PARSER_OK,
1705799ae0SJuan Castillo 	IMG_PARSER_ERR,			/* Parser internal error */
1805799ae0SJuan Castillo 	IMG_PARSER_ERR_FORMAT,		/* Malformed image */
1905799ae0SJuan Castillo 	IMG_PARSER_ERR_NOT_FOUND	/* Authentication data not found */
2005799ae0SJuan Castillo };
2105799ae0SJuan Castillo 
2205799ae0SJuan Castillo /*
2305799ae0SJuan Castillo  * Image types. A parser should be instantiated and registered for each type
2405799ae0SJuan Castillo  */
2505799ae0SJuan Castillo typedef enum img_type_enum {
2605799ae0SJuan Castillo 	IMG_RAW,			/* Binary image */
2705799ae0SJuan Castillo 	IMG_PLAT,			/* Platform specific format */
2805799ae0SJuan Castillo 	IMG_CERT,			/* X509v3 certificate */
2905799ae0SJuan Castillo 	IMG_MAX_TYPES,
3005799ae0SJuan Castillo } img_type_t;
3105799ae0SJuan Castillo 
3205799ae0SJuan Castillo /* Image parser library structure */
3305799ae0SJuan Castillo typedef struct img_parser_lib_desc_s {
3405799ae0SJuan Castillo 	img_type_t img_type;
3505799ae0SJuan Castillo 	const char *name;
3605799ae0SJuan Castillo 
3705799ae0SJuan Castillo 	void (*init)(void);
3805799ae0SJuan Castillo 	int (*check_integrity)(void *img, unsigned int img_len);
3905799ae0SJuan Castillo 	int (*get_auth_param)(const auth_param_type_desc_t *type_desc,
4005799ae0SJuan Castillo 			void *img, unsigned int img_len,
4105799ae0SJuan Castillo 			void **param, unsigned int *param_len);
4205799ae0SJuan Castillo } img_parser_lib_desc_t;
4305799ae0SJuan Castillo 
4405799ae0SJuan Castillo /* Exported functions */
4505799ae0SJuan Castillo void img_parser_init(void);
4605799ae0SJuan Castillo int img_parser_check_integrity(img_type_t img_type,
47735181b6SRoberto Vargas 		void *img_ptr, unsigned int img_len);
4805799ae0SJuan Castillo int img_parser_get_auth_param(img_type_t img_type,
4905799ae0SJuan Castillo 		const auth_param_type_desc_t *type_desc,
50735181b6SRoberto Vargas 		void *img_ptr, unsigned int img_len,
5105799ae0SJuan Castillo 		void **param_ptr, unsigned int *param_len);
5205799ae0SJuan Castillo 
5305799ae0SJuan Castillo /* Macro to register an image parser library */
5405799ae0SJuan Castillo #define REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param) \
5505799ae0SJuan Castillo 	static const img_parser_lib_desc_t __img_parser_lib_desc_##_type \
5665cd299fSSoren Brinkmann 	__section(".img_parser_lib_descs") __used = { \
5705799ae0SJuan Castillo 		.img_type = _type, \
5805799ae0SJuan Castillo 		.name = _name, \
5905799ae0SJuan Castillo 		.init = _init, \
6005799ae0SJuan Castillo 		.check_integrity = _check_int, \
6105799ae0SJuan Castillo 		.get_auth_param = _get_param \
6205799ae0SJuan Castillo 	}
6305799ae0SJuan Castillo 
64c3cf06f1SAntonio Nino Diaz #endif /* IMG_PARSER_MOD_H */
65