1 /*
2  * Copyright (C) 2014 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef IFWI_VERSION_CHECK_H
18 #define IFWI_VERSION_CHECK_H
19 
20 #include <stdint.h>
21 
22 struct fw_version {
23 	uint16_t major;
24 	uint16_t minor;
25 };
26 
27 struct firmware_versions {
28 	struct fw_version scubootstrap;
29 	struct fw_version scu;
30 	struct fw_version ia32;
31 	struct fw_version valhooks;
32 	struct fw_version ifwi;
33 	struct fw_version chaabi;
34 	struct fw_version mia;
35 };
36 
37 /* Query the SCU for current firmware versions and populate
38  * the fields in v. Returns nonzero on error */
39 int get_current_fw_rev(struct firmware_versions *v);
40 
41 /* Assuming data points to a blob of memory containing an IFWI
42  * firmware image, inpsect the FIP header inside it and
43  * populate the fields in v. Returns nonzero on error */
44 int get_image_fw_rev(void *data, unsigned sz, struct firmware_versions *v);
45 
46 /* Compare versions v1 and v2, and return -1, 1, or 0 if v1 is less than,
47  * greater than, or equal to v2, respectively */
48 int fw_vercmp(struct firmware_versions *v1, struct firmware_versions *v2);
49 
50 /* Crack ifwi firmware file */
51 int crack_update_fw(const char *fw_file, struct fw_version *ifwi_version);
52 
53 /* Crack ifwi firmware file to get the PTI Field. */
54 int crack_update_fw_pti_field(const char *fw_file, uint8_t * pti_field);
55 
56 #endif
57