blob: 7950e4cfe7d7f67ad19d863af4d20dbe3fb7d392 [file] [log] [blame]
Andrew Duggan052556f2014-04-16 11:32:30 -07001/*
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
Andrew Duggan4e811252014-04-03 15:17:57 -070018#include "updateutil.h"
19
20const char *update_error_str[] = {
21 "success", // UPDATE_SUCCESS
22 "failed", // UPDATE_FAIL
23 "timeout", // UPDATE_FAIL_TIMEOUT
24 "invalid firmware image", // UPDATE_FAIL_VERIFY_IMAGE
25 "checksum does not match image", // UPDATE_FAIL_VERIFY_CHECKSUM
26 "image firmware size does not match device", // UPDATE_FAIL_VERIFY_FIRMWARE_SIZE
27 "image config size does not match device", // UPDATE_FAIL_VERIFY_CONFIG_SIZE
28 "image version is unsupported", // UPDATE_FAIL_UNSUPPORTED_IMAGE_VERSION
29 "failed to find F01 on device", // UPDATE_FAIL_NO_FUNCTION_01
30 "failed to find F34 on device", // UPDATE_FAIL_NO_FUNCTION_34
31 "failed to query the basic properties in F01", // UPDATE_FAIL_QUERY_BASIC_PROPERTIES
32 "failed to read F34 query registers", // UPDATE_FAIL_READ_F34_QUERIES
33 "failed to read the bootloader id", // UPDATE_FAIL_READ_BOOTLOADER_ID
34 "failed to read F34 control registers", // UPDATE_FAIL_READ_F34_CONTROLS
35 "failed to write the bootloader id", // UPDATE_FAIL_WRITE_BOOTLOADER_ID
36 "failed to enable flash programming", // UPDATE_FAIL_ENABLE_FLASH_PROGRAMMING
37 "failed to reach idle state", // UPDATE_FAIL_NOT_IN_IDLE_STATE
38 "programming is not enabled", // UPDATE_FAIL_PROGRAMMING_NOT_ENABLED
39 "failed to scan the PDT", // UPDATE_FAIL_SCAN_PDT
40 "failed to read the device status", // UPDATE_FAIL_READ_DEVICE_STATUS
41 "device not in the bootloader after enabling programming", // UPDATE_FAIL_DEVICE_NOT_IN_BOOTLOADER
42 "failed to read F01 control 0 register", // UPDATE_FAIL_READ_F01_CONTROL_0
43 "failed to write F01 control 0 register", // UPDATE_FAIL_WRITE_F01_CONTROL_0
44 "failed to write initial zeros", // UPDATE_FAIL_WRITE_INITIAL_ZEROS
45 "failed to write block", // UPDATE_FAIL_WRITE_BLOCK
46 "failed to write the flash command", // UPDATE_FAIL_WRITE_FLASH_COMMAND
Andrew Duggan62137912014-05-06 16:06:19 -070047 "timeout waiting for attn", // UPDATE_FAIL_TIMEOUT_WAITING_FOR_ATTN
Andrew Duggan4e811252014-04-03 15:17:57 -070048 "failed to write erase all command", // UPDATE_FAIL_ERASE_ALL
49 "the firmware image is older then the firmware on the device", // UPDATE_FAIL_FIRMWARE_IMAGE_IS_OLDER
50 "invalid parameter", // UPDATE_FAIL_INVALID_PARAMETER
51 "failed to open firmware image file", // UPDATE_FAIL_OPEN_FIRMWARE_IMAGE
52};
53
54const char * update_err_to_string(int err)
55{
56 return update_error_str[err];
57}
58
59unsigned long extract_long(const unsigned char *data)
60{
61 return (unsigned long)data [0]
62 + (unsigned long)data [1] * 0x100
63 + (unsigned long)data [2] * 0x10000
64 + (unsigned long)data [3] * 0x1000000;
65}
66
67unsigned short extract_short(const unsigned char *data)
68{
69 return (unsigned long)data [0]
70 + (unsigned long)data [1] * 0x100;
71}