diff --git a/samples/Makefile.eeglobal_sample b/samples/Makefile.eeglobal_sample index 05babd11031..c4b5ffd9835 100644 --- a/samples/Makefile.eeglobal_sample +++ b/samples/Makefile.eeglobal_sample @@ -98,6 +98,6 @@ ifeq (_$(IOPRP_CONTENTS)_,__) $(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty) else $(DIR_GUARD) - romimg -c $@ $< + romimg -C $@ $< endif diff --git a/tools/romimg/src/main.c b/tools/romimg/src/main.c index 9a706ee3a3b..ef724899d6a 100644 --- a/tools/romimg/src/main.c +++ b/tools/romimg/src/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "romimg.h" @@ -34,13 +35,15 @@ static void DisplayROMImgDetails(const ROMIMG *ROMImg) static void DisplaySyntaxHelp(void) { - printf(REDBOLD"Syntax error"DEFCOL". Syntax:\n" - "ROMIMG -c \n\tCreate ROM image\n" + printf("Syntax:\n" + "ROMIMG -c \n\tCreate ROM image *\n" "ROMIMG -l \n\tList files in ROM image\n" - "ROMIMG -a \n\tAdd file(s) to ROM image\n" + "ROMIMG -a \n\tAdd file(s) to ROM image *\n" "ROMIMG -d \n\tDelete file(s) from ROM image\n" "ROMIMG -x \n\tExtract all files from ROM image\n" - "ROMIMG -x \n\tExtract file from ROM image\n"); + "ROMIMG -x \n\tExtract file from ROM image\n" + "\n note*: write the switch in uppercase to perform filename transformation (eg: 'ioman.irx' > 'IOMAN')\n" + ); } static void DisplayAddDeleteOperationResult(int result, const char *InvolvedFile) @@ -80,31 +83,30 @@ int main(int argc, char **argv) if (argc < 2) { DisplaySyntaxHelp(); - DPRINTF("ERROR: LESS THAN TWO ARGS PROVIDED\n"); return EINVAL; } - if (argc >= 4 && strcmp(argv[1], "-c") == 0) { + if (argc >= 4 && strcasecmp(argv[1], "-c") == 0) { if ((result = CreateBlankROMImg(argv[2], &ROMImg)) == 0) { for (FilesAffected = 0, i = 0; i < argc - 3; i++) { printf("Adding file '%s'", argv[3 + i]); - if ((result = AddFile(&ROMImg, argv[3 + i])) == 0) + if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0) FilesAffected++; printf(result == 0 ? GRNBOLD" done!"DEFCOL"\n" : REDBOLD" failed!"DEFCOL"\n"); } if (FilesAffected > 0) { - printf("Writing image..."); + printf("Writing image... "); printf("%s", (result = WriteROMImg(argv[2], &ROMImg)) == 0 ? GRNBOLD"done!"DEFCOL"\n" : REDBOLD"failed!"DEFCOL"\n"); } UnloadROMImg(&ROMImg); } else ERROR("(Internal fault) Can't create blank image file: %d (%s). Please report.\n", result, strerror(result)); - } else if (argc >= 4 && strcmp(argv[1], "-a") == 0) { + } else if (argc >= 4 && strcasecmp(argv[1], "-a") == 0) { if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) { for (i = 0, FilesAffected = 0; i < argc - 3; i++) { printf("Adding file '%s'", argv[3 + i]); - if ((result = AddFile(&ROMImg, argv[3 + i])) == 0) + if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0) FilesAffected++; DisplayAddDeleteOperationResult(result, argv[3 + i]); } diff --git a/tools/romimg/src/platform.c b/tools/romimg/src/platform.c index 965c38f680f..14e4a6c6c16 100644 --- a/tools/romimg/src/platform.c +++ b/tools/romimg/src/platform.c @@ -4,6 +4,7 @@ #include #include +#include #include "dprintf.h" #if defined(_WIN32) || defined(WIN32) #include @@ -114,3 +115,12 @@ int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize) return EIO; #endif } + +void upperbuff(char *temp) +{ + char *s = temp; + while (*s) { + *s = toupper((unsigned char) *s); + s++; + } +} diff --git a/tools/romimg/src/platform.h b/tools/romimg/src/platform.h index 8189da9a552..0eba7357d90 100644 --- a/tools/romimg/src/platform.h +++ b/tools/romimg/src/platform.h @@ -6,6 +6,7 @@ int GetLocalhostName(char *buffer, unsigned int BufferSize); unsigned int GetSystemDate(void); unsigned int GetFileCreationDate(const char *path); int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize); +void upperbuff(char *temp); #if defined(_WIN32) || defined(WIN32) #define PATHSEP '\\' diff --git a/tools/romimg/src/romimg.c b/tools/romimg/src/romimg.c index f917e659ef4..04c060f7df1 100644 --- a/tools/romimg/src/romimg.c +++ b/tools/romimg/src/romimg.c @@ -160,7 +160,7 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg) GetCurrentWorkingDirectory(cwd, sizeof(cwd)); /* Comment format: YYYYMMDD-XXXYYY,conffile,,@/ */ CommentLength = IMAGE_COMMENT_BASESIZE + strlen(filename) + sizeof(LocalhostName) + sizeof(UserName) + MAX_PATH; - ROMImg->comment = (char *)calloc(0, CommentLength+1); + ROMImg->comment = (char *)malloc( CommentLength+1); if (!ROMImg->comment) return ENOMEM; snprintf(ROMImg->comment, CommentLength, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, BUFCHK(UserName), BUFCHK(LocalhostName), cwd); @@ -453,8 +453,9 @@ static int AddExtInfoStat(struct FileEntry *file, unsigned char type, void *data return result; } -int AddFile(ROMIMG *ROMImg, const char *path) +int AddFile(ROMIMG *ROMImg, const char *path, int upperconv) { + char tbuf[10] = "\0"; // we dont need a large buf, this is for filling in the filename on ROMFS FILE *InputFile; int result; unsigned int FileDateStamp; @@ -462,6 +463,16 @@ int AddFile(ROMIMG *ROMImg, const char *path) if ((InputFile = fopen(path, "rb")) != NULL) { const char* fname = strrchr(path, PATHSEP); if (fname == NULL) fname = path; else fname++; + if (upperconv) { + strncpy(tbuf, fname, sizeof(tbuf)); + tbuf[sizeof(tbuf) - 1] = '\0'; + if (tbuf[0] != '\0') { + upperbuff(tbuf); + fname = tbuf; + char* T = strrchr(fname, '.'); + if (T != NULL) *T = '\0'; //null terminate extension + } + } int size; fseek(InputFile, 0, SEEK_END); size = ftell(InputFile); @@ -477,7 +488,7 @@ int AddFile(ROMIMG *ROMImg, const char *path) file = &ROMImg->files[ROMImg->NumFiles - 1]; memset(&ROMImg->files[ROMImg->NumFiles - 1], 0, sizeof(struct FileEntry)); - strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name) - 1); + strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name)); file->RomDir.name[sizeof(file->RomDir.name) - 1] = '\0'; file->RomDir.ExtInfoEntrySize = 0; diff --git a/tools/romimg/src/romimg.h b/tools/romimg/src/romimg.h index ad6f872e7c6..ecbabb3ec8f 100644 --- a/tools/romimg/src/romimg.h +++ b/tools/romimg/src/romimg.h @@ -68,9 +68,9 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg); int WriteROMImg(const char *file, const ROMIMG *ROMImg); int LoadROMImg(ROMIMG *ROMImg, const char *path); void UnloadROMImg(ROMIMG *ROMImg); -int AddFile(ROMIMG *ROMImg, const char *path); +int AddFile(ROMIMG *ROMImg, const char *path, int upperconv); int DeleteFile(ROMIMG *ROMImg, const char *filename); int ExtractFile(const ROMIMG *ROMImg, const char *filename, const char *FileToExtract); int IsFileExists(const ROMIMG *ROMImg, const char *filename); -#endif /* __ROMING_H__ */ \ No newline at end of file +#endif /* __ROMING_H__ */