2018-04-14 05:28:45 -03:00
|
|
|
/*
|
|
|
|
implement a file store for embedded firmware images
|
|
|
|
*/
|
2019-05-20 11:57:43 -03:00
|
|
|
#pragma once
|
2018-04-14 05:28:45 -03:00
|
|
|
|
2022-02-28 21:19:18 -04:00
|
|
|
#include <stdint.h>
|
2018-04-14 05:28:45 -03:00
|
|
|
|
|
|
|
class AP_ROMFS {
|
|
|
|
public:
|
2024-02-23 17:59:40 -04:00
|
|
|
// Find the named file and return its decompressed data and size. Caller
|
|
|
|
// must call AP_ROMFS::free() on the return value after use to free it.
|
|
|
|
// The data is guaranteed to be null-terminated such that it can be
|
|
|
|
// treated as a string.
|
2019-10-23 06:54:32 -03:00
|
|
|
static const uint8_t *find_decompress(const char *name, uint32_t &size);
|
|
|
|
|
2024-02-23 17:59:40 -04:00
|
|
|
// free decompressed file data
|
2019-10-23 06:54:32 -03:00
|
|
|
static void free(const uint8_t *data);
|
|
|
|
|
2024-03-18 16:08:54 -03:00
|
|
|
// get the size of a file without decompressing
|
|
|
|
static bool find_size(const char *name, uint32_t &size);
|
|
|
|
|
2020-03-06 20:53:39 -04:00
|
|
|
/*
|
|
|
|
directory listing interface. Start with ofs=0. Returns pathnames
|
|
|
|
that match dirname prefix. Ends with nullptr return when no more
|
|
|
|
files found
|
|
|
|
*/
|
|
|
|
static const char *dir_list(const char *dirname, uint16_t &ofs);
|
|
|
|
|
2018-07-09 03:28:28 -03:00
|
|
|
private:
|
2018-04-14 05:28:45 -03:00
|
|
|
struct embedded_file {
|
|
|
|
const char *filename;
|
2023-12-30 15:53:15 -04:00
|
|
|
uint32_t compressed_size;
|
|
|
|
uint32_t decompressed_size;
|
2021-02-22 22:55:49 -04:00
|
|
|
uint32_t crc;
|
2018-04-14 05:28:45 -03:00
|
|
|
const uint8_t *contents;
|
|
|
|
};
|
2023-12-30 15:53:15 -04:00
|
|
|
|
|
|
|
// find an embedded file
|
|
|
|
static const AP_ROMFS::embedded_file *find_file(const char *name);
|
|
|
|
|
2018-04-14 05:28:45 -03:00
|
|
|
static const struct embedded_file files[];
|
|
|
|
};
|