blob: 1e53ff8baa17699db9e80ab19beea110db628128 [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
Pavithra Palanisamya3924182017-10-26 14:43:10 +053023typedef enum {HLOS_TYPE, UBOOT_TYPE, SBL_TYPE, TZ_TYPE, RPM_TYPE, DEVCFG_TYPE}type;
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +053024
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;
Avinash Pandeybcfcba72018-01-19 13:07:54 +053035 char *img_code;
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +053036 int (*pre_op)(struct image_section *);
37 int (*get_sw_id)(struct image_section *);
38 int (*split_components)(struct image_section *, char **, char**, char**);
39};
40
41typedef struct mbn_header {
Pavithra Palanisamy0e3043f2017-09-14 19:45:05 +053042 uint32_t image_id;
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +053043 uint32_t ver_num;
44 uint32_t image_src;
45 uint8_t *image_dest_ptr;
46 uint32_t image_size;
47 uint32_t code_size;
48 uint8_t *sig_ptr;
49 uint32_t sig_sz;
50 uint8_t *cert_ptr;
51 uint32_t cert_sz;
52}Mbn_Hdr;
53
54struct ubi_ec_hdr {
55 __be32 magic;
56 __u8 version;
57 __u8 padding1[3];
58 __be64 ec; /* Warning: the current limit is 31-bit anyway! */
59 __be32 vid_hdr_offset;
60 __be32 data_offset;
61 __be32 image_seq;
62 __u8 padding2[32];
63 __be32 hdr_crc;
64};
65
66struct ubi_vid_hdr {
67 __be32 magic;
68 __u8 version;
69 __u8 vol_type;
70 __u8 copy_flag;
71 __u8 compat;
72 __be32 vol_id;
73 __be32 lnum;
74 __u8 padding1[4];
75 __be32 data_size;
76 __be32 used_ebs;
77 __be32 data_pad;
78 __be32 data_crc;
79 __u8 padding2[4];
80 __be64 sqnum;
81 __u8 padding3[12];
82 __be32 hdr_crc;
83};
84
85int get_sections(void);
86int is_authentication_check_enabled(void);
87int get_local_image_version(struct image_section *);
88int set_local_image_version(struct image_section *);
89int is_version_check_enabled(void);
90int get_sw_id_from_component_bin(struct image_section *);
91int get_sw_id_from_component_bin_elf(struct image_section *);
pavipfb8e3072017-10-12 14:47:47 +053092int get_sw_id_from_component_bin_elf64(struct image_section *);
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +053093int extract_kernel_binary(struct image_section *);
94int is_image_version_higher(void);
95int update_version(void);
96int check_image_version(void);
97int split_code_signature_cert_from_component_bin(struct image_section *, char **, char **, char **);
98int split_code_signature_cert_from_component_bin_elf(struct image_section *, char **, char **, char **);
pavipfb8e3072017-10-12 14:47:47 +053099int split_code_signature_cert_from_component_bin_elf64(struct image_section *, char **, char **, char **);
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +0530100void generate_swid_ipad(char *, unsigned long long *);
101void generate_hwid_opad(char *, char *, char *, unsigned long long *);
102int generate_hash(char *, char *, char *);
103int is_component_authenticated(char *, char *, char *);
104int is_image_authenticated(void);
105int do_board_upgrade_check(char *);