mirror of
https://github.com/pine64/blisp.git
synced 2024-12-22 06:20:12 +00:00
Stitch more error codes through tool
This commit is contained in:
parent
fced48570a
commit
6e2d40b9c4
@ -16,6 +16,9 @@ typedef enum {
|
|||||||
BLISP_ERR_PENDING = -6,
|
BLISP_ERR_PENDING = -6,
|
||||||
BLISP_ERR_CHIP_ERR = -7,
|
BLISP_ERR_CHIP_ERR = -7,
|
||||||
BLISP_ERR_INVALID_CHIP_TYPE = -8,
|
BLISP_ERR_INVALID_CHIP_TYPE = -8,
|
||||||
|
BLISP_ERR_OUT_OF_MEMORY = -9,
|
||||||
|
BLISP_ERR_INVALID_COMMAND = -10,
|
||||||
|
BLISP_ERR_CANT_OPEN_FILE=-11,
|
||||||
|
|
||||||
} blisp_return_t;
|
} blisp_return_t;
|
||||||
#endif
|
#endif
|
@ -3,11 +3,11 @@
|
|||||||
#define BLISP_CMD_H
|
#define BLISP_CMD_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "error_codes.h"
|
||||||
struct cmd {
|
struct cmd {
|
||||||
const char* name;
|
const char* name;
|
||||||
int8_t (*args_init)();
|
blisp_return_t (*args_init)();
|
||||||
uint8_t (*args_parse_exec)(int argc, char** argv);
|
blisp_return_t (*args_parse_exec)(int argc, char** argv);
|
||||||
void (*args_print_syntax)();
|
void (*args_print_syntax)();
|
||||||
void (*args_free)();
|
void (*args_free)();
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <argtable3.h>
|
||||||
#include <blisp_easy.h>
|
#include <blisp_easy.h>
|
||||||
#include "../cmd.h"
|
#include "../cmd.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include <argtable3.h>
|
|
||||||
|
|
||||||
#define REG_EXTENDED 1
|
#define REG_EXTENDED 1
|
||||||
#define REG_ICASE (REG_EXTENDED << 1)
|
#define REG_ICASE (REG_EXTENDED << 1)
|
||||||
@ -9,21 +9,21 @@
|
|||||||
static struct arg_rex* cmd;
|
static struct arg_rex* cmd;
|
||||||
static struct arg_file* single_download;
|
static struct arg_file* single_download;
|
||||||
static struct arg_int* single_download_location;
|
static struct arg_int* single_download_location;
|
||||||
static struct arg_str *port_name, *chip_type; // TODO: Make this common
|
static struct arg_str *port_name, *chip_type; // TODO: Make this common
|
||||||
static struct arg_lit* reset;
|
static struct arg_lit* reset;
|
||||||
static struct arg_end* end;
|
static struct arg_end* end;
|
||||||
static void* cmd_iot_argtable[7];
|
static void* cmd_iot_argtable[7];
|
||||||
|
|
||||||
void blisp_single_download()
|
blisp_return_t blisp_single_download() {
|
||||||
{
|
|
||||||
struct blisp_device device;
|
struct blisp_device device;
|
||||||
int32_t ret;
|
blisp_return_t ret;
|
||||||
|
|
||||||
if (blisp_common_init_device(&device, port_name, chip_type) != 0) {
|
ret = blisp_common_init_device(&device, port_name, chip_type);
|
||||||
return;
|
if (ret != BLISP_OK) {
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
ret = blisp_common_prepare_flash(&device);
|
||||||
if (blisp_common_prepare_flash(&device) != 0) {
|
if (ret != BLISP_OK) {
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
@ -32,6 +32,7 @@ void blisp_single_download()
|
|||||||
if (data_file == NULL) {
|
if (data_file == NULL) {
|
||||||
fprintf(stderr, "Failed to open data file \"%s\".\n",
|
fprintf(stderr, "Failed to open data file \"%s\".\n",
|
||||||
single_download->filename[0]);
|
single_download->filename[0]);
|
||||||
|
ret = BLISP_ERR_CANT_OPEN_FILE;
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
fseek(data_file, 0, SEEK_END);
|
fseek(data_file, 0, SEEK_END);
|
||||||
@ -39,9 +40,9 @@ void blisp_single_download()
|
|||||||
rewind(data_file);
|
rewind(data_file);
|
||||||
|
|
||||||
printf("Erasing the area, this might take a while...\n");
|
printf("Erasing the area, this might take a while...\n");
|
||||||
ret =
|
ret = blisp_device_flash_erase(
|
||||||
blisp_device_flash_erase(&device, *single_download_location->ival,
|
&device, *single_download_location->ival,
|
||||||
*single_download_location->ival + data_file_size + 1);
|
*single_download_location->ival + data_file_size + 1);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to erase.\n");
|
fprintf(stderr, "Failed to erase.\n");
|
||||||
goto exit2;
|
goto exit2;
|
||||||
@ -51,8 +52,8 @@ void blisp_single_download()
|
|||||||
struct blisp_easy_transport data_transport =
|
struct blisp_easy_transport data_transport =
|
||||||
blisp_easy_transport_new_from_file(data_file);
|
blisp_easy_transport_new_from_file(data_file);
|
||||||
|
|
||||||
ret = blisp_easy_flash_write(&device, &data_transport, *single_download_location->ival,
|
ret = blisp_easy_flash_write(&device, &data_transport,
|
||||||
data_file_size,
|
*single_download_location->ival, data_file_size,
|
||||||
blisp_common_progress_callback);
|
blisp_common_progress_callback);
|
||||||
if (ret < BLISP_OK) {
|
if (ret < BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to write data to flash.\n");
|
fprintf(stderr, "Failed to write data to flash.\n");
|
||||||
@ -67,21 +68,28 @@ void blisp_single_download()
|
|||||||
}
|
}
|
||||||
printf("Program OK!\n");
|
printf("Program OK!\n");
|
||||||
|
|
||||||
if (reset->count > 0) { // TODO: could be common
|
if (reset->count > 0) { // TODO: could be common
|
||||||
blisp_device_reset(&device);
|
|
||||||
printf("Resetting the chip.\n");
|
printf("Resetting the chip.\n");
|
||||||
|
ret = blisp_device_reset(&device);
|
||||||
|
if (ret != BLISP_OK) {
|
||||||
|
fprintf(stderr, "Failed to reset chip.\n");
|
||||||
|
goto exit2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == BLISP_OK) {
|
||||||
|
printf("Download complete!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Download complete!\n");
|
|
||||||
|
|
||||||
exit2:
|
exit2:
|
||||||
if (data_file != NULL)
|
if (data_file != NULL)
|
||||||
fclose(data_file);
|
fclose(data_file);
|
||||||
exit1:
|
exit1:
|
||||||
blisp_device_close(&device);
|
blisp_device_close(&device);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t cmd_iot_args_init() {
|
blisp_return_t cmd_iot_args_init() {
|
||||||
cmd_iot_argtable[0] = cmd =
|
cmd_iot_argtable[0] = cmd =
|
||||||
arg_rex1(NULL, NULL, "iot", NULL, REG_ICASE, NULL);
|
arg_rex1(NULL, NULL, "iot", NULL, REG_ICASE, NULL);
|
||||||
cmd_iot_argtable[1] = chip_type =
|
cmd_iot_argtable[1] = chip_type =
|
||||||
@ -99,9 +107,9 @@ int8_t cmd_iot_args_init() {
|
|||||||
|
|
||||||
if (arg_nullcheck(cmd_iot_argtable) != 0) {
|
if (arg_nullcheck(cmd_iot_argtable) != 0) {
|
||||||
fprintf(stderr, "insufficient memory\n");
|
fprintf(stderr, "insufficient memory\n");
|
||||||
return -1;
|
return BLISP_ERR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_iot_args_print_glossary() {
|
void cmd_iot_args_print_glossary() {
|
||||||
@ -111,20 +119,19 @@ void cmd_iot_args_print_glossary() {
|
|||||||
arg_print_glossary(stdout, cmd_iot_argtable, " %-25s %s\n");
|
arg_print_glossary(stdout, cmd_iot_argtable, " %-25s %s\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cmd_iot_parse_exec(int argc, char** argv) {
|
blisp_return_t cmd_iot_parse_exec(int argc, char** argv) {
|
||||||
int errors = arg_parse(argc, argv, cmd_iot_argtable);
|
int errors = arg_parse(argc, argv, cmd_iot_argtable);
|
||||||
if (errors == 0) {
|
if (errors == 0) {
|
||||||
if (single_download->count == 1 && single_download_location->count == 1) {
|
if (single_download->count == 1 && single_download_location->count == 1) {
|
||||||
blisp_single_download();
|
return blisp_single_download();
|
||||||
return 1;
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return BLISP_ERR_INVALID_COMMAND;
|
||||||
}
|
}
|
||||||
} else if (cmd->count == 1) {
|
} else if (cmd->count == 1) {
|
||||||
cmd_iot_args_print_glossary();
|
cmd_iot_args_print_glossary();
|
||||||
return 1;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_ERR_INVALID_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_iot_args_print_syntax() {
|
void cmd_iot_args_print_syntax() {
|
||||||
@ -137,4 +144,4 @@ void cmd_iot_free() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct cmd cmd_iot = {"iot", cmd_iot_args_init, cmd_iot_parse_exec,
|
struct cmd cmd_iot = {"iot", cmd_iot_args_init, cmd_iot_parse_exec,
|
||||||
cmd_iot_args_print_syntax, cmd_iot_free};
|
cmd_iot_args_print_syntax, cmd_iot_free};
|
||||||
|
@ -249,7 +249,7 @@ exit1:
|
|||||||
blisp_device_close(&device);
|
blisp_device_close(&device);
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t cmd_write_args_init() {
|
blisp_return_t cmd_write_args_init() {
|
||||||
cmd_write_argtable[0] = cmd =
|
cmd_write_argtable[0] = cmd =
|
||||||
arg_rex1(NULL, NULL, "write", NULL, REG_ICASE, NULL);
|
arg_rex1(NULL, NULL, "write", NULL, REG_ICASE, NULL);
|
||||||
cmd_write_argtable[1] = chip_type =
|
cmd_write_argtable[1] = chip_type =
|
||||||
@ -265,9 +265,9 @@ int8_t cmd_write_args_init() {
|
|||||||
|
|
||||||
if (arg_nullcheck(cmd_write_argtable) != 0) {
|
if (arg_nullcheck(cmd_write_argtable) != 0) {
|
||||||
fprintf(stderr, "insufficient memory\n");
|
fprintf(stderr, "insufficient memory\n");
|
||||||
return -1;
|
return BLISP_ERR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_write_args_print_glossary() {
|
void cmd_write_args_print_glossary() {
|
||||||
@ -277,16 +277,16 @@ void cmd_write_args_print_glossary() {
|
|||||||
arg_print_glossary(stdout, cmd_write_argtable, " %-25s %s\n");
|
arg_print_glossary(stdout, cmd_write_argtable, " %-25s %s\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cmd_write_parse_exec(int argc, char** argv) {
|
blisp_return_t cmd_write_parse_exec(int argc, char** argv) {
|
||||||
int errors = arg_parse(argc, argv, cmd_write_argtable);
|
int errors = arg_parse(argc, argv, cmd_write_argtable);
|
||||||
if (errors == 0) {
|
if (errors == 0) {
|
||||||
blisp_flash_firmware(); // TODO: Error code?
|
return blisp_flash_firmware(); // TODO: Error code?
|
||||||
return 1;
|
|
||||||
} else if (cmd->count == 1) {
|
} else if (cmd->count == 1) {
|
||||||
cmd_write_args_print_glossary();
|
cmd_write_args_print_glossary();
|
||||||
return 1;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_ERR_INVALID_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_write_args_print_syntax() {
|
void cmd_write_args_print_syntax() {
|
||||||
|
Loading…
Reference in New Issue
Block a user