blob: 081818bb4a99b602f333c59be7d004c5cf1616a5 [file] [log] [blame]
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +05301/*
2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <dumpimage.h>
15#include <elf.h>
16#include <dirent.h>
17#include <sys/ioctl.h>
18#include <mtd/mtd-user.h>
19#include <limits.h>
20#include <linux/string.h>
21#include <linux/types.h>
22
23typedef enum {HLOS_TYPE, UBOOT_TYPE, SBL_TYPE, TZ_TYPE, RPM_TYPE}type;
24
25struct image_section {
26 type section_type;
27 int max_version;
28 char file[256];
29 char *type;
30 char tmp_file[256];
31 int img_version;
32 int local_version;
33 char *version_file;
34 int is_present;
35 int (*pre_op)(struct image_section *);
36 int (*get_sw_id)(struct image_section *);
37 int (*split_components)(struct image_section *, char **, char**, char**);
38};
39
40typedef struct mbn_header {
41 uint16_t image_id;
42 uint32_t ver_num;
43 uint32_t image_src;
44 uint8_t *image_dest_ptr;
45 uint32_t image_size;
46 uint32_t code_size;
47 uint8_t *sig_ptr;
48 uint32_t sig_sz;
49 uint8_t *cert_ptr;
50 uint32_t cert_sz;
51}Mbn_Hdr;
52
53struct ubi_ec_hdr {
54 __be32 magic;
55 __u8 version;
56 __u8 padding1[3];
57 __be64 ec; /* Warning: the current limit is 31-bit anyway! */
58 __be32 vid_hdr_offset;
59 __be32 data_offset;
60 __be32 image_seq;
61 __u8 padding2[32];
62 __be32 hdr_crc;
63};
64
65struct ubi_vid_hdr {
66 __be32 magic;
67 __u8 version;
68 __u8 vol_type;
69 __u8 copy_flag;
70 __u8 compat;
71 __be32 vol_id;
72 __be32 lnum;
73 __u8 padding1[4];
74 __be32 data_size;
75 __be32 used_ebs;
76 __be32 data_pad;
77 __be32 data_crc;
78 __u8 padding2[4];
79 __be64 sqnum;
80 __u8 padding3[12];
81 __be32 hdr_crc;
82};
83
84int get_sections(void);
85int is_authentication_check_enabled(void);
86int get_local_image_version(struct image_section *);
87int set_local_image_version(struct image_section *);
88int is_version_check_enabled(void);
89int get_sw_id_from_component_bin(struct image_section *);
90int get_sw_id_from_component_bin_elf(struct image_section *);
pavipfb8e3072017-10-12 14:47:47 +053091int get_sw_id_from_component_bin_elf64(struct image_section *);
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +053092int extract_kernel_binary(struct image_section *);
93int is_image_version_higher(void);
94int update_version(void);
95int check_image_version(void);
96int split_code_signature_cert_from_component_bin(struct image_section *, char **, char **, char **);
97int split_code_signature_cert_from_component_bin_elf(struct image_section *, char **, char **, char **);
pavipfb8e3072017-10-12 14:47:47 +053098int split_code_signature_cert_from_component_bin_elf64(struct image_section *, char **, char **, char **);
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +053099void generate_swid_ipad(char *, unsigned long long *);
100void generate_hwid_opad(char *, char *, char *, unsigned long long *);
101int generate_hash(char *, char *, char *);
102int is_component_authenticated(char *, char *, char *);
103int is_image_authenticated(void);
104int do_board_upgrade_check(char *);