Home | History | Annotate | Download | only in rmi4update
      1 /*
      2  * Copyright (C) 2012 - 2014 Andrew Duggan
      3  * Copyright (C) 2012 - 2014 Synaptics Inc
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 #ifndef _FIRMWAREIMAGE_H_
     19 #define _FIRMWAREIMAGE_H_
     20 
     21 #include "rmidevice.h"
     22 #include "updateutil.h"
     23 
     24 #define RMI_IMG_CHECKSUM_OFFSET			0
     25 #define RMI_IMG_IO_OFFSET			0x06
     26 #define RMI_IMG_BOOTLOADER_VERSION_OFFSET	0x07
     27 #define RMI_IMG_IMAGE_SIZE_OFFSET		0x08
     28 #define RMI_IMG_CONFIG_SIZE_OFFSET		0x0C
     29 #define RMI_IMG_PACKAGE_ID_OFFSET		0x1A
     30 #define RMI_IMG_FW_BUILD_ID_OFFSET		0x50
     31 
     32 #define RMI_IMG_PRODUCT_ID_OFFSET		0x10
     33 #define RMI_IMG_PRODUCT_INFO_OFFSET		0x1E
     34 
     35 #define RMI_IMG_FW_OFFSET			0x100
     36 
     37 #define RMI_IMG_LOCKDOWN_V2_OFFSET		0xD0
     38 #define RMI_IMG_LOCKDOWN_V2_SIZE		0x30
     39 
     40 #define RMI_IMG_LOCKDOWN_V3_OFFSET		0xC0
     41 #define RMI_IMG_LOCKDOWN_V3_SIZE		0x40
     42 
     43 #define RMI_IMG_LOCKDOWN_V5_OFFSET		0xB0
     44 #define RMI_IMG_LOCKDOWN_V5_SIZE		0x50
     45 
     46 class FirmwareImage
     47 {
     48 public:
     49 	FirmwareImage() : m_firmwareBuildID(0), m_packageID(0), m_firmwareData(NULL), m_configData(NULL), m_lockdownData(NULL),
     50 				m_memBlock(NULL)
     51 	{}
     52 	int Initialize(const char * filename);
     53 	int VerifyImageMatchesDevice(unsigned long deviceFirmwareSize,
     54 					unsigned long deviceConfigSize);
     55 	unsigned char * GetFirmwareData() { return m_firmwareData; }
     56 	unsigned char * GetConfigData() { return m_configData; }
     57 	unsigned char * GetLockdownData() { return m_lockdownData; }
     58 	unsigned long GetFirmwareSize() { return m_firmwareSize; }
     59 	unsigned long GetConfigSize() { return m_configSize; }
     60 	unsigned long GetLockdownSize() { return m_lockdownSize; }
     61 	unsigned long GetFirmwareID() { return m_firmwareBuildID; }
     62 	bool HasIO() { return m_io; }
     63 	~FirmwareImage();
     64 
     65 private:
     66 	unsigned long Checksum(unsigned short * data, unsigned long len);
     67 	void PrintHeaderInfo();
     68 
     69 private:
     70 	unsigned long m_checksum;
     71 	unsigned long m_firmwareSize;
     72 	unsigned long m_configSize;
     73 	unsigned long m_lockdownSize;
     74 	long m_imageSize;
     75 	unsigned long m_firmwareBuildID;
     76 	unsigned short m_packageID;
     77 	unsigned char m_bootloaderVersion;
     78 	unsigned char m_io;
     79 	char m_productID[RMI_PRODUCT_ID_LENGTH + 1];
     80 	unsigned short m_productInfo;
     81 
     82 	unsigned char * m_firmwareData;
     83 	unsigned char * m_configData;
     84 	unsigned char * m_lockdownData;
     85 	unsigned char * m_memBlock;
     86 };
     87 
     88 #endif // _FIRMWAREIMAGE_H_
     89