Integrates fixkey workflow into the normal update workflow
Normal upload via umcumgr can update the bootloader if needed without additional steps.
This commit is contained in:
parent
d1a1717af9
commit
10b9f33142
30
src/image.c
30
src/image.c
|
@ -122,6 +122,7 @@ static void cbor_require_type(CborValue *it, CborType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_version(void) {
|
static char *get_version(void) {
|
||||||
|
serial_flush(serial_fd);
|
||||||
int rc = write(serial_fd, IMAGE_LIST_CMD, sizeof(IMAGE_LIST_CMD) - 1);
|
int rc = write(serial_fd, IMAGE_LIST_CMD, sizeof(IMAGE_LIST_CMD) - 1);
|
||||||
if (rc < sizeof(IMAGE_LIST_CMD) - 1) {
|
if (rc < sizeof(IMAGE_LIST_CMD) - 1) {
|
||||||
fprintf(stderr, "Failed to send command: %s\n", strerror(errno));
|
fprintf(stderr, "Failed to send command: %s\n", strerror(errno));
|
||||||
|
@ -188,9 +189,6 @@ static char *get_version(void) {
|
||||||
cbor_value_dup_text_string(&version_tag, &version, &len, NULL);
|
cbor_value_dup_text_string(&version_tag, &version, &len, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!version) {
|
|
||||||
printf("No applicaiton image found\n");
|
|
||||||
}
|
|
||||||
free(decoded_buf);
|
free(decoded_buf);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +245,7 @@ static void wrap_and_send_pkt(uint8_t *data, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_upload(char *filename){
|
void do_upload(char *filename){
|
||||||
|
serial_flush(serial_fd);
|
||||||
size_t pos = 0, len;
|
size_t pos = 0, len;
|
||||||
uint8_t const *payload;
|
uint8_t const *payload;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
|
@ -259,11 +258,13 @@ void do_upload(char *filename){
|
||||||
struct stat st;
|
struct stat st;
|
||||||
fstat(fd, &st);
|
fstat(fd, &st);
|
||||||
len = st.st_size;
|
len = st.st_size;
|
||||||
|
|
||||||
uint8_t *payload_mut = calloc(1, len);
|
uint8_t *payload_mut = calloc(1, len);
|
||||||
if (!payload_mut) {
|
if (!payload_mut) {
|
||||||
fprintf(stderr, "Failed alloc %s:%d", __FILE__, __LINE__);
|
fprintf(stderr, "Failed alloc %s:%d", __FILE__, __LINE__);
|
||||||
exit(9);
|
exit(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
while (bytes_read < len) {
|
while (bytes_read < len) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -375,28 +376,30 @@ void do_upload(char *filename){
|
||||||
pos += actual_size;
|
pos += actual_size;
|
||||||
free(out);
|
free(out);
|
||||||
}
|
}
|
||||||
printf("\nSuccess.\n");
|
printf("\n");
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fix_and_upload(char *filename) {
|
void fix_and_upload(char *filename) {
|
||||||
char *version = get_version();
|
char *version = get_version();
|
||||||
if (!strcmp(version, "0.3.2.0") ) {
|
if (version && !strcmp(version, "0.3.2.0") ) {
|
||||||
// Upload bootloader update payload
|
// Upload bootloader update payload
|
||||||
printf("Bootloader update required, uploading...\n");
|
printf("Bootloader update required, uploading...\n");
|
||||||
do_upload(NULL);
|
do_upload(NULL);
|
||||||
|
|
||||||
// Reset into controller
|
// Reset into controller
|
||||||
|
printf("Starting Controller\n");
|
||||||
gpio_ble_req_controller();
|
gpio_ble_req_controller();
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
// Update bootloader
|
// Update bootloader
|
||||||
|
printf("Triggering bootloader upgrade\n");
|
||||||
write(serial_fd, fixkey_msg, sizeof(fixkey_msg));
|
write(serial_fd, fixkey_msg, sizeof(fixkey_msg));
|
||||||
if (fsync(serial_fd) < 0) {
|
sleep(3);
|
||||||
fprintf(stderr, "fsync of serial device failed.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset into new bootloader
|
// Reset into new bootloader
|
||||||
|
printf("Reseting into new bootloader\n");
|
||||||
gpio_ble_req_bootloader();
|
gpio_ble_req_bootloader();
|
||||||
|
usleep(50000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the update
|
// Do the update
|
||||||
|
@ -413,8 +416,13 @@ void image_main(int fd, int argc, char **argv){
|
||||||
}
|
}
|
||||||
if (!strcmp(argv[0], "version")) {
|
if (!strcmp(argv[0], "version")) {
|
||||||
char *version = get_version();
|
char *version = get_version();
|
||||||
printf("%s\n", version);
|
|
||||||
free(version);
|
if (version) {
|
||||||
|
printf("%s\n", version);
|
||||||
|
free(version);
|
||||||
|
} else {
|
||||||
|
printf("No application image found.\n");
|
||||||
|
}
|
||||||
} else if (!strcmp(argv[0], "upload")) {
|
} else if (!strcmp(argv[0], "upload")) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "umcumgr image upload <binary file>\n");
|
fprintf(stderr, "umcumgr image upload <binary file>\n");
|
||||||
|
|
Loading…
Reference in New Issue