mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-24 06:07:52 -04:00
add built time output to image generator
Image generator now adds the built time (time + date) to the VHDL image files. Replaced tab by whitespaces.
This commit is contained in:
parent
f9be9ad9fc
commit
62639cbb6c
1 changed files with 125 additions and 104 deletions
|
@ -36,6 +36,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
const uint32_t signature = 0x4788CAFE;
|
||||
|
@ -43,23 +44,23 @@ const uint32_t signature = 0x4788CAFE;
|
|||
int main(int argc, char *argv[]) {
|
||||
|
||||
if ((argc != 4) && (argc != 5)){
|
||||
printf("<<< NEORV32 executable image generator >>>\n"
|
||||
"by Stephan Nolting\n"
|
||||
"Three arguments are required.\n"
|
||||
"1st: Option\n"
|
||||
" -app_bin : Generate application executable binary (binary file, little-endian, with header) \n"
|
||||
" -app_hex : Generate application raw executable (hex file, no header)\n"
|
||||
" -app_img : Generate application raw executable memory image (vhdl file, no header)\n"
|
||||
" -bld_img : Generate bootloader raw executable memory image (vdhl file, no header)\n"
|
||||
"2nd: Input file (raw binary image)\n"
|
||||
"3rd: Output file\n"
|
||||
"4th: Project folder (optional)\n");
|
||||
return 0;
|
||||
printf("<<< NEORV32 executable image generator >>>\n"
|
||||
"by Stephan Nolting\n"
|
||||
"Three arguments are required.\n"
|
||||
"1st: Option\n"
|
||||
" -app_bin : Generate application executable binary (binary file, little-endian, with header) \n"
|
||||
" -app_hex : Generate application raw executable (hex file, no header)\n"
|
||||
" -app_img : Generate application raw executable memory image (vhdl file, no header)\n"
|
||||
" -bld_img : Generate bootloader raw executable memory image (vdhl file, no header)\n"
|
||||
"2nd: Input file (raw binary image)\n"
|
||||
"3rd: Output file\n"
|
||||
"4th: Project folder (optional)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *input, *output;
|
||||
unsigned char buffer[4];
|
||||
char tmp_string[1024];
|
||||
char tmp_string[2048];
|
||||
uint32_t tmp = 0, size = 0, checksum = 0;
|
||||
unsigned int i = 0;
|
||||
int option = 0;
|
||||
|
@ -74,8 +75,8 @@ int main(int argc, char *argv[]) {
|
|||
else if (strcmp(argv[1], "-app_hex") == 0)
|
||||
option = 4;
|
||||
else {
|
||||
printf("Invalid option!");
|
||||
return 1;
|
||||
printf("Invalid option!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// open input file
|
||||
|
@ -112,6 +113,24 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Get image's compilation date and time
|
||||
// ------------------------------------------------------------
|
||||
time_t time_current;
|
||||
time(&time_current);
|
||||
struct tm *time_local = localtime(&time_current);
|
||||
char compile_time[64];
|
||||
|
||||
snprintf(compile_time, 64, "%02d.%02d.%d %02d:%02d:%02d",
|
||||
time_local->tm_mday,
|
||||
time_local->tm_mon + 1,
|
||||
time_local->tm_year + 1900,
|
||||
time_local->tm_hour,
|
||||
time_local->tm_min,
|
||||
time_local->tm_sec
|
||||
);
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Get size of application (in bytes)
|
||||
// ------------------------------------------------------------
|
||||
|
@ -193,95 +212,22 @@ int main(int argc, char *argv[]) {
|
|||
// ------------------------------------------------------------
|
||||
if (option == 2) {
|
||||
|
||||
// header
|
||||
// header
|
||||
sprintf(tmp_string, "-- The NEORV32 RISC-V Processor, https://github.com/stnolting/neorv32\n"
|
||||
"-- Auto-generated memory init file (for APPLICATION) from source file <%s/%s>\n"
|
||||
"-- Size: %lu bytes\n"
|
||||
"-- MARCH: %s\n"
|
||||
"\n"
|
||||
"library ieee;\n"
|
||||
"use ieee.std_logic_1164.all;\n"
|
||||
"\n"
|
||||
"-- Auto-generated memory init file (for APPLICATION) from source file <%s/%s>\n"
|
||||
"-- Size: %lu bytes\n"
|
||||
"-- MARCH: %s\n"
|
||||
"-- Built: %s\n"
|
||||
"\n"
|
||||
"library ieee;\n"
|
||||
"use ieee.std_logic_1164.all;\n"
|
||||
"\n"
|
||||
"library neorv32;\n"
|
||||
"use neorv32.neorv32_package.all;\n"
|
||||
"\n"
|
||||
"package neorv32_application_image is\n"
|
||||
"\n"
|
||||
" constant application_init_image : mem32_t := (\n", argv[4], argv[2], raw_exe_size, string_march);
|
||||
fputs(tmp_string, output);
|
||||
|
||||
// data
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
i = 0;
|
||||
|
||||
while (i < (input_words-1)) {
|
||||
if (fread(&buffer, sizeof(unsigned char), 4, input) != 0) {
|
||||
tmp = (uint32_t)(buffer[0] << 0);
|
||||
tmp |= (uint32_t)(buffer[1] << 8);
|
||||
tmp |= (uint32_t)(buffer[2] << 16);
|
||||
tmp |= (uint32_t)(buffer[3] << 24);
|
||||
sprintf(tmp_string, " %08d => x\"%08x\",\n", i, (unsigned int)tmp);
|
||||
fputs(tmp_string, output);
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
printf("Unexpected input file end!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fread(&buffer, sizeof(unsigned char), 4, input) != 0) {
|
||||
tmp = (uint32_t)(buffer[0] << 0);
|
||||
tmp |= (uint32_t)(buffer[1] << 8);
|
||||
tmp |= (uint32_t)(buffer[2] << 16);
|
||||
tmp |= (uint32_t)(buffer[3] << 24);
|
||||
sprintf(tmp_string, " %08d => x\"%08x\"\n", i, (unsigned int)tmp);
|
||||
fputs(tmp_string, output);
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
printf("Unexpected input file end!\n");
|
||||
}
|
||||
|
||||
// end
|
||||
sprintf(tmp_string, " );\n"
|
||||
"\n"
|
||||
"end neorv32_application_image;\n");
|
||||
fputs(tmp_string, output);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Generate BOOTLOADER's executable memory init file (no header!)
|
||||
// ------------------------------------------------------------
|
||||
if (option == 3) {
|
||||
|
||||
// header
|
||||
sprintf(tmp_string, "-- The NEORV32 RISC-V Processor, https://github.com/stnolting/neorv32\n"
|
||||
"-- Auto-generated memory init file (for BOOTLOADER) from source file <%s/%s>\n"
|
||||
"-- Size: %lu bytes\n"
|
||||
"-- MARCH: %s\n"
|
||||
"\n"
|
||||
"library ieee;\n"
|
||||
"use ieee.std_logic_1164.all;\n"
|
||||
"\n"
|
||||
"library neorv32;\n"
|
||||
"use neorv32.neorv32_package.all;\n"
|
||||
"\n"
|
||||
"package neorv32_bootloader_image is\n"
|
||||
"\n"
|
||||
" constant bootloader_init_image : mem32_t := (\n", argv[4], argv[2], raw_exe_size, string_march);
|
||||
"\n"
|
||||
"package neorv32_application_image is\n"
|
||||
"\n"
|
||||
" constant application_init_image : mem32_t := (\n", argv[4], argv[2], raw_exe_size, string_march, compile_time);
|
||||
fputs(tmp_string, output);
|
||||
|
||||
// data
|
||||
|
@ -328,10 +274,85 @@ int main(int argc, char *argv[]) {
|
|||
printf("Unexpected input file end!\n");
|
||||
}
|
||||
|
||||
// end
|
||||
// end
|
||||
sprintf(tmp_string, " );\n"
|
||||
"\n"
|
||||
"end neorv32_bootloader_image;\n");
|
||||
"\n"
|
||||
"end neorv32_application_image;\n");
|
||||
fputs(tmp_string, output);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Generate BOOTLOADER's executable memory init file (no header!)
|
||||
// ------------------------------------------------------------
|
||||
if (option == 3) {
|
||||
|
||||
// header
|
||||
sprintf(tmp_string, "-- The NEORV32 RISC-V Processor, https://github.com/stnolting/neorv32\n"
|
||||
"-- Auto-generated memory init file (for BOOTLOADER) from source file <%s/%s>\n"
|
||||
"-- Size: %lu bytes\n"
|
||||
"-- MARCH: %s\n"
|
||||
"-- Built: %s\n"
|
||||
"\n"
|
||||
"library ieee;\n"
|
||||
"use ieee.std_logic_1164.all;\n"
|
||||
"\n"
|
||||
"library neorv32;\n"
|
||||
"use neorv32.neorv32_package.all;\n"
|
||||
"\n"
|
||||
"package neorv32_bootloader_image is\n"
|
||||
"\n"
|
||||
" constant bootloader_init_image : mem32_t := (\n", argv[4], argv[2], raw_exe_size, string_march, compile_time);
|
||||
fputs(tmp_string, output);
|
||||
|
||||
// data
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
i = 0;
|
||||
|
||||
while (i < (input_words-1)) {
|
||||
if (fread(&buffer, sizeof(unsigned char), 4, input) != 0) {
|
||||
tmp = (uint32_t)(buffer[0] << 0);
|
||||
tmp |= (uint32_t)(buffer[1] << 8);
|
||||
tmp |= (uint32_t)(buffer[2] << 16);
|
||||
tmp |= (uint32_t)(buffer[3] << 24);
|
||||
sprintf(tmp_string, " %08d => x\"%08x\",\n", i, (unsigned int)tmp);
|
||||
fputs(tmp_string, output);
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
printf("Unexpected input file end!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fread(&buffer, sizeof(unsigned char), 4, input) != 0) {
|
||||
tmp = (uint32_t)(buffer[0] << 0);
|
||||
tmp |= (uint32_t)(buffer[1] << 8);
|
||||
tmp |= (uint32_t)(buffer[2] << 16);
|
||||
tmp |= (uint32_t)(buffer[3] << 24);
|
||||
sprintf(tmp_string, " %08d => x\"%08x\"\n", i, (unsigned int)tmp);
|
||||
fputs(tmp_string, output);
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
printf("Unexpected input file end!\n");
|
||||
}
|
||||
|
||||
// end
|
||||
sprintf(tmp_string, " );\n"
|
||||
"\n"
|
||||
"end neorv32_bootloader_image;\n");
|
||||
fputs(tmp_string, output);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue