mirror of
https://github.com/pine64/blisp.git
synced 2025-03-13 10:28:57 +00:00
Scratching out parsers
This commit is contained in:
parent
013c1d0141
commit
cf00bedeaf
25
tools/blisp/src/file_parsers/bin/bin_file.h
Normal file
25
tools/blisp/src/file_parsers/bin/bin_file.h
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by ralim on 01/08/23.
|
||||
//
|
||||
|
||||
#ifndef BLISP_BIN_FILE_H
|
||||
#define BLISP_BIN_FILE_H
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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
|
@ -1,7 +1,29 @@
|
||||
#include "parse_file.h"
|
||||
#include <string.h>
|
||||
#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;
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user