Skip to content

Commit

Permalink
Merge pull request #673 from israpps/romimg-fix
Browse files Browse the repository at this point in the history
fix romimg bundled on docker containers
  • Loading branch information
fjtrujy authored Nov 11, 2024
2 parents 50072a4 + b10e8ba commit ed5ead7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 35 deletions.
1 change: 1 addition & 0 deletions samples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ release-samples:
$(MKDIR) -p $(SHARE_TARGET)
cp -f Makefile_sample $(SAMPLES_TARGET)/Makefile
cp -f Makefile.pref_sample $(SAMPLES_TARGET)/Makefile.pref
cp -f Makefile.ioprp_sample $(SAMPLES_TARGET)/Makefile.ioprp
cp -f Makefile.eeglobal_sample $(SAMPLES_TARGET)/Makefile.eeglobal
cp -f Makefile.eeglobal_cpp_sample $(SAMPLES_TARGET)/Makefile.eeglobal_cpp
cp -f Makefile.iopglobal_sample $(SAMPLES_TARGET)/Makefile.iopglobal
Expand Down
9 changes: 0 additions & 9 deletions samples/Makefile.eeglobal_sample
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,3 @@ $(EE_ERL): $(EE_OBJS)
$(EE_LIB): $(EE_OBJS)
$(DIR_GUARD)
$(EE_AR) cru $(EE_LIB) $(EE_OBJS)

$(IOPRP_BIN): $(IOPRP_CONTENTS)
ifeq (_$(IOPRP_CONTENTS)_,__)
$(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty)
else
$(DIR_GUARD)
romimg -c $@ $<
endif

15 changes: 15 additions & 0 deletions samples/Makefile.ioprp_sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

$(IOPRP_BIN): $(IOPRP_CONTENTS)
ifeq (_$(IOPRP_CONTENTS)_,__)
$(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty)
else
$(DIR_GUARD)
romimg -C $@ $<
endif
24 changes: 13 additions & 11 deletions tools/romimg/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>

#include "romimg.h"

Expand Down Expand Up @@ -34,13 +35,15 @@ static void DisplayROMImgDetails(const ROMIMG *ROMImg)

static void DisplaySyntaxHelp(void)
{
printf(REDBOLD"Syntax error"DEFCOL". Syntax:\n"
"ROMIMG -c <ROM image> <files>\n\tCreate ROM image\n"
printf("Syntax:\n"
"ROMIMG -c <ROM image> <files>\n\tCreate ROM image *\n"
"ROMIMG -l <ROM image>\n\tList files in ROM image\n"
"ROMIMG -a <ROM image> <file(s)>\n\tAdd file(s) to ROM image\n"
"ROMIMG -a <ROM image> <file(s)>\n\tAdd file(s) to ROM image *\n"
"ROMIMG -d <ROM image> <file(s)>\n\tDelete file(s) from ROM image\n"
"ROMIMG -x <ROM image>\n\tExtract all files from ROM image\n"
"ROMIMG -x <ROM image> <file>\n\tExtract file from ROM image\n");
"ROMIMG -x <ROM image> <file>\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)
Expand Down Expand Up @@ -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. Please report.\n", result);
} else if (argc >= 4 && strcmp(argv[1], "-a") == 0) {
ERROR("(Internal fault) Can't create blank image file: %d (%s). Please report.\n", result, strerror(result));
} 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]);
}
Expand Down
10 changes: 10 additions & 0 deletions tools/romimg/src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <errno.h>
#include <stdlib.h>
#include <ctype.h>
#include "dprintf.h"
#if defined(_WIN32) || defined(WIN32)
#include <windows.h>
Expand Down Expand Up @@ -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++;
}
}
3 changes: 2 additions & 1 deletion tools/romimg/src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ 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 '\\'
#else
#define PATHSEP '/'
#endif

#endif /* __PLATFORM_H__ */
#endif /* __PLATFORM_H__ */
35 changes: 23 additions & 12 deletions tools/romimg/src/romimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>

#include "platform.h"
#include "romimg.h"
#include "SonyRX.h"

#define IMAGE_COMMENT_BASESIZE 31

struct ROMImgStat
{
void *image;
Expand Down Expand Up @@ -139,12 +143,7 @@ static int GetExtInfoStat(const struct ROMImgStat *ImageStat, struct RomDirFileF
int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
{
unsigned int CommentLength;
char LocalhostName[32], cwd[128];
#if defined(_WIN32) || defined(WIN32)
char UserName[32] = "";
#else
char* UserName;
#endif
char LocalhostName[32] = {0}, cwd[PATH_MAX] = {0}, UserName[32] = {0};
struct FileEntry *ResetFile;
struct ExtInfoFieldEntry *ExtInfoEntry;

Expand All @@ -154,14 +153,15 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
#if defined(_WIN32) || defined(WIN32)
GetUsername(UserName, sizeof(UserName));
#else
UserName = getenv("USER");
getlogin_r(UserName, sizeof(UserName));
#endif
GetLocalhostName(LocalhostName, sizeof(LocalhostName));
GetCurrentWorkingDirectory(cwd, sizeof(cwd));
/* Comment format: YYYYMMDD-XXXYYY,conffile,<filename>,<user>@<localhost>/<image path> */
CommentLength = 31 + strlen(filename) + strlen(UserName) + strlen(LocalhostName) + strlen(cwd);
ROMImg->comment = (char *)malloc(CommentLength);
sprintf(ROMImg->comment, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, (UserName[0] =='\0')?"":UserName, LocalhostName, cwd);
CommentLength = IMAGE_COMMENT_BASESIZE + strlen(filename) + sizeof(LocalhostName) + sizeof(UserName) + sizeof(cwd);
ROMImg->comment = (char *)malloc( CommentLength+1);
if (!ROMImg->comment) return ENOMEM;
snprintf(ROMImg->comment, CommentLength, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, UserName, LocalhostName, cwd);

// Create a blank RESET file.
ROMImg->NumFiles = 1;
Expand Down Expand Up @@ -452,15 +452,26 @@ 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[9] = "\0"; // we dont need a large buf, this is for filling in the filename on ROMFS
FILE *InputFile;
int result;
unsigned int FileDateStamp;
unsigned short FileVersion;
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);
Expand All @@ -476,7 +487,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;

Expand Down
4 changes: 2 additions & 2 deletions tools/romimg/src/romimg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
#endif /* __ROMING_H__ */

0 comments on commit ed5ead7

Please sign in to comment.