diff options
Diffstat (limited to 'util/ecst.c')
-rw-r--r-- | util/ecst.c | 876 |
1 files changed, 345 insertions, 531 deletions
diff --git a/util/ecst.c b/util/ecst.c index 8d0ce940d6..2c3150c34a 100644 --- a/util/ecst.c +++ b/util/ecst.c @@ -1,5 +1,5 @@ /* - * Copyright 2015 The Chromium OS Authors. All rights reserved. + * Copyright 2015 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -39,20 +39,21 @@ int is_mrider15 = FALSE; /* Chips information, RAM start address and RAM size. */ struct chip_info chip_info[] = { - [NPCX5M5G] = {NPCX5M5G_RAM_ADDR, NPCX5M5G_RAM_SIZE}, - [NPCX5M6G] = {NPCX5M6G_RAM_ADDR, NPCX5M6G_RAM_SIZE}, - [NPCX7M5] = {NPCX7M5X_RAM_ADDR, NPCX7M5X_RAM_SIZE}, - [NPCX7M6] = {NPCX7M6X_RAM_ADDR, NPCX7M6X_RAM_SIZE}, - [NPCX7M7] = {NPCX7M7X_RAM_ADDR, NPCX7M7X_RAM_SIZE}, - [NPCX9M3] = {NPCX9M3X_RAM_ADDR, NPCX9M3X_RAM_SIZE}, - [NPCX9M6] = {NPCX9M6X_RAM_ADDR, NPCX9M6X_RAM_SIZE}, + [NPCX5M5G] = { NPCX5M5G_RAM_ADDR, NPCX5M5G_RAM_SIZE }, + [NPCX5M6G] = { NPCX5M6G_RAM_ADDR, NPCX5M6G_RAM_SIZE }, + [NPCX7M5] = { NPCX7M5X_RAM_ADDR, NPCX7M5X_RAM_SIZE }, + [NPCX7M6] = { NPCX7M6X_RAM_ADDR, NPCX7M6X_RAM_SIZE }, + [NPCX7M7] = { NPCX7M7X_RAM_ADDR, NPCX7M7X_RAM_SIZE }, + [NPCX9M3] = { NPCX9M3X_RAM_ADDR, NPCX9M3X_RAM_SIZE }, + [NPCX9M6] = { NPCX9M6X_RAM_ADDR, NPCX9M6X_RAM_SIZE }, }; BUILD_ASSERT(ARRAY_SIZE(chip_info) == NPCX_CHIP_RAM_VAR_NONE); /* Support chips name strings */ -const char *supported_chips = "npcx5m5g, npcx5m6g, npcx7m5g, npcx7m6g, " - "npcx7m6f, npcx7m6fb, npcx7m6fc, npcx7m7fc, npcx7m7wb, " - "npcx7m7wc, npcx9m3f or npcx9m6f"; +const char *supported_chips = + "npcx5m5g, npcx5m6g, npcx7m5g, npcx7m6g, " + "npcx7m6f, npcx7m6fb, npcx7m6fc, npcx7m7fc, npcx7m7wb, " + "npcx7m7wc, npcx9m3f or npcx9m6f"; static unsigned int calc_api_csum_bin(void); static unsigned int initialize_crc_32(void); @@ -70,16 +71,17 @@ static unsigned int finalize_crc_32(unsigned int crc); * and returns FALSE. */ static int splice_into_path(char *result, const char *path, int resultsz, - const char *prefix) { + const char *prefix) +{ char *last_delim, *result_last_delim; if (strlen(path) + strlen(prefix) + 1 > resultsz) { my_printf(TERR, - "\n\nfilename '%s' with prefix '%s' too long\n\n", - path, prefix); + "\n\nfilename '%s' with prefix '%s' too long\n\n", + path, prefix); my_printf(TINF, - "\n\n%zu + %zu + 1 needs to fit in %d bytes\n\n", - strlen(path), strlen(prefix), resultsz); + "\n\n%zu + %zu + 1 needs to fit in %d bytes\n\n", + strlen(path), strlen(prefix), resultsz); return FALSE; } @@ -124,7 +126,7 @@ static enum npcx_chip_ram_variant chip_to_ram_var(const char *chip_name) else if (str_cmp_no_case(chip_name, "npcx7m6fc") == 0) return NPCX7M6; else if (str_cmp_no_case(chip_name, "npcx7m6g") == 0) - return NPCX7M6; + return NPCX7M6; else if (str_cmp_no_case(chip_name, "npcx7m5g") == 0) return NPCX7M5; else if (str_cmp_no_case(chip_name, "npcx5m6g") == 0) @@ -149,7 +151,6 @@ static enum npcx_chip_ram_variant chip_to_ram_var(const char *chip_name) int main(int argc, char *argv[]) { - int mode_choose = FALSE; /* Do we get a bin File? */ int main_fw_hdr_flag = FALSE; @@ -160,7 +161,7 @@ int main(int argc, char *argv[]) /* Following variables: common to all modes */ int main_status = TRUE; - unsigned int main_temp = 0L; + unsigned int main_temp = 0L; char main_str_temp[TMP_STR_SIZE]; char *end_ptr; @@ -189,17 +190,15 @@ int main(int argc, char *argv[]) g_verbose = NO_VERBOSE; g_ram_start_address = chip_info[DEFAULT_CHIP].ram_addr; - g_ram_size = chip_info[DEFAULT_CHIP].ram_size; + g_ram_size = chip_info[DEFAULT_CHIP].ram_size; /* Set default values */ g_calc_type = CALC_TYPE_NONE; bin_params.spi_max_clk = SPI_MAX_CLOCK_DEFAULT; bin_params.spi_clk_ratio = 0x00; bin_params.spi_read_mode = SPI_READ_MODE_DEFAULT; - bin_params.fw_load_addr = - chip_info[DEFAULT_CHIP].ram_addr; - bin_params.fw_ep = - chip_info[DEFAULT_CHIP].ram_addr; + bin_params.fw_load_addr = chip_info[DEFAULT_CHIP].ram_addr; + bin_params.fw_ep = chip_info[DEFAULT_CHIP].ram_addr; bin_params.fw_err_detec_s_addr = FW_CRC_START_ADDR; bin_params.fw_err_detec_e_addr = FW_CRC_START_ADDR; bin_params.flash_size = FLASH_SIZE_DEFAULT; @@ -234,20 +233,18 @@ int main(int argc, char *argv[]) else if (str_cmp_no_case(hdr_args[arg_ind], "-vv") == 0) g_verbose = SUPER_VERBOSE; - else if (str_cmp_no_case(hdr_args[arg_ind], - "-mode") == 0) { + else if (str_cmp_no_case(hdr_args[arg_ind], "-mode") == 0) { mode_choose = TRUE; arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%s", main_str_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%s", main_str_temp) != + 1)) { my_printf(TERR, "\nCannot read operation mode"); my_printf(TERR, ", bt, bh or api. !\n"); main_status = FALSE; } else { /* bt, bh and api should not coexist */ - if (main_fw_hdr_flag || - main_api_flag || + if (main_fw_hdr_flag || main_api_flag || main_hdr_flag) { my_printf(TERR, "\nOperation modes bt"); my_printf(TERR, ", bh, and api should"); @@ -257,8 +254,8 @@ int main(int argc, char *argv[]) if (str_cmp_no_case(main_str_temp, "bt") == 0) main_fw_hdr_flag = TRUE; - else if (str_cmp_no_case(main_str_temp, - "bh") == 0) + else if (str_cmp_no_case(main_str_temp, "bh") == + 0) main_hdr_flag = TRUE; else if (str_cmp_no_case(main_str_temp, "api") == 0) @@ -266,8 +263,8 @@ int main(int argc, char *argv[]) else { my_printf(TERR, "\nInvalid operation mode "); - my_printf(TERR, - "(%s)\n", main_str_temp); + my_printf(TERR, "(%s)\n", + main_str_temp); main_status = FALSE; } } @@ -276,11 +273,10 @@ int main(int argc, char *argv[]) else if (str_cmp_no_case(hdr_args[arg_ind], "-chip") == 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%s", - main_str_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%s", main_str_temp) != + 1)) { my_printf(TERR, "\nCannot read chip name %s.\n", - supported_chips); + supported_chips); main_status = FALSE; } else { enum npcx_chip_ram_variant ram_variant; @@ -291,41 +287,38 @@ int main(int argc, char *argv[]) "\nInvalid chip name (%s) ", main_str_temp); my_printf(TERR, ", it should be %s.\n", - supported_chips); + supported_chips); main_status = FALSE; break; } - if ((bin_params.bin_params - & BIN_FW_LOAD_START_ADDR) == - 0x00000000) + if ((bin_params.bin_params & + BIN_FW_LOAD_START_ADDR) == 0x00000000) bin_params.fw_load_addr = - chip_info[ram_variant].ram_addr; + chip_info[ram_variant].ram_addr; - if ((bin_params.bin_params - & BIN_FW_ENTRY_POINT) == - 0x00000000) + if ((bin_params.bin_params & + BIN_FW_ENTRY_POINT) == 0x00000000) bin_params.fw_ep = - chip_info[ram_variant].ram_addr; + chip_info[ram_variant].ram_addr; g_ram_start_address = chip_info[ram_variant].ram_addr; - g_ram_size = - chip_info[ram_variant].ram_size; + g_ram_size = chip_info[ram_variant].ram_size; if ((ram_variant == NPCX5M5G) || - (ram_variant == NPCX5M6G)) { + (ram_variant == NPCX5M6G)) { is_mrider15 = TRUE; } } - /* -argfile Read argument file. File name must be after it.*/ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-argfile") == 0) { + /* -argfile Read argument file. File name must be after + * it.*/ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-argfile") == + 0) { arg_ind++; if (arg_ind < arg_num) { - strncpy(arg_file_name, - hdr_args[arg_ind], - sizeof(arg_file_name) - 1); + strncpy(arg_file_name, hdr_args[arg_ind], + sizeof(arg_file_name) - 1); arg_file_pointer = fopen(arg_file_name, "rt"); if (arg_file_pointer == NULL) { my_printf(TERR, @@ -340,16 +333,15 @@ int main(int argc, char *argv[]) (tmp_ind + arg_ind + 1) < arg_num; tmp_ind++) strncpy(tmp_hdr_args[tmp_ind], - hdr_args - [tmp_ind+arg_ind+1], + hdr_args[tmp_ind + + arg_ind + 1], ARG_SIZE); tmp_arg_num = tmp_ind; /* Read arguments from file to array */ for (arg_ind++; - fscanf(arg_file_pointer, - "%s", + fscanf(arg_file_pointer, "%s", hdr_args[arg_ind]) == 1; arg_ind++) ; @@ -359,9 +351,9 @@ int main(int argc, char *argv[]) /* Copy back the restored arguments. */ for (tmp_ind = 0; - (tmp_ind < tmp_arg_num) && - (arg_ind < MAX_ARGS); - tmp_ind++) { + (tmp_ind < tmp_arg_num) && + (arg_ind < MAX_ARGS); + tmp_ind++) { strncpy(hdr_args[arg_ind++], tmp_hdr_args[tmp_ind], ARG_SIZE); @@ -379,120 +371,113 @@ int main(int argc, char *argv[]) } else if (str_cmp_no_case(hdr_args[arg_ind], "-i") == 0) { arg_ind++; if (arg_ind < arg_num) { - strncpy(input_file_name, - hdr_args[arg_ind], - sizeof(input_file_name) - 1); + strncpy(input_file_name, hdr_args[arg_ind], + sizeof(input_file_name) - 1); } else { my_printf(TERR, "\nMissing Input File Name\n"); main_status = FALSE; } - /* -o Get output file name. */ + /* -o Get output file name. */ } else if (str_cmp_no_case(hdr_args[arg_ind], "-o") == 0) { arg_ind++; if (arg_ind < arg_num) { - strncpy(output_file_name, - hdr_args[arg_ind], + strncpy(output_file_name, hdr_args[arg_ind], sizeof(output_file_name) - 1); } else { my_printf(TERR, "\nMissing Output File Name.\n"); main_status = FALSE; } - /* -usearmrst get FW entry point from FW image offset 4.*/ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-usearmrst") == 0) { - if ((bin_params.bin_params & - BIN_FW_ENTRY_POINT) != 0x00000000) { + /* -usearmrst get FW entry point from FW image + * offset 4.*/ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-usearmrst") == + 0) { + if ((bin_params.bin_params & BIN_FW_ENTRY_POINT) != + 0x00000000) { my_printf(TERR, "\n-usearmrst not allowed, "); my_printf(TERR, "FW entry point already set "); my_printf(TERR, "using -fwep !\n"); main_status = FALSE; } else - bin_params.bin_params |= - BIN_FW_USER_ARM_RESET; - /* -nohcrs disable header CRC*/ + bin_params.bin_params |= BIN_FW_USER_ARM_RESET; + /* -nohcrs disable header CRC*/ } else if (str_cmp_no_case(hdr_args[arg_ind], "-nohcrc") == 0) - bin_params.bin_params |= - BIN_FW_HDR_CRC_DISABLE; + bin_params.bin_params |= BIN_FW_HDR_CRC_DISABLE; /* -ph merg header in BIN file. */ else if (str_cmp_no_case(hdr_args[arg_ind], "-ph") == 0) { - bin_params.bin_params |= - BIN_FW_HDR_OFFSET; - if ((strlen(hdr_args[arg_ind+1]) == 0) || - (sscanf(hdr_args[arg_ind+1], - "%x", - &main_temp) != 1)) + bin_params.bin_params |= BIN_FW_HDR_OFFSET; + if ((strlen(hdr_args[arg_ind + 1]) == 0) || + (sscanf(hdr_args[arg_ind + 1], "%x", &main_temp) != + 1)) bin_params.fw_hdr_offset = 0; else { arg_ind++; bin_params.fw_hdr_offset = main_temp; } - /* -spimaxclk Get SPI flash max clock. */ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-spimaxclk") == 0) { + /* -spimaxclk Get SPI flash max clock. */ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-spimaxclk") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%d", &main_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%d", &main_temp) != + 1)) { my_printf(TERR, "\nCannot read SPI Flash Max"); my_printf(TERR, " Clock !\n"); main_status = FALSE; } else bin_params.spi_max_clk = - (unsigned char) main_temp; - /* -spiclkratio Get SPI flash max clock ratio. */ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-spiclkratio") == 0) { + (unsigned char)main_temp; + /* -spiclkratio Get SPI flash max clock ratio. */ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-spiclkratio") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%d", &main_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%d", &main_temp) != + 1)) { my_printf(TERR, "\nCannot read SPI Clock Ratio\n"); main_status = FALSE; } else bin_params.spi_clk_ratio = - (unsigned char)main_temp; + (unsigned char)main_temp; - /* spireadmode get SPI read mode. */ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-spireadmode") == 0) { + /* spireadmode get SPI read mode. */ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-spireadmode") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%20s", - main_str_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%20s", main_str_temp) != + 1)) { my_printf(TERR, "\nCannot read SPI Flash"); my_printf(TERR, " Read Mode !\n"); main_status = FALSE; } else { if (str_cmp_no_case(main_str_temp, - SPI_NORMAL_MODE_VAL) == 0) + SPI_NORMAL_MODE_VAL) == 0) bin_params.spi_read_mode = - (unsigned char) SPI_NORMAL_MODE; + (unsigned char)SPI_NORMAL_MODE; else if (str_cmp_no_case(main_str_temp, - SPI_SINGLE_MODE_VAL) == 0) + SPI_SINGLE_MODE_VAL) == + 0) bin_params.spi_read_mode = - (unsigned char) - SPI_SINGLE_MODE; + (unsigned char)SPI_SINGLE_MODE; else if (str_cmp_no_case(main_str_temp, - SPI_DUAL_MODE_VAL) == 0) + SPI_DUAL_MODE_VAL) == + 0) bin_params.spi_read_mode = - (unsigned char) - SPI_DUAL_MODE; + (unsigned char)SPI_DUAL_MODE; else if (str_cmp_no_case(main_str_temp, - SPI_QUAD_MODE_VAL) == 0) + SPI_QUAD_MODE_VAL) == + 0) bin_params.spi_read_mode = - (unsigned char) - SPI_QUAD_MODE; + (unsigned char)SPI_QUAD_MODE; else { my_printf(TERR, "\nInvalid SPI Flash Read "); my_printf(TERR, "Mode (%s), it should be ", main_str_temp); - my_printf(TERR, - "normal, singleMode, "); + my_printf(TERR, "normal, singleMode, "); my_printf(TERR, "dualMode or quadMode !\n"); main_status = FALSE; @@ -508,95 +493,88 @@ int main(int argc, char *argv[]) bin_params.bin_params |= BIN_FW_CRC_DISABLE; /* -fwloadaddr, Get the FW load address. */ - else if (str_cmp_no_case(hdr_args[arg_ind], - "-fwloadaddr") == 0) { + else if (str_cmp_no_case(hdr_args[arg_ind], "-fwloadaddr") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%x", - &main_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%x", &main_temp) != + 1)) { my_printf(TERR, "\nCannot read FW Load "); my_printf(TERR, "\nstart address !\n"); main_status = FALSE; } else { /* Check that the address is 16-bytes aligned */ - if ((main_temp & - ADDR_16_BYTES_ALIGNED_MASK) != 0) { + if ((main_temp & ADDR_16_BYTES_ALIGNED_MASK) != + 0) { my_printf(TERR, "\nFW load address start "); my_printf(TERR, "address (0x%08X) is not ", main_temp); - my_printf(TERR, - "16-bytes aligned !\n"); + my_printf(TERR, "16-bytes aligned !\n"); main_status = FALSE; } else { - bin_params.fw_load_addr = - main_temp; + bin_params.fw_load_addr = main_temp; bin_params.bin_params |= - BIN_FW_LOAD_START_ADDR; + BIN_FW_LOAD_START_ADDR; } } - /* -fwep, Get the FW entry point. */ + /* -fwep, Get the FW entry point. */ } else if (str_cmp_no_case(hdr_args[arg_ind], "-fwep") == 0) { - if ((bin_params.bin_params & BIN_FW_USER_ARM_RESET) - != 0x00000000) { - my_printf(TERR, - "\n-fwep not allowed, FW entry point"); + if ((bin_params.bin_params & BIN_FW_USER_ARM_RESET) != + 0x00000000) { + my_printf( + TERR, + "\n-fwep not allowed, FW entry point"); my_printf(TERR, " already set using -usearmrst!\n"); main_status = FALSE; } else { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%x", - &main_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%x", + &main_temp) != 1)) { my_printf(TERR, "\nCan't read FW E-Point\n"); main_status = FALSE; } else { - bin_params.fw_ep = - main_temp; + bin_params.fw_ep = main_temp; bin_params.bin_params |= - BIN_FW_ENTRY_POINT; + BIN_FW_ENTRY_POINT; } } - /* - * -crcstart, Get the address from where to calculate - * the FW CRC. - */ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-crcstart") == 0) { + /* + * -crcstart, Get the address from where to calculate + * the FW CRC. + */ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-crcstart") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%x", - &main_temp) != 1)) { - my_printf(TERR, - "\nCannot read FW CRC"); - my_printf(TERR, - " start address !\n"); + (sscanf(hdr_args[arg_ind], "%x", &main_temp) != + 1)) { + my_printf(TERR, "\nCannot read FW CRC"); + my_printf(TERR, " start address !\n"); main_status = FALSE; } else { bin_params.fw_err_detec_e_addr = bin_params.fw_err_detec_e_addr - - bin_params.fw_err_detec_s_addr - + main_temp; - bin_params.fw_err_detec_s_addr = - main_temp; + bin_params.fw_err_detec_s_addr + + main_temp; + bin_params.fw_err_detec_s_addr = main_temp; bin_params.bin_params |= BIN_FW_CKS_START; } - /* -crcsize, Get the area size that need to be CRCed. */ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-crcsize") == 0) { + /* -crcsize, Get the area size that need to be CRCed. + */ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-crcsize") == + 0) { arg_ind++; main_temp = 0x00; if (hdr_args[arg_ind] == NULL) end_ptr = NULL; else - main_temp = strtol(hdr_args[arg_ind], - &end_ptr, 16); + main_temp = + strtol(hdr_args[arg_ind], &end_ptr, 16); if (hdr_args[arg_ind] == end_ptr) { my_printf(TERR, @@ -604,8 +582,8 @@ int main(int argc, char *argv[]) main_status = FALSE; } else { bin_params.fw_err_detec_e_addr = - bin_params.fw_err_detec_s_addr - + main_temp - 1; + bin_params.fw_err_detec_s_addr + + main_temp - 1; bin_params.bin_params |= BIN_FW_CKS_SIZE; } } @@ -613,9 +591,8 @@ int main(int argc, char *argv[]) else if (str_cmp_no_case(hdr_args[arg_ind], "-fwlen") == 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%x", - &main_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%x", &main_temp) != + 1)) { my_printf(TERR, "\nCannot read FW length !\n"); main_status = FALSE; } else { @@ -624,25 +601,24 @@ int main(int argc, char *argv[]) } } /* flashsize, Get the flash size. */ - else if (str_cmp_no_case(hdr_args[arg_ind], - "-flashsize") == 0) { + else if (str_cmp_no_case(hdr_args[arg_ind], "-flashsize") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%d", - &main_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%d", &main_temp) != + 1)) { my_printf(TERR, "\nCannot read Flash size !\n"); main_status = FALSE; } else bin_params.flash_size = main_temp; - /* -apisign, Get the method for error detect calculation. */ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-apisign") == 0) { + /* -apisign, Get the method for error detect + * calculation. */ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-apisign") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%s", - main_str_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%s", main_str_temp) != + 1)) { my_printf(TERR, "\nCannot read API sign, CRC,"); my_printf(TERR, " CheckSum or None. !\n"); main_status = FALSE; @@ -666,23 +642,21 @@ int main(int argc, char *argv[]) main_str_temp); main_status = FALSE; } - } - /* -pointer, Get the FW image address. */ - } else if (str_cmp_no_case(hdr_args[arg_ind], - "-pointer") == 0) { + /* -pointer, Get the FW image address. */ + } else if (str_cmp_no_case(hdr_args[arg_ind], "-pointer") == + 0) { arg_ind++; if ((hdr_args[arg_ind] == NULL) || - (sscanf(hdr_args[arg_ind], - "%x", - &main_temp) != 1)) { + (sscanf(hdr_args[arg_ind], "%x", &main_temp) != + 1)) { my_printf(TERR, "\nCannot read FW Image address !\n"); main_status = FALSE; } else { /* Check that the address is 16-bytes aligned */ - if ((main_temp & ADDR_16_BYTES_ALIGNED_MASK) - != 0) { + if ((main_temp & ADDR_16_BYTES_ALIGNED_MASK) != + 0) { my_printf(TERR, "\nFW Image address (0x%08X)" " isn't 16-bytes aligned !\n", @@ -696,8 +670,7 @@ int main(int argc, char *argv[]) main_temp); my_printf(TERR, "is higher from flash size"); - my_printf(TERR, - " (0x%08X) !\n", + my_printf(TERR, " (0x%08X) !\n", MAX_FLASH_SIZE); main_status = FALSE; } else { @@ -713,8 +686,8 @@ int main(int argc, char *argv[]) if (hdr_args[arg_ind] == NULL) end_ptr = NULL; else - main_temp = strtol(hdr_args[arg_ind], - &end_ptr, 16); + main_temp = + strtol(hdr_args[arg_ind], &end_ptr, 16); if (hdr_args[arg_ind] == end_ptr) { my_printf(TERR, "\nCannot read BootLoader"); @@ -722,11 +695,12 @@ int main(int argc, char *argv[]) main_status = FALSE; } else { /* Check that the address is 16-bytes aligned */ - if ((main_temp & ADDR_16_BYTES_ALIGNED_MASK) - != 0) { - my_printf(TERR, - "\nFW Image address (0x%08X) ", - main_temp); + if ((main_temp & ADDR_16_BYTES_ALIGNED_MASK) != + 0) { + my_printf( + TERR, + "\nFW Image address (0x%08X) ", + main_temp); my_printf(TERR, "is not 16-bytes aligned!\n"); } @@ -737,8 +711,7 @@ int main(int argc, char *argv[]) main_temp); my_printf(TERR, " is higher from flash size"); - my_printf(TERR, - " (0x%08X) !\n", + my_printf(TERR, " (0x%08X) !\n", MAX_FLASH_SIZE); main_status = FALSE; } else { @@ -747,27 +720,25 @@ int main(int argc, char *argv[]) } } } else { - my_printf(TERR, - "\nUnknown flag: %s\n", + my_printf(TERR, "\nUnknown flag: %s\n", hdr_args[arg_ind]); main_status = FALSE; } } /* - * If the input and output file have the same name then exit with error. - */ + * If the input and output file have the same name then exit with error. + */ if (strcmp(output_file_name, input_file_name) == 0) { my_printf(TINF, - "Input file name (%s) should be differed from\n", - input_file_name); + "Input file name (%s) should be differed from\n", + input_file_name); my_printf(TINF, "Output file name (%s).\n", output_file_name); main_status = FALSE; } /* No problems reading argv? So go on... */ if (main_status) { - /* if output file already exist, then delete it. */ tmp_file = fopen(output_file_name, "w"); if (tmp_file != NULL) @@ -802,18 +773,17 @@ int main(int argc, char *argv[]) /* Say Bye Bye */ if (main_status) { my_printf(TPAS, "\n\n******************************"); - my_printf(TPAS, "\n*** SUCCESS ***"); - my_printf(TPAS, "\n******************************\n"); + my_printf(TPAS, "\n*** SUCCESS ***"); + my_printf(TPAS, "\n******************************\n"); exit(EXIT_SUCCESS); } else { my_printf(TERR, "\n\n******************************"); - my_printf(TERR, "\n*** FAILED ***"); - my_printf(TERR, "\n******************************\n"); + my_printf(TERR, "\n*** FAILED ***"); + my_printf(TERR, "\n******************************\n"); exit(EXIT_FAILURE); } - } /* @@ -930,12 +900,9 @@ void exit_with_usage(void) * Description: Copy the source file to the end of the destination file. *-------------------------------------------------------------------------- */ -int copy_file_to_file(char *dst_file_name, - char *src_file_name, - int offset, - int origin) +int copy_file_to_file(char *dst_file_name, char *src_file_name, int offset, + int origin) { - int index = 0; int result = 0; unsigned char local_val; @@ -1030,12 +997,9 @@ void my_printf(int error_level, char *fmt, ...) * Description: Writes to ELF or BIN files - whatever is open *-------------------------------------------------------------------------- */ -int write_to_file(unsigned int write_value, - unsigned int offset, - unsigned char num_of_bytes, - char *print_string) +int write_to_file(unsigned int write_value, unsigned int offset, + unsigned char num_of_bytes, char *print_string) { - int result = 0; int index; unsigned int localValue4; @@ -1046,32 +1010,23 @@ int write_to_file(unsigned int write_value, return FALSE; switch (num_of_bytes) { - case(1): + case (1): localValue1 = (unsigned char)write_value; - result = (int)(fwrite(&localValue1, 1, - 1, g_hfd_pointer)); - break; - case(2): + result = (int)(fwrite(&localValue1, 1, 1, g_hfd_pointer)); + break; + case (2): localValue2 = (unsigned short)write_value; - result = (int)(fwrite(&localValue2, - 2, - 1, - g_hfd_pointer)); + result = (int)(fwrite(&localValue2, 2, 1, g_hfd_pointer)); break; - case(4): + case (4): localValue4 = write_value; - result = (int)(fwrite(&localValue4, - 4, - 1, - g_hfd_pointer)); + result = (int)(fwrite(&localValue4, 4, 1, g_hfd_pointer)); break; default: /* Pad the same value N times. */ localValue1 = (unsigned char)write_value; for (index = 0; index < num_of_bytes; index++) - result = (int)(fwrite(&localValue1, - 1, - 1, + result = (int)(fwrite(&localValue1, 1, 1, g_hfd_pointer)); break; } @@ -1079,18 +1034,15 @@ int write_to_file(unsigned int write_value, my_printf(TINF, "\nIn write_to_file - %s", print_string); if (result) { - my_printf(TINF, - " - Offset %2d - value 0x%x", - offset, write_value); + my_printf(TINF, " - Offset %2d - value 0x%x", offset, + write_value); } else { - my_printf(TERR, - "\n\nCouldn't write %x to file at %x\n\n", - write_value, offset); + my_printf(TERR, "\n\nCouldn't write %x to file at %x\n\n", + write_value, offset); return FALSE; } return TRUE; - } /* @@ -1101,10 +1053,8 @@ int write_to_file(unsigned int write_value, * Description : Reads from open BIN file *-------------------------------------------------------------------------- */ -int read_from_file(unsigned int offset, - unsigned char size_to_read, - unsigned int *read_value, - char *print_string) +int read_from_file(unsigned int offset, unsigned char size_to_read, + unsigned int *read_value, char *print_string) { int result; unsigned int localValue4; @@ -1115,25 +1065,16 @@ int read_from_file(unsigned int offset, return FALSE; switch (size_to_read) { - case(1): - result = (int)(fread(&localValue1, - 1, - 1, - input_file_pointer)); + case (1): + result = (int)(fread(&localValue1, 1, 1, input_file_pointer)); *read_value = localValue1; break; - case(2): - result = (int)(fread(&localValue2, - 2, - 1, - input_file_pointer)); + case (2): + result = (int)(fread(&localValue2, 2, 1, input_file_pointer)); *read_value = localValue2; break; - case(4): - result = (int)(fread(&localValue4, - 4, - 1, - input_file_pointer)); + case (4): + result = (int)(fread(&localValue4, 4, 1, input_file_pointer)); *read_value = localValue4; break; default: @@ -1145,13 +1086,10 @@ int read_from_file(unsigned int offset, my_printf(TINF, "\nIn read_from_file - %s", print_string); if (result) { - my_printf(TINF, - " - Offset %d - value %x", - offset, *read_value); + my_printf(TINF, " - Offset %d - value %x", offset, *read_value); } else { - my_printf(TERR, - "\n\nCouldn't read from file at %x\n\n", - offset); + my_printf(TERR, "\n\nCouldn't read from file at %x\n\n", + offset); return FALSE; } @@ -1210,12 +1148,11 @@ void finalize_calculation(unsigned int *check_sum_crc) * given the previous checksum\crc *-------------------------------------------------------------------------- */ -void update_calculation(unsigned int *check_sum_crc, - unsigned char byte_to_add) +void update_calculation(unsigned int *check_sum_crc, unsigned char byte_to_add) { switch (g_calc_type) { case CALC_TYPE_NONE: - /* Do nothing */ + /* Do nothing */ break; case CALC_TYPE_CHECKSUM: *check_sum_crc += byte_to_add; @@ -1328,25 +1265,22 @@ int main_bin(struct tbinparams binary_params) bin_fw_offset = binary_params.fw_hdr_offset + HEADER_SIZE; my_printf(TINF, "\nBIN file: %s, size: %d (0x%x) bytes\n", - input_file_name, - bin_file_size_bytes, - bin_file_size_bytes); + input_file_name, bin_file_size_bytes, bin_file_size_bytes); /* Check validity of FW header offset. */ if (((int)binary_params.fw_hdr_offset < 0) || - (binary_params.fw_hdr_offset > bin_file_size_bytes)) { + (binary_params.fw_hdr_offset > bin_file_size_bytes)) { my_printf(TERR, "\nFW header offset 0x%08x (%d) should be in the" " range of 0 and file size (%d).\n", binary_params.fw_hdr_offset, - binary_params.fw_hdr_offset, - bin_file_size_bytes); + binary_params.fw_hdr_offset, bin_file_size_bytes); return FALSE; } /* Create the header file in the same directory as the input file. */ if (!splice_into_path(g_hdr_input_name, input_file_name, - sizeof(g_hdr_input_name), "hdr_")) + sizeof(g_hdr_input_name), "hdr_")) return FALSE; g_hfd_pointer = fopen(g_hdr_input_name, "w+b"); if (g_hfd_pointer == NULL) { @@ -1356,7 +1290,7 @@ int main_bin(struct tbinparams binary_params) if (strlen(output_file_name) == 0) { if (!splice_into_path(output_file_name, input_file_name, - sizeof(output_file_name), "out_")) + sizeof(output_file_name), "out_")) return FALSE; } @@ -1368,15 +1302,12 @@ int main_bin(struct tbinparams binary_params) ********************************************************************* */ /* Write the ancore. */ - if (!write_to_file(FW_HDR_ANCHOR, - HDR_ANCHOR_OFFSET, - 4, + if (!write_to_file(FW_HDR_ANCHOR, HDR_ANCHOR_OFFSET, 4, "HDR - FW Header ANCHOR ")) return FALSE; /* Write the extended anchor. */ if (binary_params.bin_params & BIN_FW_HDR_CRC_DISABLE) { - /* Write the ancore and the extended anchor. */ if (!write_to_file(FW_HDR_EXT_ANCHOR_DISABLE, HDR_EXTENDED_ANCHOR_OFFSET, 2, @@ -1409,14 +1340,13 @@ int main_bin(struct tbinparams binary_params) break; default: my_printf(TERR, "\n\nInvalid SPI Flash MAX clock (%d MHz) ", - binary_params.spi_max_clk); + binary_params.spi_max_clk); my_printf(TERR, "- it should be 20, 25, 33, 40 or 50 MHz"); return FALSE; } /* If SPI clock ratio set for MRIDER15, then it is error. */ if ((binary_params.spi_clk_ratio != 0x00) && (is_mrider15 == TRUE)) { - my_printf(TERR, "\nspiclkratio is not relevant for"); my_printf(TERR, " npcx5mng chips family !\n"); @@ -1439,13 +1369,13 @@ int main_bin(struct tbinparams binary_params) break; default: my_printf(TERR, "\n\nInvalid SPI Core Clock Ratio (%d) ", - binary_params.spi_clk_ratio); + binary_params.spi_clk_ratio); my_printf(TERR, "- it should be 1 or 2"); return FALSE; } if (!write_to_file(tmp_param, HDR_SPI_MAX_CLK_OFFSET, 1, - "HDR - SPI flash MAX Clock ")) + "HDR - SPI flash MAX Clock ")) return FALSE; /* Write the SPI flash Read Mode. */ @@ -1453,7 +1383,6 @@ int main_bin(struct tbinparams binary_params) /* If needed, set the unlimited burst bit. */ if (binary_params.bin_params & BIN_UNLIM_BURST_ENABLE) { if (is_mrider15 == TRUE) { - my_printf(TERR, "\nunlimburst is not relevant for"); my_printf(TERR, " npcx5mng chips family !\n"); @@ -1462,35 +1391,29 @@ int main_bin(struct tbinparams binary_params) tmp_param |= SPI_UNLIMITED_BURST_ENABLE; } - if (!write_to_file(tmp_param, - HDR_SPI_READ_MODE_OFFSET, 1, - "HDR - SPI flash Read Mode ")) + if (!write_to_file(tmp_param, HDR_SPI_READ_MODE_OFFSET, 1, + "HDR - SPI flash Read Mode ")) return FALSE; /* Write the error detection configuration. */ if (binary_params.bin_params & BIN_FW_CRC_DISABLE) { if (!write_to_file(FW_CRC_DISABLE, - HDR_ERR_DETECTION_CONF_OFFSET, - 1, + HDR_ERR_DETECTION_CONF_OFFSET, 1, "HDR - FW CRC Disabled ")) return FALSE; } else { /* Write the ancore and the extended anchor. */ - if (!write_to_file(FW_CRC_ENABLE, - HDR_ERR_DETECTION_CONF_OFFSET, 1, - "HDR - FW CRC Enabled ")) + if (!write_to_file(FW_CRC_ENABLE, HDR_ERR_DETECTION_CONF_OFFSET, + 1, "HDR - FW CRC Enabled ")) return FALSE; } /* FW entry point should be between the FW load address and RAM size */ - if ((binary_params.fw_load_addr > - (g_ram_start_address + g_ram_size)) || - (binary_params.fw_load_addr < g_ram_start_address)) { - my_printf(TERR, - "\nFW load address (0x%08x) should be between ", + if ((binary_params.fw_load_addr > (g_ram_start_address + g_ram_size)) || + (binary_params.fw_load_addr < g_ram_start_address)) { + my_printf(TERR, "\nFW load address (0x%08x) should be between ", binary_params.fw_load_addr); - my_printf(TERR, - "start (0x%08x) and end (0x%08x) of RAM ).", + my_printf(TERR, "start (0x%08x) and end (0x%08x) of RAM ).", g_ram_start_address, (g_ram_start_address + g_ram_size)); @@ -1499,8 +1422,8 @@ int main_bin(struct tbinparams binary_params) /* Write the FW load start address */ if (!write_to_file(binary_params.fw_load_addr, - HDR_FW_LOAD_START_ADDR_OFFSET, 4, - "HDR - FW load start address ")) + HDR_FW_LOAD_START_ADDR_OFFSET, 4, + "HDR - FW load start address ")) return FALSE; /* @@ -1512,25 +1435,22 @@ int main_bin(struct tbinparams binary_params) * size of the binary file minus the offset of the start of the * FW. */ - binary_params.fw_len = bin_file_size_bytes-bin_fw_offset; + binary_params.fw_len = bin_file_size_bytes - bin_fw_offset; } if ((int)binary_params.fw_len < 0) { my_printf(TERR, "\nFW length %d (0x%08x) should be greater than 0x0.", - binary_params.fw_len, - binary_params.fw_len); + binary_params.fw_len, binary_params.fw_len); return FALSE; } if (((int)binary_params.fw_len > - (bin_file_size_bytes - bin_fw_offset)) || - ((int)binary_params.fw_len > g_ram_size)) { - my_printf(TERR, - "\nFW length %d (0x%08x) should be within the", + (bin_file_size_bytes - bin_fw_offset)) || + ((int)binary_params.fw_len > g_ram_size)) { + my_printf(TERR, "\nFW length %d (0x%08x) should be within the", binary_params.fw_len, binary_params.fw_len); - my_printf(TERR, - " input-file (related to the FW offset)"); + my_printf(TERR, " input-file (related to the FW offset)"); my_printf(TERR, "\n (0x%08x) and within the RAM (RAM size: 0x%08x).", (bin_file_size_bytes - bin_fw_offset), g_ram_size); @@ -1538,61 +1458,48 @@ int main_bin(struct tbinparams binary_params) } if ((binary_params.bin_params & BIN_FW_USER_ARM_RESET) != 0x00000000) { - read_from_file((bin_fw_offset + ARM_FW_ENTRY_POINT_OFFSET), - 4, - &binary_params.fw_ep, - "read FW entry point for FW image "); - - if ((binary_params.fw_ep < - binary_params.fw_load_addr) || - (binary_params.fw_ep > - (binary_params.fw_load_addr + - binary_params.fw_len))) { + read_from_file((bin_fw_offset + ARM_FW_ENTRY_POINT_OFFSET), 4, + &binary_params.fw_ep, + "read FW entry point for FW image "); + + if ((binary_params.fw_ep < binary_params.fw_load_addr) || + (binary_params.fw_ep > + (binary_params.fw_load_addr + binary_params.fw_len))) { my_printf(TERR, "\nFW entry point (0x%08x) should be between", binary_params.fw_ep); - my_printf(TERR, - " the FW load address (0x%08x) ", + my_printf(TERR, " the FW load address (0x%08x) ", binary_params.fw_load_addr); - my_printf(TERR, - "and FW length (0x%08x).\n", + my_printf(TERR, "and FW length (0x%08x).\n", (binary_params.fw_load_addr + - binary_params.fw_len)); + binary_params.fw_len)); return FALSE; } } /* FW entry point should be between the FW load address and RAM size */ - if ((binary_params.fw_ep < - binary_params.fw_load_addr) || - (binary_params.fw_ep > - (binary_params.fw_load_addr + - binary_params.fw_len))) { + if ((binary_params.fw_ep < binary_params.fw_load_addr) || + (binary_params.fw_ep > + (binary_params.fw_load_addr + binary_params.fw_len))) { if (((binary_params.bin_params & BIN_FW_ENTRY_POINT) == - 0x00000000) && - ((binary_params.bin_params & - BIN_FW_LOAD_START_ADDR) != 0x00000000)) { - binary_params.fw_ep = - binary_params.fw_load_addr; + 0x00000000) && + ((binary_params.bin_params & BIN_FW_LOAD_START_ADDR) != + 0x00000000)) { + binary_params.fw_ep = binary_params.fw_load_addr; } else { - my_printf(TERR, - "\nFW entry point (0x%08x) should be ", + my_printf(TERR, "\nFW entry point (0x%08x) should be ", binary_params.fw_ep); - my_printf(TERR, - "\between the FW load address (0x%08x)", + my_printf(TERR, "\between the FW load address (0x%08x)", binary_params.fw_load_addr); - my_printf(TERR, - " and FW length (0x%08x).\n", + my_printf(TERR, " and FW length (0x%08x).\n", (binary_params.fw_load_addr + - binary_params.fw_len)); + binary_params.fw_len)); return FALSE; } } /* Write the FW entry point */ - if (!write_to_file(binary_params.fw_ep, - HDR_FW_ENTRY_POINT_OFFSET, - 4, + if (!write_to_file(binary_params.fw_ep, HDR_FW_ENTRY_POINT_OFFSET, 4, "HDR - FW Entry point ")) return FALSE; @@ -1602,17 +1509,15 @@ int main_bin(struct tbinparams binary_params) * In case the size was not set, then CRC end address is * the size of the binary file. */ - binary_params.fw_err_detec_e_addr = - binary_params.fw_len - 1; + binary_params.fw_err_detec_e_addr = binary_params.fw_len - 1; } else { /* CRC end address should be less than FW length. */ if (binary_params.fw_err_detec_e_addr > - (binary_params.fw_len - 1)) { + (binary_params.fw_len - 1)) { my_printf(TERR, "\nCRC end address (0x%08x) should be less ", binary_params.fw_err_detec_e_addr); - my_printf(TERR, - "than the FW length %d (0x%08x)", + my_printf(TERR, "than the FW length %d (0x%08x)", (binary_params.fw_len), (binary_params.fw_len)); return FALSE; @@ -1621,40 +1526,35 @@ int main_bin(struct tbinparams binary_params) /* Check CRC start and end addresses. */ if (binary_params.fw_err_detec_s_addr > - binary_params.fw_err_detec_e_addr) { + binary_params.fw_err_detec_e_addr) { my_printf(TERR, "\nCRC start address (0x%08x) should be less or ", binary_params.fw_err_detec_s_addr); my_printf(TERR, "equal to CRC end address (0x%08x)\nPlease check ", binary_params.fw_err_detec_e_addr); - my_printf(TERR, - "CRC start address and CRC size arguments."); + my_printf(TERR, "CRC start address and CRC size arguments."); return FALSE; } /* CRC start addr should be between the FW load address and RAM size */ - if (binary_params.fw_err_detec_s_addr > - binary_params.fw_len) { + if (binary_params.fw_err_detec_s_addr > binary_params.fw_len) { my_printf(TERR, "\nCRC start address (0x%08x) should ", binary_params.fw_err_detec_s_addr); - my_printf(TERR, "be FW length (0x%08x).", - binary_params.fw_len); + my_printf(TERR, "be FW length (0x%08x).", binary_params.fw_len); return FALSE; } /* Write the CRC start address */ if (!write_to_file(binary_params.fw_err_detec_s_addr, - HDR_FW_ERR_DETECT_START_ADDR_OFFSET, - 4, + HDR_FW_ERR_DETECT_START_ADDR_OFFSET, 4, "HDR - FW CRC Start ")) return FALSE; /* CRC end addr should be between the CRC start address and RAM size */ if ((binary_params.fw_err_detec_e_addr < - binary_params.fw_err_detec_s_addr) || - (binary_params.fw_err_detec_e_addr > - binary_params.fw_len)) { + binary_params.fw_err_detec_s_addr) || + (binary_params.fw_err_detec_e_addr > binary_params.fw_len)) { my_printf(TERR, "\nCRC end address (0x%08x) should be between the ", binary_params.fw_err_detec_e_addr); @@ -1667,8 +1567,7 @@ int main_bin(struct tbinparams binary_params) /* Write the CRC end address */ if (!write_to_file(binary_params.fw_err_detec_e_addr, - HDR_FW_ERR_DETECT_END_ADDR_OFFSET, - 4, + HDR_FW_ERR_DETECT_END_ADDR_OFFSET, 4, "HDR - FW CRC End ")) return FALSE; @@ -1678,22 +1577,18 @@ int main_bin(struct tbinparams binary_params) binary_params.fw_len += (16 - tmp_param); /* FW load address + FW length should be less than the RAM size. */ - if ((binary_params.fw_load_addr + - binary_params.fw_len) > - (g_ram_start_address + g_ram_size)) { + if ((binary_params.fw_load_addr + binary_params.fw_len) > + (g_ram_start_address + g_ram_size)) { my_printf(TERR, "\nFW load address + FW length should (0x%08x) be ", (binary_params.fw_load_addr + binary_params.fw_len)); - my_printf(TERR, - "less than the RAM size (0x%08x).", + my_printf(TERR, "less than the RAM size (0x%08x).", (g_ram_start_address + g_ram_size)); return FALSE; } /* Write the FW length */ - if (!write_to_file(binary_params.fw_len, - HDR_FW_LENGTH_OFFSET, - 4, + if (!write_to_file(binary_params.fw_len, HDR_FW_LENGTH_OFFSET, 4, "HDR - FW Length ")) return FALSE; @@ -1716,30 +1611,26 @@ int main_bin(struct tbinparams binary_params) break; default: my_printf(TERR, "\n\nInvalid Flash size (%d MBytes) -", - binary_params.flash_size); + binary_params.flash_size); my_printf(TERR, " it should be 1, 2, 4, 8 or 16 MBytes\n"); return FALSE; } - if (!write_to_file(tmp_param, - HDR_FLASH_SIZE_OFFSET, - 1, + if (!write_to_file(tmp_param, HDR_FLASH_SIZE_OFFSET, 1, "HDR - Flash size ")) return FALSE; /* Write the reserved bytes. */ if (!write_to_file(PAD_VALUE, HDR_RESERVED, 26, - "HDR - Reserved (26 bytes) ")) + "HDR - Reserved (26 bytes) ")) return FALSE; - /* Refresh the FW header bin file in order to calculate CRC */ if (g_hfd_pointer) { fclose(g_hfd_pointer); g_hfd_pointer = fopen(g_hdr_input_name, "r+b"); if (g_hfd_pointer == NULL) { - my_printf(TERR, - "\n\nCannot open %s\n\n", + my_printf(TERR, "\n\nCannot open %s\n\n", input_file_name); return FALSE; } @@ -1757,9 +1648,7 @@ int main_bin(struct tbinparams binary_params) binary_params.hdr_crc = 0; /* Write FW header CRC to header file */ - if (!write_to_file(binary_params.hdr_crc, - HDR_FW_HEADER_SIG_OFFSET, - 4, + if (!write_to_file(binary_params.hdr_crc, HDR_FW_HEADER_SIG_OFFSET, 4, "HDR - Header CRC ")) return FALSE; @@ -1767,11 +1656,11 @@ int main_bin(struct tbinparams binary_params) if ((binary_params.bin_params & BIN_FW_CRC_DISABLE) == 0) { /* Calculate ... */ g_calc_type = CALC_TYPE_CRC; - if (!calc_firmware_csum_bin(&binary_params.fw_crc, - (bin_fw_offset + - binary_params.fw_err_detec_s_addr), - (binary_params.fw_err_detec_e_addr - - binary_params.fw_err_detec_s_addr+1))) + if (!calc_firmware_csum_bin( + &binary_params.fw_crc, + (bin_fw_offset + binary_params.fw_err_detec_s_addr), + (binary_params.fw_err_detec_e_addr - + binary_params.fw_err_detec_s_addr + 1))) return FALSE; g_calc_type = CALC_TYPE_NONE; @@ -1779,9 +1668,7 @@ int main_bin(struct tbinparams binary_params) binary_params.fw_crc = 0; /* Write the FW CRC into file header file */ - if (!write_to_file(binary_params.fw_crc, - HDR_FW_IMAGE_SIG_OFFSET, - 4, + if (!write_to_file(binary_params.fw_crc, HDR_FW_IMAGE_SIG_OFFSET, 4, "HDR - FW CRC ")) return FALSE; @@ -1802,22 +1689,14 @@ int main_bin(struct tbinparams binary_params) fclose(output_file_pointer); if ((binary_params.bin_params & BIN_FW_HDR_OFFSET) != 0) { - copy_file_to_file(output_file_name, - input_file_name, - 0, - SEEK_SET); - copy_file_to_file(output_file_name, - g_hdr_input_name, - binary_params.fw_hdr_offset, + copy_file_to_file(output_file_name, input_file_name, 0, SEEK_SET); + copy_file_to_file(output_file_name, g_hdr_input_name, + binary_params.fw_hdr_offset, SEEK_SET); } else { - copy_file_to_file(output_file_name, - g_hdr_input_name, - 0, + copy_file_to_file(output_file_name, g_hdr_input_name, 0, SEEK_END); - copy_file_to_file(output_file_name, - input_file_name, - 0, + copy_file_to_file(output_file_name, input_file_name, 0, SEEK_END); } @@ -1848,20 +1727,16 @@ int calc_header_crc_bin(unsigned int *p_cksum) if (fseek(g_hfd_pointer, 0x00000000, SEEK_SET) < 0) return FALSE; - if (fread(g_header_array, - HEADER_SIZE, - 1, - g_hfd_pointer) != 1) + if (fread(g_header_array, HEADER_SIZE, 1, g_hfd_pointer) != 1) return FALSE; for (i = 0; i < (HEADER_SIZE - HEADER_CRC_FIELDS_SIZE); i++) { - /* * I had once the Verbose check inside the my_printf, but * it made ECST run sloooowwwwwly.... */ if (g_verbose == SUPER_VERBOSE) { - if (i%line_print_size == 0) + if (i % line_print_size == 0) my_printf(TDBG, "\n[%.4x]: ", i); my_printf(TDBG, "%.2x ", g_header_array[i]); @@ -1872,10 +1747,8 @@ int calc_header_crc_bin(unsigned int *p_cksum) if (g_verbose == SUPER_VERBOSE) { if ((i + 1) % line_print_size == 0) - my_printf(TDBG, - "FW Header ChecksumCRC = %.8x", - calc_header_checksum_crc); - + my_printf(TDBG, "FW Header ChecksumCRC = %.8x", + calc_header_checksum_crc); } } @@ -1895,11 +1768,9 @@ int calc_header_crc_bin(unsigned int *p_cksum) * Description: TBD ******************************************************************* */ -int calc_firmware_csum_bin(unsigned int *p_cksum, - unsigned int fw_offset, - unsigned int fw_length) +int calc_firmware_csum_bin(unsigned int *p_cksum, unsigned int fw_offset, + unsigned int fw_length) { - unsigned int i; unsigned int calc_read_bytes; unsigned int calc_num_of_bytes_to_read; @@ -1912,16 +1783,12 @@ int calc_firmware_csum_bin(unsigned int *p_cksum, calc_curr_position = fw_offset; if (g_verbose == REGULAR_VERBOSE) { - my_printf(TINF, - "\nFW Error Detect Start Dddress: 0x%08x", + my_printf(TINF, "\nFW Error Detect Start Dddress: 0x%08x", calc_curr_position); - my_printf(TINF, - "\nFW Error Detect End Dddress: 0x%08x", + my_printf(TINF, "\nFW Error Detect End Dddress: 0x%08x", calc_curr_position + calc_num_of_bytes_to_read - 1); - my_printf(TINF, - "\nFW Error Detect Size: %d (0x%X)", - calc_num_of_bytes_to_read, - calc_num_of_bytes_to_read); + my_printf(TINF, "\nFW Error Detect Size: %d (0x%X)", + calc_num_of_bytes_to_read, calc_num_of_bytes_to_read); } init_calculation(&calc_fw_checksum_crc); @@ -1932,13 +1799,10 @@ int calc_firmware_csum_bin(unsigned int *p_cksum, else calc_read_bytes = calc_num_of_bytes_to_read; - if (fseek(input_file_pointer, - calc_curr_position, SEEK_SET) < 0) + if (fseek(input_file_pointer, calc_curr_position, SEEK_SET) < 0) return 0; - if (fread(g_fw_array, - calc_read_bytes, - 1, - input_file_pointer) != 1) + if (fread(g_fw_array, calc_read_bytes, 1, input_file_pointer) != + 1) return 0; for (i = 0; i < calc_read_bytes; i++) { @@ -1947,9 +1811,8 @@ int calc_firmware_csum_bin(unsigned int *p_cksum, * but it made ECST run sloooowwwwwly.... */ if (g_verbose == SUPER_VERBOSE) { - if (i%line_print_size == 0) - my_printf(TDBG, - "\n[%.4x]: ", + if (i % line_print_size == 0) + my_printf(TDBG, "\n[%.4x]: ", calc_curr_position + i); my_printf(TDBG, "%.2x ", g_fw_array[i]); @@ -1960,8 +1823,7 @@ int calc_firmware_csum_bin(unsigned int *p_cksum, if (g_verbose == SUPER_VERBOSE) { if ((i + 1) % line_print_size == 0) - my_printf(TDBG, - "FW Checksum= %.8x", + my_printf(TDBG, "FW Checksum= %.8x", calc_fw_checksum_crc); } } @@ -2006,24 +1868,19 @@ int main_hdr(void) } if (strlen(output_file_name) == 0) - strncpy(tmp_file_name, - input_file_name, + strncpy(tmp_file_name, input_file_name, sizeof(tmp_file_name) - 1); else { - copy_file_to_file(output_file_name, - input_file_name, - 0, + copy_file_to_file(output_file_name, input_file_name, 0, SEEK_END); - strncpy(tmp_file_name, - output_file_name, + strncpy(tmp_file_name, output_file_name, sizeof(tmp_file_name) - 1); } /* Open Header file */ g_hdr_pointer = fopen(tmp_file_name, "r+b"); if (g_hdr_pointer == NULL) { - my_printf(TERR, - "\n\nCannot open %s file.\n\n", + my_printf(TERR, "\n\nCannot open %s file.\n\n", tmp_file_name); return FALSE; } @@ -2035,10 +1892,9 @@ int main_hdr(void) my_printf(TERR, "\n\nFW offset 0x%08x should be less than ", fw_offset); - my_printf(TERR, - "file size 0x%x (%d).\n\n", + my_printf(TERR, "file size 0x%x (%d).\n\n", bin_file_size_bytes, bin_file_size_bytes); - return FALSE; + return FALSE; } /* FW table should be less than file size. */ @@ -2046,7 +1902,7 @@ int main_hdr(void) my_printf(TERR, "\n\nFW table 0x%08x should be less ", ptr_fw_addr); my_printf(TERR, "than file size 0x%x (%d).\n\n", - bin_file_size_bytes, bin_file_size_bytes); + bin_file_size_bytes, bin_file_size_bytes); return FALSE; } @@ -2054,25 +1910,15 @@ int main_hdr(void) return FALSE; tmp_long_val = HDR_PTR_SIGNATURE; - result = (int)(fwrite(&tmp_long_val, - 4, - 1, - g_hdr_pointer)); - result |= (int)(fwrite(&ptr_fw_addr, - 4, - 1, - g_hdr_pointer)); + result = (int)(fwrite(&tmp_long_val, 4, 1, g_hdr_pointer)); + result |= (int)(fwrite(&ptr_fw_addr, 4, 1, g_hdr_pointer)); if (result) { - my_printf(TINF, - "\nBootLoader Header file: %s\n", + my_printf(TINF, "\nBootLoader Header file: %s\n", tmp_file_name); - my_printf(TINF, - " Offset: 0x%08X, Signature: 0x%08X,", + my_printf(TINF, " Offset: 0x%08X, Signature: 0x%08X,", fw_offset, HDR_PTR_SIGNATURE); - my_printf(TINF, - " Pointer: 0x%08X\n", - ptr_fw_addr); + my_printf(TINF, " Pointer: 0x%08X\n", ptr_fw_addr); } else { my_printf(TERR, "\n\nCouldn't write signature (%x) and " @@ -2082,7 +1928,6 @@ int main_hdr(void) } } else { - if (strlen(output_file_name) == 0) { my_printf(TERR, "\n\nNo output file selected "); my_printf(TERR, "for BootLoader header file.\n\n"); @@ -2092,8 +1937,7 @@ int main_hdr(void) /* Open Output file */ g_hdr_pointer = fopen(output_file_name, "w+b"); if (g_hdr_pointer == NULL) { - my_printf(TERR, - "\n\nCannot open %s file.\n\n", + my_printf(TERR, "\n\nCannot open %s file.\n\n", output_file_name); return FALSE; } @@ -2102,23 +1946,15 @@ int main_hdr(void) return FALSE; tmp_long_val = HDR_PTR_SIGNATURE; - result = (int)(fwrite(&tmp_long_val, - 4, - 1, - g_hdr_pointer)); - result |= (int)(fwrite(&ptr_fw_addr, - 4, - 1, - g_hdr_pointer)); + result = (int)(fwrite(&tmp_long_val, 4, 1, g_hdr_pointer)); + result |= (int)(fwrite(&ptr_fw_addr, 4, 1, g_hdr_pointer)); if (result) { - my_printf(TINF, - "\nBootLoader Header file: %s\n", + my_printf(TINF, "\nBootLoader Header file: %s\n", output_file_name); my_printf(TINF, " Signature: 0x%08X, Pointer: 0x%08X\n", - HDR_PTR_SIGNATURE, - ptr_fw_addr); + HDR_PTR_SIGNATURE, ptr_fw_addr); } else { my_printf(TERR, "\n\nCouldn't write signature (%x) and ", @@ -2128,7 +1964,6 @@ int main_hdr(void) output_file_name); return FALSE; } - } /* Close if needed... */ @@ -2166,15 +2001,15 @@ int main_api(void) /* If API input file was not declared, then print error message. */ if (strlen(input_file_name) == 0) { - my_printf(TERR, + my_printf( + TERR, "\n\nNeed to define API input file, using -i flag\n\n"); return FALSE; - } if (strlen(output_file_name) == 0) { if (!splice_into_path(tmp_file_name, input_file_name, - sizeof(tmp_file_name), "api_")) + sizeof(tmp_file_name), "api_")) return FALSE; } else strncpy(tmp_file_name, output_file_name, @@ -2204,27 +2039,20 @@ int main_api(void) api_file_size_bytes = get_file_length(api_file_pointer); if (api_file_size_bytes < 0) return FALSE; - my_printf(TINF, - "\nAPI file: %s, size: %d bytes (0x%x)\n", - tmp_file_name, - api_file_size_bytes, - api_file_size_bytes); + my_printf(TINF, "\nAPI file: %s, size: %d bytes (0x%x)\n", + tmp_file_name, api_file_size_bytes, api_file_size_bytes); crc_checksum = calc_api_csum_bin(); if (fseek(api_file_pointer, api_file_size_bytes, SEEK_SET) < 0) return FALSE; - result = (int)(fwrite(&crc_checksum, - 4, - 1, - api_file_pointer)); + result = (int)(fwrite(&crc_checksum, 4, 1, api_file_pointer)); if (result) my_printf(TINF, "\nIn API BIN file - Offset 0x%08X - value 0x%08X", - api_file_size_bytes, - crc_checksum); + api_file_size_bytes, crc_checksum); else { my_printf(TERR, "\n\nCouldn't write %x to API BIN file at %08x\n\n", @@ -2241,7 +2069,6 @@ int main_api(void) return TRUE; } - /* ******************************************************************* * Function: calc_api_csum_bin @@ -2250,10 +2077,9 @@ int main_api(void) * Return: Return the CRC \ checksum, or "0" in case of fail. * Description: TBD ******************************************************************* -*/ + */ unsigned int calc_api_csum_bin(void) { - unsigned int i; unsigned int calc_read_bytes; int calc_num_of_bytes_to_read; @@ -2269,10 +2095,8 @@ unsigned int calc_api_csum_bin(void) my_printf(TDBG, "\nAPI CRC \\ Checksum First Byte Address: 0x%08x", calc_curr_position); - my_printf(TDBG, - "\nAPI CRC \\ Checksum Size: %d (0x%X)", - calc_num_of_bytes_to_read, - calc_num_of_bytes_to_read); + my_printf(TDBG, "\nAPI CRC \\ Checksum Size: %d (0x%X)", + calc_num_of_bytes_to_read, calc_num_of_bytes_to_read); } init_calculation(&calc_fw_checksum_crc); @@ -2283,13 +2107,10 @@ unsigned int calc_api_csum_bin(void) else calc_read_bytes = calc_num_of_bytes_to_read; - if (fseek(api_file_pointer, - calc_curr_position, SEEK_SET) < 0) + if (fseek(api_file_pointer, calc_curr_position, SEEK_SET) < 0) return 0; - if (fread(g_fw_array, - calc_read_bytes, - 1, - api_file_pointer) != 1) + if (fread(g_fw_array, calc_read_bytes, 1, api_file_pointer) != + 1) return 0; for (i = 0; i < calc_read_bytes; i++) { @@ -2298,10 +2119,9 @@ unsigned int calc_api_csum_bin(void) * but it made ecst run sloooowwwwwly.... */ if (g_verbose == SUPER_VERBOSE) { - if (i%line_print_size == 0) - my_printf(TDBG, - "\n[%.4x]: ", - calc_curr_position + i); + if (i % line_print_size == 0) + my_printf(TDBG, "\n[%.4x]: ", + calc_curr_position + i); my_printf(TDBG, "%.2x ", g_fw_array[i]); } @@ -2311,8 +2131,7 @@ unsigned int calc_api_csum_bin(void) if (g_verbose == SUPER_VERBOSE) { if ((i + 1) % line_print_size == 0) - my_printf(TDBG, - "FW Checksum= %.8x", + my_printf(TDBG, "FW Checksum= %.8x", calc_fw_checksum_crc); } } @@ -2323,14 +2142,13 @@ unsigned int calc_api_csum_bin(void) finalize_calculation(&calc_fw_checksum_crc); return calc_fw_checksum_crc; - } /* ************************************************************************** * CRC Handler ************************************************************************** -*/ + */ /* ******************************************************************* @@ -2343,7 +2161,7 @@ unsigned int calc_api_csum_bin(void) ******************************************************************* */ -#define P_32 0xEDB88320L +#define P_32 0xEDB88320L /* ******************************************************************* @@ -2394,7 +2212,7 @@ static void init_crc32_tab(void); unsigned int initialize_crc_32(void) { return 0xffffffffL; -} /* initialize_crc_32 */ +} /* initialize_crc_32 */ /* ******************************************************************* @@ -2410,7 +2228,6 @@ unsigned int initialize_crc_32(void) unsigned int update_crc_32(unsigned int crc, char c) { - unsigned int tmp, long_c; long_c = 0x000000ffL & (unsigned int)c; @@ -2423,7 +2240,7 @@ unsigned int update_crc_32(unsigned int crc, char c) return crc; -} /* update_crc_32 */ +} /* update_crc_32 */ /* ******************************************************************* @@ -2437,16 +2254,13 @@ unsigned int update_crc_32(unsigned int crc, char c) */ static void init_crc32_tab(void) { - int i, j; unsigned int crc; for (i = 0; i < 256; i++) { - crc = (unsigned int)i; for (j = 0; j < 8; j++) { - if (crc & 0x00000001L) crc = (crc >> 1) ^ P_32; else @@ -2458,7 +2272,7 @@ static void init_crc32_tab(void) crc_tab32_init = TRUE; -} /* init_crc32_tab */ +} /* init_crc32_tab */ /* ******************************************************************* @@ -2473,13 +2287,13 @@ static void init_crc32_tab(void) unsigned int finalize_crc_32(unsigned int crc) { - int i; unsigned int result = 0; for (i = 0; i < NUM_OF_BYTES; i++) - SET_VAR_BIT(result, NUM_OF_BYTES - (i+1), READ_VAR_BIT(crc, i)); + SET_VAR_BIT(result, NUM_OF_BYTES - (i + 1), + READ_VAR_BIT(crc, i)); return result; -} /* finalize_crc_32 */ +} /* finalize_crc_32 */ |