9 #include "flash_confs.h"
11 size_t get_name_match(const flash_configs* , const char * name);
13 void prepend(FILE * fno, size_t offset);
14 int main(int argc, char *argv[]){
20 size_t padding = 0x1000; // default offset for nor
23 const flash_configs * configs = get_flash_confs();
24 const flexspi_nor_config_t * config;
25 while ((opt = getopt(argc, argv, "p:n:o:b:")) != -1)
31 padding = strtol(optarg, NULL, 0);
33 printf("Invalid value for -%c.\n", opt);
38 strncpy(name,optarg,32);
41 strncpy(fname,optarg,32);
44 bin = strtol(optarg, NULL, 0);
46 printf("Invalid value for -%c.\n", opt);
59 if(!strnlen(fname,32))
60 puts("Need an output file name.");
62 puts("Need a flash config name.");
63 if(!strnlen(name,32) || !strnlen(fname,32))
66 index = get_name_match(configs,name);
68 printf("No match found for %s!\nExiting...\n",name);
71 printf("Match found using %s flash config.\n",configs[index].name);
73 config = &configs[index].config;
75 fnum = fopen(fname,"wb+");
77 printf("Can't open %s for writing!\nExiting...\n",fname);
81 fwrite(config,sizeof(flexspi_nor_config_t),1,fnum);
82 for(size_t i = sizeof(flexspi_nor_config_t); i < padding;i++)
91 size_t get_name_match(const flash_configs* configs, const char * name){
93 while(*configs[i].name){
94 if(strncmp(configs[i].name,name,32) == 0)
100 void prepend(FILE * fno, size_t offset){
104 uboot = fopen("u-boot.img","r");
106 puts("Can't open u-boot.img for reading!\nExiting...");
110 SPL = fopen("SPL","r");
112 puts("Can't open SPL for reading!\nExiting...");
117 fseek(SPL, 0, SEEK_END);
122 fwrite(buf,sz,1,fno);
124 for(size_t i = ftell(fno); i < offset;i++)
127 fseek(uboot, 0, SEEK_END);
129 buf = realloc(buf, sz);
131 fread(buf,sz,1,uboot);
132 fwrite(buf,sz,1,fno);