#ifndef __CONFIG_H
#define __CONFIG_H
-#define config_version 1 ///< Static version of the config. Updated when the config has changed in an
+#define config_version 2 ///< Static version of the config. Updated when the config has changed in an
///< incompatible way.
#define CONFIG_MAGIC "OVAN" ///< Magic to identify config files.
uint8_t options[256]; ///< Options in the menu - deliberately large to avoid
///< config version bumps.
-
- uint64_t patch_ids[256]; ///< What patches are enabled by UUID. 256 is an
- ///< arbitrary limit - contact me if you hit it.
-} __attribute__((packed));
-
-/* State of a patch file
- */
-struct patch_state
-{
- char filename[256]; ///< Patch filename.
-
- uint8_t state; ///< Status of patch.
} __attribute__((packed));
#ifdef LOADER
if (!(conf_handle = fopen(config_file_path, "w")))
poweroff();
- fwrite(config, 1, sizeof(struct config_file), conf_handle);
+ fwrite(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle);
fclose(conf_handle);
}
cid[0] >>= 4;
}
- config = (struct config_file*)malloc(sizeof(struct config_file));
- memset(config, 0, sizeof(struct config_file));
+ config = (struct config_file*)malloc(sizeof(struct config_file) + FCRAM_SPACING / 2);
+ memset(config, 0, sizeof(struct config_file) + FCRAM_SPACING / 2);
+ enable_list = (uint8_t*)config + sizeof(struct config_file);
}
// Zero on success.
if (!(conf_handle = fopen(config_file_path, "r"))) {
regenerate_config();
} else {
- fread(config, 1, sizeof(struct config_file), conf_handle);
+ fread(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle);
+
fclose(conf_handle);
if (memcmp(&(config->magic), CONFIG_MAGIC, 4)) {
regenerate_config();
}
- if (config->config_ver < config_version) {
+ if (config->config_ver != config_version) {
f_unlink(config_file_path);
regenerate_config();
}
void
save_config()
{
- write_file(enable_list, PATH_TEMP "/PATCHENABLE", FCRAM_SPACING / 2);
-
f_unlink(config_file_path);
if (!(conf_handle = fopen(config_file_path, "w")))
while(1);
- fwrite(config, 1, sizeof(struct config_file), conf_handle);
+ fwrite(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle);
+
fclose(conf_handle);
}
// FIXME - Remove limit
#define MAX_PATCHES 256
struct options_s *patches = NULL;
-uint8_t *enable_list = NULL;
+uint8_t *enable_list;
static struct options_s options[] = {
// Patches.
current_menu_index_patches = 0;
- if (!enable_list)
- enable_list = malloc(FCRAM_SPACING / 2); // FIXME - the PATCHENABLE file has to go. Badly.
+ if (!patches)
+ patches = malloc(sizeof(struct options_s) * 258); // FIXME - hard limit. Implement realloc.
- if (!patches)
- patches = malloc(sizeof(struct options_s) * 258); // FIXME - hard limit. Implement realloc.
+ strncpy(patches[0].name, "Patches", 64);
+ strncpy(patches[0].desc, "", 255);
+ patches[0].index = 0;
+ patches[0].allowed = not_option;
+ patches[0].a = 1;
+ patches[0].b = 0;
+ patches[0].indent = 0;
- memset(enable_list, 0, FCRAM_SPACING / 2);
-
- if (!desc_is_fname) {
- strncpy(patches[0].name, "Patches", 64);
- strncpy(patches[0].desc, "", 255);
- patches[0].index = 0;
- patches[0].allowed = not_option;
- patches[0].a = 1;
- patches[0].b = 0;
- patches[0].indent = 0;
-
- current_menu_index_patches += 1;
- }
+ current_menu_index_patches += 1;
recurse_call(name, patch_func);
patches[current_menu_index_patches].index = -1;
-
- FILE *f;
- if ((f = fopen(PATH_TEMP "/PATCHENABLE", "r"))) {
- fread(enable_list, 1, FCRAM_SPACING / 2, f);
- fclose(f);
- }
}
void
void list_patches_build(char *name, int desc_is_fname);
-int
-generate_patch_cache()
+void
+patch_cache_func(char* fpath)
{
- // Remove cache
- rrmdir(PATH_LOADER_CACHE);
- f_mkdir(PATH_LOADER_CACHE);
+ FILINFO f2;
+ if (f_stat(fpath, &f2) != FR_OK)
+ return;
- list_patches_build(PATH_PATCHES, 1);
+ if (!(f2.fattrib & AM_DIR)) {
+ struct system_patch p;
+ read_file(&p, fpath, sizeof(struct system_patch));
- for (int i = 0; patches[i].index != -1; i++) {
- if (enable_list[patches[i].index]) {
+ if (memcmp(p.magic, "AIDA", 4))
+ return;
+
+ if (enable_list[p.uuid]) {
// Patch is enabled. Cache it.
- if (execb(patches[i].desc, 1)) {
- abort("Failed to apply:\n %s\n", patches[i].name);
+ if (execb(fpath, 1)) {
+ abort("Failed to cache:\n %s\n", fpath);
}
wait();
}
}
+}
+
+int
+generate_patch_cache()
+{
+ // Remove cache
+ rrmdir(PATH_LOADER_CACHE);
+ f_mkdir(PATH_LOADER_CACHE);
+
+ recurse_call(PATH_PATCHES, patch_cache_func);
return 0;
}