blob: 17c6e62ccb63652de355b15db126f8bd7821ca71 [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
Ram Chandra Jangirf40cda92017-10-16 10:08:42 +053085typedef struct {
86 uint32_t codeword;
87 uint32_t magic;
88 uint32_t RESERVED_0;
89 uint32_t RESERVED_1;
90 uint32_t RESERVED_2;
91 uint32_t image_src;
92 uint8_t *image_dest_ptr;
93 uint32_t image_size;
94 uint32_t code_size;
95 uint8_t *sig_ptr;
96 uint32_t sig_size;
97 uint8_t *cert_ptr;
98 uint32_t cert_size;
99 uint32_t root_cert_sel;
100 uint32_t num_root_certs;
101 uint32_t RESERVED_5;
102 uint32_t RESERVED_6;
103 uint32_t RESERVED_7;
104 uint32_t RESERVED_8;
105 uint32_t RESERVED_9;
106} Sbl_Hdr;
107
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +0530108int get_sections(void);
109int is_authentication_check_enabled(void);
110int get_local_image_version(struct image_section *);
111int set_local_image_version(struct image_section *);
112int is_version_check_enabled(void);
113int get_sw_id_from_component_bin(struct image_section *);
114int get_sw_id_from_component_bin_elf(struct image_section *);
pavipfb8e3072017-10-12 14:47:47 +0530115int get_sw_id_from_component_bin_elf64(struct image_section *);
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +0530116int extract_kernel_binary(struct image_section *);
117int is_image_version_higher(void);
118int update_version(void);
119int check_image_version(void);
120int split_code_signature_cert_from_component_bin(struct image_section *, char **, char **, char **);
121int split_code_signature_cert_from_component_bin_elf(struct image_section *, char **, char **, char **);
pavipfb8e3072017-10-12 14:47:47 +0530122int split_code_signature_cert_from_component_bin_elf64(struct image_section *, char **, char **, char **);
Sachin Sundar1ed5f5b2017-03-28 17:34:42 +0530123void generate_swid_ipad(char *, unsigned long long *);
124void generate_hwid_opad(char *, char *, char *, unsigned long long *);
125int generate_hash(char *, char *, char *);
126int is_component_authenticated(char *, char *, char *);
127int is_image_authenticated(void);
128int do_board_upgrade_check(char *);
Ram Chandra Jangir62928dc2018-02-01 16:23:46 +0530129int check_nand_preamble(uint8_t *);
Naresh Kumar Mehta488a6132019-04-05 17:41:16 +0530130int find_mtd_part_size(void);