diff --git a/tools/blisp/src/file_parsers/bin/bin_file.h b/tools/blisp/src/file_parsers/bin/bin_file.h new file mode 100644 index 0000000..de58b63 --- /dev/null +++ b/tools/blisp/src/file_parsers/bin/bin_file.h @@ -0,0 +1,25 @@ +// +// Created by ralim on 01/08/23. +// + +#ifndef BLISP_BIN_FILE_H +#define BLISP_BIN_FILE_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int bin_file_parse(const char* file_path_on_disk, + uint8_t** payload, + size_t* payload_length, + size_t* payload_address); +#ifdef __cplusplus +}; +#endif + +#endif // BLISP_BIN_FILE_H diff --git a/tools/blisp/src/file_parsers/parse_file.c b/tools/blisp/src/file_parsers/parse_file.c index 9c1ccc1..029b73e 100644 --- a/tools/blisp/src/file_parsers/parse_file.c +++ b/tools/blisp/src/file_parsers/parse_file.c @@ -1,7 +1,29 @@ #include "parse_file.h" +#include +#include "dfu_file.h" + +const char* get_filename_ext(const char* filename) { + const char* dot = strrchr(filename, '.'); + if (!dot || dot == filename) + return ""; + return dot + 1; +} int parse_firmware_file(const char* file_path_on_disk, parsed_firmware_file_t* parsed_results) { // Switchcase on the extension of the file - + const char* ext = get_filename_ext(file_path_on_disk); + + if (strncmp(ext, "dfu", 3) == 0 || strncmp(ext, "DFU", 3) == 0) { + printf("Input file identified as a .dfu file\r\n"); + // Handle as a .dfu file + return dfu_file_parse("test.dfu", &parsed_results->payload, + &parsed_results->payload_length, + &parsed_results->payload_address); + } else if (strncmp(ext, "bin", 3) == 0 || strncmp(ext, "BIN", 3) == 0) { + printf("Input file identified as a .bin file\r\n"); + // Raw binary file + } + // TODO: Hex files? + return PARSED_ERROR_INVALID_FILETYPE; } \ No newline at end of file diff --git a/tools/blisp/src/file_parsers/parse_file.h b/tools/blisp/src/file_parsers/parse_file.h index c10d4f5..d24ae8c 100644 --- a/tools/blisp/src/file_parsers/parse_file.h +++ b/tools/blisp/src/file_parsers/parse_file.h @@ -1,8 +1,9 @@ #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 */ +#define PARSED_ERROR_INVALID_FILETYPE -0x1000 +#define PARSED_ERROR_TOO_BIG -0x1001 /* Input expands to be too big */ +#define PARSED_ERROR_BAD_DFU -0x1002 /* 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