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 FLASH_HARDWARE_FAILURE = 0x1f, 39 }; 40 41 enum v7_partition_id { 42 NONE_PARTITION = 0x00, 43 BOOTLOADER_PARTITION = 0x01, 44 DEVICE_CONFIG_PARTITION, 45 FLASH_CONFIG_PARTITION, 46 MANUFACTURING_BLOCK_PARTITION, 47 GUEST_SERIALIZATION_PARTITION, 48 GLOBAL_PARAMETERS_PARTITION, 49 CORE_CODE_PARTITION, 50 CORE_CONFIG_PARTITION, 51 GUEST_CODE_PARTITION, 52 DISPLAY_CONFIG_PARTITION, 53 EXTERNAL_TOUCH_AFE_CONFIG_PARTITION, 54 UTILITY_PARAMETER_PARTITION, 55 }; 56 57 enum v7_flash_command { 58 CMD_V7_IDLE = 0x00, 59 CMD_V7_ENTER_BL, 60 CMD_V7_READ, 61 CMD_V7_WRITE, 62 CMD_V7_ERASE, 63 CMD_V7_ERASE_AP, 64 CMD_V7_SENSOR_ID, 65 }; 66 67 enum bl_version { 68 BL_V5 = 5, 69 BL_V6 = 6, 70 BL_V7 = 7, 71 BL_V8 = 8, 72 }; 73 74 struct f34_v7_query_0 { 75 union { 76 struct { 77 unsigned char subpacket_1_size:3; 78 unsigned char has_config_id:1; 79 unsigned char f34_query0_b4:1; 80 unsigned char has_thqa:1; 81 unsigned char f34_query0_b6__7:2; 82 } __attribute__((packed));; 83 unsigned char data[1]; 84 }; 85 }; 86 87 struct f34_v7_query_1_7 { 88 union { 89 struct { 90 /* query 1 */ 91 unsigned char bl_minor_revision; 92 unsigned char bl_major_revision; 93 94 /* query 2 */ 95 unsigned char bl_fw_id_7_0; 96 unsigned char bl_fw_id_15_8; 97 unsigned char bl_fw_id_23_16; 98 unsigned char bl_fw_id_31_24; 99 100 /* query 3 */ 101 unsigned char minimum_write_size; 102 unsigned char block_size_7_0; 103 unsigned char block_size_15_8; 104 unsigned char flash_page_size_7_0; 105 unsigned char flash_page_size_15_8; 106 107 /* query 4 */ 108 unsigned char adjustable_partition_area_size_7_0; 109 unsigned char adjustable_partition_area_size_15_8; 110 111 /* query 5 */ 112 unsigned char flash_config_length_7_0; 113 unsigned char flash_config_length_15_8; 114 115 /* query 6 */ 116 unsigned char payload_length_7_0; 117 unsigned char payload_length_15_8; 118 119 /* query 7 */ 120 unsigned char f34_query7_b0:1; 121 unsigned char has_bootloader:1; 122 unsigned char has_device_config:1; 123 unsigned char has_flash_config:1; 124 unsigned char has_manufacturing_block:1; 125 unsigned char has_guest_serialization:1; 126 unsigned char has_global_parameters:1; 127 unsigned char has_core_code:1; 128 unsigned char has_core_config:1; 129 unsigned char has_guest_code:1; 130 unsigned char has_display_config:1; 131 unsigned char f34_query7_b11__15:5; 132 unsigned char f34_query7_b16__23; 133 unsigned char f34_query7_b24__31; 134 } __attribute__((packed));; 135 unsigned char data[21]; 136 }; 137 }; 138 139 struct partition_tbl 140 { 141 union { 142 struct { 143 unsigned short partition_id; 144 unsigned short partition_len; 145 unsigned short partition_addr; 146 unsigned short partition_prop; 147 } __attribute__((packed));; 148 unsigned char data[8]; 149 }; 150 }; 151 // leon end 152 153 class RMI4Update 154 { 155 public: RMI4Update(RMIDevice & device,FirmwareImage & firmwareImage)156 RMI4Update(RMIDevice & device, FirmwareImage & firmwareImage) : m_device(device), 157 m_firmwareImage(firmwareImage), m_writeBlockWithCmd(true) 158 { 159 m_IsErased = false; 160 } 161 int UpdateFirmware(bool force = false, bool performLockdown = false); 162 163 private: 164 int DisableNonessentialInterupts(); 165 int FindUpdateFunctions(); 166 int ReadFlashConfig(); 167 int rmi4update_poll(); 168 int ReadF34QueriesV7(); 169 int ReadF34Queries(); 170 int ReadF34Controls(); 171 int WriteBootloaderID(); 172 int EnterFlashProgrammingV7(); 173 int EraseFirmwareV7(); 174 int WriteFirmwareV7(); 175 int WriteCoreConfigV7(); 176 int WriteFlashConfigV7(); 177 int EnterFlashProgramming(); 178 int WriteBlocks(unsigned char *block, unsigned short count, unsigned char cmd); 179 int WaitForIdle(int timeout_ms, bool readF34OnSucess = true); GetFirmwareSize()180 int GetFirmwareSize() { return m_blockSize * m_fwBlockCount; } GetConfigSize()181 int GetConfigSize() { return m_blockSize * m_configBlockCount; } 182 183 private: 184 RMIDevice & m_device; 185 FirmwareImage & m_firmwareImage; 186 187 RMIFunction m_f01; 188 RMIFunction m_f34; 189 190 unsigned char m_deviceStatus; 191 unsigned char m_bootloaderID[RMI_BOOTLOADER_ID_SIZE]; 192 bool m_writeBlockWithCmd; 193 194 /* F34 Controls */ 195 unsigned char m_f34Command; 196 unsigned char m_f34Status; 197 bool m_programEnabled; 198 199 /* F34 Query */ 200 bool m_hasNewRegmap; 201 bool m_unlocked; 202 bool m_hasConfigID; 203 unsigned short m_blockSize; 204 unsigned short m_fwBlockCount; 205 unsigned short m_configBlockCount; 206 /* for BL_V7 */ 207 unsigned short m_flashConfigLength; 208 unsigned short m_payloadLength; 209 unsigned short m_guestBlockCount; 210 struct partition_tbl *m_partitionCore; 211 struct partition_tbl *m_partitionConfig; 212 struct partition_tbl *m_partitionGuest; 213 unsigned char m_flashStatus; 214 unsigned char m_flashCmd; 215 unsigned char m_inBLmode; 216 unsigned long m_buildID; 217 unsigned char *m_guestData; 218 /* BL_V7 end */ 219 220 unsigned short m_f34StatusAddr; 221 enum bl_version m_blVersion; 222 223 bool m_IsErased; 224 }; 225 226 #endif // _RMI4UPDATE_H_ 227