1 /* 2 * Copyright (C) 2014 Andrew Duggan 3 * Copyright (C) 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 _RMI4UPDATE_H_ 19 #define _RMI4UPDATE_H_ 20 21 #include "rmidevice.h" 22 #include "firmware_image.h" 23 24 #define RMI_BOOTLOADER_ID_SIZE 2 25 26 // leon add 27 enum v7_status { 28 SUCCESS = 0x00, 29 DEVICE_NOT_IN_BOOTLOADER_MODE, 30 INVALID_PARTITION, 31 INVALID_COMMAND, 32 INVALID_BLOCK_OFFSET, 33 INVALID_TRANSFER, 34 NOT_ERASED, 35 FLASH_PROGRAMMING_KEY_INCORRECT, 36 BAD_PARTITION_TABLE, 37 CHECKSUM_FAILED, 38 WRITE_PROTECTION = 0x0E, 39 FLASH_HARDWARE_FAILURE = 0x1f, 40 }; 41 42 enum v7_partition_id { 43 NONE_PARTITION = 0x00, 44 BOOTLOADER_PARTITION = 0x01, 45 DEVICE_CONFIG_PARTITION, 46 FLASH_CONFIG_PARTITION, 47 MANUFACTURING_BLOCK_PARTITION, 48 GUEST_SERIALIZATION_PARTITION, 49 GLOBAL_PARAMETERS_PARTITION, 50 CORE_CODE_PARTITION, 51 CORE_CONFIG_PARTITION, 52 GUEST_CODE_PARTITION, 53 DISPLAY_CONFIG_PARTITION, 54 EXTERNAL_TOUCH_AFE_CONFIG_PARTITION, 55 UTILITY_PARAMETER_PARTITION, 56 FIXED_LOCATION_DATA_PARTITION = 0x0E, 57 }; 58 59 enum v7_flash_command { 60 CMD_V7_IDLE = 0x00, 61 CMD_V7_ENTER_BL, 62 CMD_V7_READ, 63 CMD_V7_WRITE, 64 CMD_V7_ERASE, 65 CMD_V7_ERASE_AP, 66 CMD_V7_SENSOR_ID, 67 CMD_V7_SIGNATURE, 68 }; 69 70 enum bl_version { 71 BL_V5 = 5, 72 BL_V6 = 6, 73 BL_V7 = 7, 74 BL_V8 = 8, 75 BL_V10 = 10, 76 }; 77 78 struct f34_v7_query_0 { 79 union { 80 struct { 81 unsigned char subpacket_1_size:3; 82 unsigned char has_config_id:1; 83 unsigned char f34_query0_b4:1; 84 unsigned char has_thqa:1; 85 unsigned char f34_query0_b6__7:2; 86 } __attribute__((packed));; 87 unsigned char data[1]; 88 }; 89 }; 90 91 struct f34_v7_query_1_7 { 92 union { 93 struct { 94 /* query 1 */ 95 unsigned char bl_minor_revision; 96 unsigned char bl_major_revision; 97 98 /* query 2 */ 99 unsigned char bl_fw_id_7_0; 100 unsigned char bl_fw_id_15_8; 101 unsigned char bl_fw_id_23_16; 102 unsigned char bl_fw_id_31_24; 103 104 /* query 3 */ 105 unsigned char minimum_write_size; 106 unsigned char block_size_7_0; 107 unsigned char block_size_15_8; 108 unsigned char flash_page_size_7_0; 109 unsigned char flash_page_size_15_8; 110 111 /* query 4 */ 112 unsigned char adjustable_partition_area_size_7_0; 113 unsigned char adjustable_partition_area_size_15_8; 114 115 /* query 5 */ 116 unsigned char flash_config_length_7_0; 117 unsigned char flash_config_length_15_8; 118 119 /* query 6 */ 120 unsigned char payload_length_7_0; 121 unsigned char payload_length_15_8; 122 123 /* query 7 */ 124 unsigned char f34_query7_b0:1; 125 unsigned char has_bootloader:1; 126 unsigned char has_device_config:1; 127 unsigned char has_flash_config:1; 128 unsigned char has_manufacturing_block:1; 129 unsigned char has_guest_serialization:1; 130 unsigned char has_global_parameters:1; 131 unsigned char has_core_code:1; 132 unsigned char has_core_config:1; 133 unsigned char has_guest_code:1; 134 unsigned char has_display_config:1; 135 unsigned char f34_query7_b11_13:3; 136 unsigned char has_fld:1; 137 unsigned char f34_query7_b15:1; 138 unsigned char f34_query7_b16__23; 139 unsigned char f34_query7_b24__31; 140 } __attribute__((packed));; 141 unsigned char data[21]; 142 }; 143 }; 144 145 struct partition_tbl 146 { 147 union { 148 struct { 149 unsigned short partition_id; 150 unsigned short partition_len; 151 unsigned short partition_addr; 152 unsigned short partition_prop; 153 } __attribute__((packed));; 154 unsigned char data[8]; 155 }; 156 }; 157 // leon end 158 159 class RMI4Update 160 { 161 public: RMI4Update(RMIDevice & device,FirmwareImage & firmwareImage)162 RMI4Update(RMIDevice & device, FirmwareImage & firmwareImage) : m_device(device), 163 m_firmwareImage(firmwareImage), m_writeBlockWithCmd(true) 164 { 165 m_IsErased = false; 166 m_hasCoreCode = false; 167 m_hasCoreConfig = false; 168 m_hasFlashConfig = false; 169 m_hasFLD = false; 170 m_hasGlobalParameters = false; 171 } 172 int UpdateFirmware(bool force = false, bool performLockdown = false); 173 174 private: 175 int DisableNonessentialInterupts(); 176 int FindUpdateFunctions(); 177 int ReadFlashConfig(); 178 int rmi4update_poll(); 179 int ReadF34QueriesV7(); 180 int ReadF34Queries(); 181 int ReadF34Controls(); 182 int WriteBootloaderID(); 183 int EnterFlashProgrammingV7(); 184 int EraseFirmwareV7(); 185 int EraseFlashConfigV10(); 186 int EraseCoreCodeV10(); 187 int WriteFirmwareV7(); 188 int WriteCoreConfigV7(); 189 int WriteFlashConfigV7(); 190 int WriteFLDV7(); 191 int WriteGlobalParametersV7(); 192 int EnterFlashProgramming(); 193 int WriteBlocks(unsigned char *block, unsigned short count, unsigned char cmd); 194 int WaitForIdle(int timeout_ms, bool readF34OnSucess = true); GetFirmwareSize()195 int GetFirmwareSize() { return m_blockSize * m_fwBlockCount; } GetConfigSize()196 int GetConfigSize() { return m_blockSize * m_configBlockCount; } 197 int WriteSignatureV7(enum signature_BLv7 signature_partition, unsigned char* data, int offset); 198 bool IsBLv87(); 199 int ReadMSL(); 200 201 private: 202 RMIDevice & m_device; 203 FirmwareImage & m_firmwareImage; 204 205 RMIFunction m_f01; 206 RMIFunction m_f34; 207 208 unsigned char m_deviceStatus; 209 unsigned char m_bootloaderID[RMI_BOOTLOADER_ID_SIZE]; 210 bool m_writeBlockWithCmd; 211 212 /* F34 Controls */ 213 unsigned char m_f34Command; 214 unsigned char m_f34Status; 215 bool m_programEnabled; 216 217 /* F34 Query */ 218 bool m_hasNewRegmap; 219 bool m_unlocked; 220 bool m_hasConfigID; 221 unsigned short m_blockSize; 222 unsigned short m_fwBlockCount; 223 unsigned short m_configBlockCount; 224 /* for BL_V7 */ 225 unsigned short m_flashConfigLength; 226 unsigned short m_payloadLength; 227 unsigned short m_guestBlockCount; 228 struct partition_tbl *m_partitionCore; 229 struct partition_tbl *m_partitionConfig; 230 struct partition_tbl *m_partitionGuest; 231 unsigned char m_flashStatus; 232 unsigned char m_flashCmd; 233 unsigned char m_inBLmode; 234 unsigned long m_buildID; 235 unsigned char *m_guestData; 236 bool m_hasCoreCode; 237 bool m_hasCoreConfig; 238 bool m_hasFlashConfig; 239 bool m_hasGlobalParameters; 240 /* BL_V7 end */ 241 242 /* BL v8.7 */ 243 unsigned short m_MSL; 244 /* BL v8.7 end */ 245 246 /* for BL V10 */ 247 bool m_hasFLD; 248 /* BL_V7 end */ 249 250 unsigned short m_f34StatusAddr; 251 enum bl_version m_blVersion; 252 253 bool m_IsErased; 254 }; 255 256 #endif // _RMI4UPDATE_H_ 257