@@ -168,31 +168,35 @@ void fill_up_boot_header(struct bfl_boot_header* boot_header) {
168168
169169blisp_return_t blisp_flash_firmware () {
170170 struct blisp_device device ;
171- blisp_return_t ret ;
171+ blisp_return_t ret = BLISP_OK ;
172172
173173 if (access (binary_to_write -> filename [0 ], R_OK ) != 0 ) {
174174 // File not accessible, error out.
175175 fprintf (stderr , "Input firmware not found: %s\n" , binary_to_write -> filename [0 ]);
176176 cmd_write_args_print_glossary (); /* Print help to assist user */
177177 /* No need to free memory, will now exit with ret code 1 */
178- return 1 ;
178+ return BLISP_ERR_CANT_OPEN_FILE ;
179179 }
180180
181181 ret = blisp_common_init_device (& device , port_name , chip_type );
182-
183- if (ret != 0 ) {
182+ if (ret != BLISP_OK ) {
184183 return ret ;
185184 }
186185
187- if (blisp_common_prepare_flash (& device ) != 0 ) {
186+ ret = blisp_common_prepare_flash (& device );
187+ if (ret != BLISP_OK ) {
188188 // TODO: Error handling
189189 goto exit1 ;
190190 }
191191
192192 parsed_firmware_file_t parsed_file ;
193193 memset (& parsed_file , 0 , sizeof (parsed_file ));
194- int parsed_result =
195- parse_firmware_file (binary_to_write -> filename [0 ], & parsed_file );
194+ if (parse_firmware_file (binary_to_write -> filename [0 ], & parsed_file ) < 0 ) {
195+ // `parse_firmware_file` doesn't return `blisp_return_t`
196+ // so we default to the generic error.
197+ ret = BLISP_ERR_UNKNOWN ;
198+ goto exit1 ;
199+ }
196200
197201 // If we are injecting a bootloader section, make it, erase flash, and flash
198202 // it. Then when we do firmware later on; it will be located afterwards
@@ -233,13 +237,13 @@ blisp_return_t blisp_flash_firmware() {
233237
234238 if (ret != BLISP_OK ) {
235239 fprintf (stderr ,
236- "Failed to erase flash. Tried to erase from 0x%08lu to 0x%08lu \n" ,
240+ "Failed to erase flash. Tried to erase from 0x%08zx to 0x%08zx \n" ,
237241 parsed_file .payload_address ,
238242 parsed_file .payload_address + parsed_file .payload_length + 1 );
239243 goto exit2 ;
240244 }
241245
242- printf ("Flashing the firmware %lu bytes @ 0x%08lu ...\n" ,
246+ printf ("Flashing the firmware %zu bytes @ 0x%08zx ...\n" ,
243247 parsed_file .payload_length , parsed_file .payload_address );
244248 struct blisp_easy_transport data_transport =
245249 blisp_easy_transport_new_from_memory (parsed_file .payload ,
@@ -249,7 +253,7 @@ blisp_return_t blisp_flash_firmware() {
249253 & device , & data_transport , parsed_file .payload_address ,
250254 parsed_file .payload_length , blisp_common_progress_callback );
251255
252- if (ret < BLISP_OK ) {
256+ if (ret != BLISP_OK ) {
253257 fprintf (stderr , "Failed to write app to flash.\n" );
254258 goto exit2 ;
255259 }
@@ -275,6 +279,8 @@ blisp_return_t blisp_flash_firmware() {
275279 free (parsed_file .payload );
276280exit1 :
277281 blisp_device_close (& device );
282+
283+ return ret ;
278284}
279285
280286blisp_return_t cmd_write_args_init () {
0 commit comments