Merge tag 'u-boot-stm32-20220617' of https://source.denx.de/u-boot/custodians/u-boot-stm
[platform/kernel/u-boot.git] / tools / gpimage.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2014
4  * Texas Instruments Incorporated
5  * Add gpimage format for keystone devices to format spl image. This is
6  * Based on omapimage.c
7  *
8  * (C) Copyright 2010
9  * Linaro LTD, www.linaro.org
10  * Author: John Rigby <john.rigby@linaro.org>
11  * Based on TI's signGP.c
12  *
13  * (C) Copyright 2009
14  * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
15  *
16  * (C) Copyright 2008
17  * Marvell Semiconductor <www.marvell.com>
18  * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
19  */
20
21 #include "imagetool.h"
22 #include <compiler.h>
23 #include <image.h>
24 #include "gpheader.h"
25
26 static uint8_t gpimage_header[GPIMAGE_HDR_SIZE];
27
28 /* to be in keystone gpimage */
29 static int gpimage_check_image_types(uint8_t type)
30 {
31         if (type == IH_TYPE_GPIMAGE)
32                 return EXIT_SUCCESS;
33         return EXIT_FAILURE;
34 }
35
36 static int gpimage_verify_header(unsigned char *ptr, int image_size,
37                         struct image_tool_params *params)
38 {
39         struct gp_header *gph = (struct gp_header *)ptr;
40
41         return gph_verify_header(gph, 1);
42 }
43
44 static void gpimage_print_header(const void *ptr)
45 {
46         const struct gp_header *gph = (struct gp_header *)ptr;
47
48         gph_print_header(gph, 1);
49 }
50
51 static void gpimage_set_header(void *ptr, struct stat *sbuf, int ifd,
52                                 struct image_tool_params *params)
53 {
54         struct gp_header *gph = (struct gp_header *)ptr;
55
56         gph_set_header(gph, sbuf->st_size - GPIMAGE_HDR_SIZE, params->addr, 1);
57 }
58
59 /*
60  * gpimage parameters
61  */
62 U_BOOT_IMAGE_TYPE(
63         gpimage,
64         "TI KeyStone GP Image support",
65         GPIMAGE_HDR_SIZE,
66         (void *)&gpimage_header,
67         gpimage_check_params,
68         gpimage_verify_header,
69         gpimage_print_header,
70         gpimage_set_header,
71         NULL,
72         gpimage_check_image_types,
73         NULL,
74         NULL
75 );