mirror of
https://github.com/pine64/blisp.git
synced 2025-03-13 10:28:57 +00:00
Relocate dfu parsing and link in
This commit is contained in:
parent
98343db387
commit
013c1d0141
@ -2,7 +2,10 @@ set(ARGTABLE3_ENABLE_TESTS OFF CACHE BOOL "Enable unit tests")
|
||||
set(ARGTABLE3_ENABLE_EXAMPLES OFF CACHE BOOL "Enable examples")
|
||||
#set(ARGTABLE3_REPLACE_GETOPT OFF CACHE BOOL "Replace getopt in the system C library")
|
||||
|
||||
add_executable(blisp src/main.c src/cmd/write.c src/util.c src/common.c src/cmd/iot.c src/cmd/dfu/dfu_file.c src/cmd/dfu/dfu_crc.c)
|
||||
add_executable(blisp src/main.c src/cmd/write.c src/util.c src/common.c src/cmd/iot.c)
|
||||
|
||||
add_subdirectory(src/file_parsers)
|
||||
|
||||
|
||||
if(BLISP_USE_SYSTEM_LIBRARIES)
|
||||
find_package(Argtable3 REQUIRED)
|
||||
@ -18,7 +21,7 @@ target_include_directories(blisp PRIVATE
|
||||
|
||||
target_link_libraries(blisp PRIVATE
|
||||
argtable3
|
||||
libblisp_static)
|
||||
libblisp_static file_parsers)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(blisp PRIVATE Setupapi.lib)
|
||||
|
@ -178,6 +178,16 @@ blisp_return_t blisp_flash_firmware() {
|
||||
goto exit1;
|
||||
}
|
||||
|
||||
// Open the file to be flashed; to determine the size of the section of flash
|
||||
// to erase
|
||||
int64_t firmware_file_size = 0;
|
||||
const uint32_t firmware_base_address_offset =
|
||||
0x2000; // Firmware files start 0x2000 offset into flash to skip the boot
|
||||
// header
|
||||
int64_t firmware_file_start_address = 0;
|
||||
|
||||
|
||||
|
||||
FILE* firmware_file = fopen(binary_to_write->filename[0], "rb");
|
||||
if (firmware_file == NULL) {
|
||||
fprintf(stderr, "Failed to open firmware file \"%s\".\n",
|
||||
@ -185,9 +195,10 @@ blisp_return_t blisp_flash_firmware() {
|
||||
goto exit1;
|
||||
}
|
||||
fseek(firmware_file, 0, SEEK_END);
|
||||
int64_t firmware_file_size = ftell(firmware_file);
|
||||
firmware_file_size = ftell(firmware_file);
|
||||
rewind(firmware_file);
|
||||
|
||||
// Create a default boot header section in ram to be written out
|
||||
struct bfl_boot_header boot_header;
|
||||
fill_up_boot_header(&boot_header);
|
||||
|
||||
|
23
tools/blisp/src/file_parsers/CMakeLists.txt
Normal file
23
tools/blisp/src/file_parsers/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
list(APPEND ADD_INCLUDE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/bin"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/dfu"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE sources
|
||||
)
|
||||
list(APPEND ADD_SRCS ${sources})
|
||||
|
||||
add_library(file_parsers
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/bin/bin_file.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/dfu/dfu_file.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/dfu/dfu_crc.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/parse_file.c"
|
||||
)
|
||||
|
||||
target_include_directories(file_parsers PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bin
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/dfu
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
||||
)
|
0
tools/blisp/src/file_parsers/bin/bin_file.c
Normal file
0
tools/blisp/src/file_parsers/bin/bin_file.c
Normal file
@ -13,9 +13,11 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int dfu_file_parse(const char* file_path_on_disk, uint8_t** payload,
|
||||
size_t* payload_length, size_t* payload_address);
|
||||
// Parse the dfu file and returns 0 if ok, or -ve on error parsing
|
||||
int dfu_file_parse(const char* file_path_on_disk,
|
||||
uint8_t** payload,
|
||||
size_t* payload_length,
|
||||
size_t* payload_address);
|
||||
// Internal
|
||||
|
||||
uint32_t crc32_byte(uint32_t accum, uint8_t delta);
|
7
tools/blisp/src/file_parsers/parse_file.c
Normal file
7
tools/blisp/src/file_parsers/parse_file.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include "parse_file.h"
|
||||
|
||||
int parse_firmware_file(const char* file_path_on_disk,
|
||||
parsed_firmware_file_t* parsed_results) {
|
||||
// Switchcase on the extension of the file
|
||||
|
||||
}
|
13
tools/blisp/src/file_parsers/parse_file.h
Normal file
13
tools/blisp/src/file_parsers/parse_file.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "parsed_firmware_file.h"
|
||||
|
||||
#define PARSED_ERROR_TOO_BIG = -0x1000 /* Input expands to be too big */
|
||||
#define PARSED_ERROR_BAD_DFU = -0x1001 /* DFU file provided but not valid */
|
||||
|
||||
// This attempts to parse the given file, and returns the parsed version of that
|
||||
// file. This will handle any repacking required to create one contigious file
|
||||
// Eg if the input file has holes,they will be 0x00 filled
|
||||
// And headers etc are parsed to determine start position
|
||||
|
||||
int parse_firmware_file(const char* file_path_on_disk,
|
||||
parsed_firmware_file_t* parsed_results);
|
14
tools/blisp/src/file_parsers/parsed_firmware_file.h
Normal file
14
tools/blisp/src/file_parsers/parsed_firmware_file.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Parsed firmware file is a generic struct that we parse from a user input
|
||||
// firmware file This is used so that we can (relatively) seamlessly handle
|
||||
// .bin, .hex and .def files
|
||||
|
||||
typedef struct {
|
||||
bool needs_boot_struct; // If true, boot struct should be generated
|
||||
uint8_t* payload; // The main firmware payload
|
||||
size_t payload_length; // Size of the payload
|
||||
size_t payload_address; // Start address of the payload
|
||||
} parsed_firmware_file_t;
|
@ -45,7 +45,7 @@ int8_t args_parse_exec(int argc, char** argv) {
|
||||
print_help();
|
||||
return BLISP_OK;
|
||||
} else if (version->count) {
|
||||
printf("blisp v0.0.3\n");
|
||||
printf("blisp v0.0.4\n");
|
||||
printf("Copyright (C) 2023 Marek Kraus and PINE64 Community\n");
|
||||
return BLISP_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user