mirror of
https://github.com/pine64/blisp.git
synced 2026-09-18 21:51:30 +00:00
Fix compiler warnings: blisp_flash_firmware
Improve blisp_flash_firmware error handling: - Address never checked return of `parse_firmware_file` - Ensure the function always returns the correct blisp_return_t value - Make error checking syntactic dance consistent
This commit is contained in:
@@ -168,31 +168,35 @@ void fill_up_boot_header(struct bfl_boot_header* boot_header) {
|
|||||||
|
|
||||||
blisp_return_t blisp_flash_firmware() {
|
blisp_return_t blisp_flash_firmware() {
|
||||||
struct blisp_device device;
|
struct blisp_device device;
|
||||||
blisp_return_t ret;
|
blisp_return_t ret = BLISP_OK;
|
||||||
|
|
||||||
if (access(binary_to_write->filename[0], R_OK) != 0) {
|
if (access(binary_to_write->filename[0], R_OK) != 0) {
|
||||||
// File not accessible, error out.
|
// File not accessible, error out.
|
||||||
fprintf(stderr, "Input firmware not found: %s\n", binary_to_write->filename[0]);
|
fprintf(stderr, "Input firmware not found: %s\n", binary_to_write->filename[0]);
|
||||||
cmd_write_args_print_glossary(); /* Print help to assist user */
|
cmd_write_args_print_glossary(); /* Print help to assist user */
|
||||||
/* No need to free memory, will now exit with ret code 1 */
|
/* No need to free memory, will now exit with ret code 1 */
|
||||||
return 1;
|
return BLISP_ERR_CANT_OPEN_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = blisp_common_init_device(&device, port_name, chip_type);
|
ret = blisp_common_init_device(&device, port_name, chip_type);
|
||||||
|
if (ret != BLISP_OK) {
|
||||||
if (ret != 0) {
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blisp_common_prepare_flash(&device) != 0) {
|
ret = blisp_common_prepare_flash(&device);
|
||||||
|
if (ret != BLISP_OK) {
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed_firmware_file_t parsed_file;
|
parsed_firmware_file_t parsed_file;
|
||||||
memset(&parsed_file, 0, sizeof(parsed_file));
|
memset(&parsed_file, 0, sizeof(parsed_file));
|
||||||
int parsed_result =
|
if (parse_firmware_file(binary_to_write->filename[0], &parsed_file) < 0) {
|
||||||
parse_firmware_file(binary_to_write->filename[0], &parsed_file);
|
// `parse_firmware_file` doesn't return `blisp_return_t`
|
||||||
|
// so we default to the generic error.
|
||||||
|
ret = BLISP_ERR_UNKNOWN;
|
||||||
|
goto exit1;
|
||||||
|
}
|
||||||
|
|
||||||
// If we are injecting a bootloader section, make it, erase flash, and flash
|
// If we are injecting a bootloader section, make it, erase flash, and flash
|
||||||
// it. Then when we do firmware later on; it will be located afterwards
|
// it. Then when we do firmware later on; it will be located afterwards
|
||||||
@@ -249,7 +253,7 @@ blisp_return_t blisp_flash_firmware() {
|
|||||||
&device, &data_transport, parsed_file.payload_address,
|
&device, &data_transport, parsed_file.payload_address,
|
||||||
parsed_file.payload_length, blisp_common_progress_callback);
|
parsed_file.payload_length, blisp_common_progress_callback);
|
||||||
|
|
||||||
if (ret < BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to write app to flash.\n");
|
fprintf(stderr, "Failed to write app to flash.\n");
|
||||||
goto exit2;
|
goto exit2;
|
||||||
}
|
}
|
||||||
@@ -275,6 +279,8 @@ exit2:
|
|||||||
free(parsed_file.payload);
|
free(parsed_file.payload);
|
||||||
exit1:
|
exit1:
|
||||||
blisp_device_close(&device);
|
blisp_device_close(&device);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
blisp_return_t cmd_write_args_init() {
|
blisp_return_t cmd_write_args_init() {
|
||||||
|
|||||||
Reference in New Issue
Block a user