mirror of
https://github.com/pine64/blisp.git
synced 2025-08-21 11:00:52 +00:00
Compare commits
No commits in common. "6306a00de773cc04fd885c6174afba7feff62350" and "c63883bfa7a118aaba3630e30b9e13fb1351e0f1" have entirely different histories.
6306a00de7
...
c63883bfa7
@ -354,16 +354,13 @@ int32_t blisp_easy_flash_write(struct blisp_device* device,
|
||||
if (buffer_size > buffer_max_size) {
|
||||
buffer_size = buffer_max_size;
|
||||
}
|
||||
ret = blisp_easy_transport_read(data_transport, buffer, buffer_size);
|
||||
if (ret < BLISP_OK) {
|
||||
fprintf(stderr, "Failed to read firmware chunk! (ret:%d)\n ", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
blisp_easy_transport_read(data_transport, buffer,
|
||||
buffer_size); // TODO: Error Handling
|
||||
ret = blisp_device_flash_write(device, flash_location + sent_data, buffer,
|
||||
buffer_size);
|
||||
if (ret < BLISP_OK) {
|
||||
fprintf(stderr, "Failed to write firmware! (ret:%d)\n ", ret);
|
||||
// TODO: Error logigng: fprintf(stderr, "Failed to write firmware! (ret:
|
||||
// %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
sent_data += buffer_size;
|
||||
|
@ -195,7 +195,6 @@ blisp_return_t blisp_flash_firmware() {
|
||||
printf("Erasing flash to flash boot header\n");
|
||||
ret = blisp_device_flash_erase(&device, 0x0000,
|
||||
sizeof(struct bfl_boot_header));
|
||||
|
||||
if (ret != BLISP_OK) {
|
||||
fprintf(stderr, "Failed to erase flash.\n");
|
||||
goto exit2;
|
||||
@ -218,8 +217,7 @@ blisp_return_t blisp_flash_firmware() {
|
||||
printf("Erasing flash for firmware, this might take a while...\n");
|
||||
ret = blisp_device_flash_erase(
|
||||
&device, parsed_file.payload_address,
|
||||
parsed_file.payload_address + parsed_file.payload_length);
|
||||
|
||||
parsed_file.payload_address + parsed_file.payload_length + 1);
|
||||
if (ret != BLISP_OK) {
|
||||
fprintf(stderr,
|
||||
"Failed to erase flash. Tried to erase from 0x%08X to 0x%08X\n",
|
||||
@ -228,8 +226,7 @@ blisp_return_t blisp_flash_firmware() {
|
||||
goto exit2;
|
||||
}
|
||||
|
||||
printf("Flashing the firmware %d bytes @ 0x%08X...\n",
|
||||
parsed_file.payload_length, parsed_file.payload_address);
|
||||
printf("Flashing the firmware @ 0x%08X...\n", parsed_file.payload_address);
|
||||
struct blisp_easy_transport data_transport =
|
||||
blisp_easy_transport_new_from_memory(parsed_file.payload,
|
||||
parsed_file.payload_length);
|
||||
|
@ -3,11 +3,6 @@
|
||||
//
|
||||
#include "dfu_file.h"
|
||||
#include <stdlib.h>
|
||||
#include "parse_file.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <sys\types.h>
|
||||
#endif
|
||||
|
||||
#define DFU_SUFFIX_LENGTH 16
|
||||
#define LMDFU_PREFIX_LENGTH 8
|
||||
@ -78,17 +73,11 @@ int dfu_file_parse(const char* file_path_on_disk,
|
||||
size_t* payload_address) {
|
||||
uint8_t* dfu_file_contents = NULL;
|
||||
ssize_t file_size = get_file_contents(file_path_on_disk, &dfu_file_contents);
|
||||
if (file_size < 0) {
|
||||
return file_size;
|
||||
}
|
||||
if (file_size == 0 || dfu_file_contents == NULL) {
|
||||
return PARSED_ERROR_CANT_OPEN_FILE;
|
||||
if (file_size <= 0 || dfu_file_contents == NULL) {
|
||||
return -1;
|
||||
}
|
||||
// Parse DFU data
|
||||
struct dfu_file dfu_info = parse_dfu_suffix(dfu_file_contents, file_size);
|
||||
if (dfu_info.size.firmware == 0) {
|
||||
return PARSED_ERROR_BAD_DFU;
|
||||
}
|
||||
// Check if its for a BL* chip
|
||||
// if (dfu_info.idVendor != 0x28E9) {
|
||||
// free(dfu_file_contents);
|
||||
@ -211,8 +200,7 @@ struct dfu_file parse_dfu_suffix(const uint8_t* file_contents,
|
||||
if (file_contents_length < DFU_SUFFIX_LENGTH) {
|
||||
reason = "File too short for DFU suffix";
|
||||
missing_suffix = 1;
|
||||
output.size.firmware = 0;
|
||||
return output;
|
||||
goto checked;
|
||||
}
|
||||
|
||||
dfu_suffix = file_contents + file_contents_length - DFU_SUFFIX_LENGTH;
|
||||
@ -220,8 +208,7 @@ struct dfu_file parse_dfu_suffix(const uint8_t* file_contents,
|
||||
if (dfu_suffix[10] != 'D' || dfu_suffix[9] != 'F' || dfu_suffix[8] != 'U') {
|
||||
reason = "Invalid DFU suffix signature";
|
||||
missing_suffix = 1;
|
||||
output.size.firmware = 0;
|
||||
return output;
|
||||
goto checked;
|
||||
}
|
||||
// Calculate contents CRC32
|
||||
for (int i = 0; i < file_contents_length - 4; i++) {
|
||||
@ -234,9 +221,7 @@ struct dfu_file parse_dfu_suffix(const uint8_t* file_contents,
|
||||
if (output.dwCRC != crc) {
|
||||
reason = "DFU suffix CRC does not match";
|
||||
missing_suffix = 1;
|
||||
|
||||
output.size.firmware = 0;
|
||||
return output;
|
||||
goto checked;
|
||||
}
|
||||
|
||||
/* At this point we believe we have a DFU suffix
|
||||
@ -248,21 +233,18 @@ struct dfu_file parse_dfu_suffix(const uint8_t* file_contents,
|
||||
|
||||
if (output.size.suffix < DFU_SUFFIX_LENGTH) {
|
||||
fprintf(stderr, "Unsupported DFU suffix length %d", output.size.suffix);
|
||||
output.size.firmware = 0;
|
||||
return output;
|
||||
}
|
||||
|
||||
if (output.size.suffix > file_contents_length) {
|
||||
fprintf(stderr, "Invalid DFU suffix length %d", output.size.suffix);
|
||||
output.size.firmware = 0;
|
||||
return output;
|
||||
}
|
||||
|
||||
output.idVendor = (dfu_suffix[5] << 8) + dfu_suffix[4];
|
||||
output.idProduct = (dfu_suffix[3] << 8) + dfu_suffix[2];
|
||||
output.bcdDevice = (dfu_suffix[1] << 8) + dfu_suffix[0];
|
||||
|
||||
const int res = probe_prefix(&output);
|
||||
checked:
|
||||
int res = probe_prefix(&output);
|
||||
|
||||
if (output.size.prefix) {
|
||||
const uint8_t* data = file_contents;
|
||||
|
@ -1,11 +1,6 @@
|
||||
#ifndef PARSE_FILE_H_
|
||||
#define PARSE_FILE_H_
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(_MSC_VER)
|
||||
#include <BaseTsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
#include "parsed_firmware_file.h"
|
||||
|
||||
#define PARSED_ERROR_INVALID_FILETYPE -0x1000
|
||||
@ -24,5 +19,3 @@ int parse_firmware_file(const char* file_path_on_disk,
|
||||
// Internal util
|
||||
ssize_t get_file_contents(const char* file_path_on_disk,
|
||||
uint8_t** file_contents);
|
||||
|
||||
#endif // PARSE_FILE_H_
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef PARSED_FIRMWARE_H_
|
||||
#define PARSED_FIRMWARE_H_
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@ -14,4 +13,3 @@ typedef struct {
|
||||
size_t payload_length; // Size of the payload
|
||||
size_t payload_address; // Start address of the payload
|
||||
} parsed_firmware_file_t;
|
||||
#endif // PARSED_FIRMWARE_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user