1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "imagetool.h"
21#include <compiler.h>
22#include <image.h>
23#include "gpheader.h"
24
25
26void to_be32(uint32_t *gph_size, uint32_t *gph_load_addr)
27{
28 *gph_size = cpu_to_be32(*gph_size);
29 *gph_load_addr = cpu_to_be32(*gph_load_addr);
30}
31
32int gph_verify_header(struct gp_header *gph, int be)
33{
34 uint32_t gph_size = gph->size;
35 uint32_t gph_load_addr = gph->load_addr;
36
37 if (be)
38 to_be32(&gph_size, &gph_load_addr);
39
40 if (!gph_size || !gph_load_addr)
41 return -1;
42
43 return 0;
44}
45
46void gph_print_header(const struct gp_header *gph, int be)
47{
48 uint32_t gph_size = gph->size, gph_load_addr = gph->load_addr;
49
50 if (be)
51 to_be32(&gph_size, &gph_load_addr);
52
53 if (!gph_size) {
54 fprintf(stderr, "Error: invalid image size %x\n", gph_size);
55 exit(EXIT_FAILURE);
56 }
57
58 if (!gph_load_addr) {
59 fprintf(stderr, "Error: invalid image load address %x\n",
60 gph_load_addr);
61 exit(EXIT_FAILURE);
62 }
63 printf("GP Header: Size %x LoadAddr %x\n", gph_size, gph_load_addr);
64}
65
66void gph_set_header(struct gp_header *gph, uint32_t size, uint32_t load_addr,
67 int be)
68{
69 gph->size = size;
70 gph->load_addr = load_addr;
71 if (be)
72 to_be32(&gph->size, &gph->load_addr);
73}
74
75int gpimage_check_params(struct image_tool_params *params)
76{
77 return (params->dflag && (params->fflag || params->lflag)) ||
78 (params->fflag && (params->dflag || params->lflag)) ||
79 (params->lflag && (params->dflag || params->fflag));
80}
81