Skip to content

Commit ed5ead7

Browse files
authored
Merge pull request #673 from israpps/romimg-fix
fix romimg bundled on docker containers
2 parents 50072a4 + b10e8ba commit ed5ead7

File tree

8 files changed

+66
-35
lines changed

8 files changed

+66
-35
lines changed

samples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ release-samples:
2323
$(MKDIR) -p $(SHARE_TARGET)
2424
cp -f Makefile_sample $(SAMPLES_TARGET)/Makefile
2525
cp -f Makefile.pref_sample $(SAMPLES_TARGET)/Makefile.pref
26+
cp -f Makefile.ioprp_sample $(SAMPLES_TARGET)/Makefile.ioprp
2627
cp -f Makefile.eeglobal_sample $(SAMPLES_TARGET)/Makefile.eeglobal
2728
cp -f Makefile.eeglobal_cpp_sample $(SAMPLES_TARGET)/Makefile.eeglobal_cpp
2829
cp -f Makefile.iopglobal_sample $(SAMPLES_TARGET)/Makefile.iopglobal

samples/Makefile.eeglobal_sample

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,3 @@ $(EE_ERL): $(EE_OBJS)
9292
$(EE_LIB): $(EE_OBJS)
9393
$(DIR_GUARD)
9494
$(EE_AR) cru $(EE_LIB) $(EE_OBJS)
95-
96-
$(IOPRP_BIN): $(IOPRP_CONTENTS)
97-
ifeq (_$(IOPRP_CONTENTS)_,__)
98-
$(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty)
99-
else
100-
$(DIR_GUARD)
101-
romimg -c $@ $<
102-
endif
103-

samples/Makefile.ioprp_sample

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# _____ ___ ____ ___ ____
2+
# ____| | ____| | | |____|
3+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4+
#-----------------------------------------------------------------------
5+
# Copyright ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
9+
$(IOPRP_BIN): $(IOPRP_CONTENTS)
10+
ifeq (_$(IOPRP_CONTENTS)_,__)
11+
$(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty)
12+
else
13+
$(DIR_GUARD)
14+
romimg -C $@ $<
15+
endif

tools/romimg/src/main.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string.h>
88
#include <sys/stat.h>
99
#include <unistd.h>
10+
#include <ctype.h>
1011

1112
#include "romimg.h"
1213

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

3536
static void DisplaySyntaxHelp(void)
3637
{
37-
printf(REDBOLD"Syntax error"DEFCOL". Syntax:\n"
38-
"ROMIMG -c <ROM image> <files>\n\tCreate ROM image\n"
38+
printf("Syntax:\n"
39+
"ROMIMG -c <ROM image> <files>\n\tCreate ROM image *\n"
3940
"ROMIMG -l <ROM image>\n\tList files in ROM image\n"
40-
"ROMIMG -a <ROM image> <file(s)>\n\tAdd file(s) to ROM image\n"
41+
"ROMIMG -a <ROM image> <file(s)>\n\tAdd file(s) to ROM image *\n"
4142
"ROMIMG -d <ROM image> <file(s)>\n\tDelete file(s) from ROM image\n"
4243
"ROMIMG -x <ROM image>\n\tExtract all files from ROM image\n"
43-
"ROMIMG -x <ROM image> <file>\n\tExtract file from ROM image\n");
44+
"ROMIMG -x <ROM image> <file>\n\tExtract file from ROM image\n"
45+
"\n note*: write the switch in uppercase to perform filename transformation (eg: 'ioman.irx' > 'IOMAN')\n"
46+
);
4447
}
4548

4649
static void DisplayAddDeleteOperationResult(int result, const char *InvolvedFile)
@@ -80,31 +83,30 @@ int main(int argc, char **argv)
8083

8184
if (argc < 2) {
8285
DisplaySyntaxHelp();
83-
DPRINTF("ERROR: LESS THAN TWO ARGS PROVIDED\n");
8486
return EINVAL;
8587
}
8688

87-
if (argc >= 4 && strcmp(argv[1], "-c") == 0) {
89+
if (argc >= 4 && strcasecmp(argv[1], "-c") == 0) {
8890
if ((result = CreateBlankROMImg(argv[2], &ROMImg)) == 0) {
8991
for (FilesAffected = 0, i = 0; i < argc - 3; i++) {
9092
printf("Adding file '%s'", argv[3 + i]);
91-
if ((result = AddFile(&ROMImg, argv[3 + i])) == 0)
93+
if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0)
9294
FilesAffected++;
9395
printf(result == 0 ? GRNBOLD" done!"DEFCOL"\n" : REDBOLD" failed!"DEFCOL"\n");
9496
}
9597

9698
if (FilesAffected > 0) {
97-
printf("Writing image...");
99+
printf("Writing image... ");
98100
printf("%s", (result = WriteROMImg(argv[2], &ROMImg)) == 0 ? GRNBOLD"done!"DEFCOL"\n" : REDBOLD"failed!"DEFCOL"\n");
99101
}
100102
UnloadROMImg(&ROMImg);
101103
} else
102-
ERROR("(Internal fault) Can't create blank image file: %d. Please report.\n", result);
103-
} else if (argc >= 4 && strcmp(argv[1], "-a") == 0) {
104+
ERROR("(Internal fault) Can't create blank image file: %d (%s). Please report.\n", result, strerror(result));
105+
} else if (argc >= 4 && strcasecmp(argv[1], "-a") == 0) {
104106
if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) {
105107
for (i = 0, FilesAffected = 0; i < argc - 3; i++) {
106108
printf("Adding file '%s'", argv[3 + i]);
107-
if ((result = AddFile(&ROMImg, argv[3 + i])) == 0)
109+
if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0)
108110
FilesAffected++;
109111
DisplayAddDeleteOperationResult(result, argv[3 + i]);
110112
}

tools/romimg/src/platform.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <errno.h>
66
#include <stdlib.h>
7+
#include <ctype.h>
78
#include "dprintf.h"
89
#if defined(_WIN32) || defined(WIN32)
910
#include <windows.h>
@@ -114,3 +115,12 @@ int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize)
114115
return EIO;
115116
#endif
116117
}
118+
119+
void upperbuff(char *temp)
120+
{
121+
char *s = temp;
122+
while (*s) {
123+
*s = toupper((unsigned char) *s);
124+
s++;
125+
}
126+
}

tools/romimg/src/platform.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ int GetLocalhostName(char *buffer, unsigned int BufferSize);
66
unsigned int GetSystemDate(void);
77
unsigned int GetFileCreationDate(const char *path);
88
int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize);
9+
void upperbuff(char *temp);
910

1011
#if defined(_WIN32) || defined(WIN32)
1112
#define PATHSEP '\\'
1213
#else
1314
#define PATHSEP '/'
1415
#endif
1516

16-
#endif /* __PLATFORM_H__ */
17+
#endif /* __PLATFORM_H__ */

tools/romimg/src/romimg.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
#include <stdio.h>
77
#include <stdlib.h>
88
#include <string.h>
9+
#include <unistd.h>
10+
#include <limits.h>
911

1012
#include "platform.h"
1113
#include "romimg.h"
1214
#include "SonyRX.h"
1315

16+
#define IMAGE_COMMENT_BASESIZE 31
17+
1418
struct ROMImgStat
1519
{
1620
void *image;
@@ -139,12 +143,7 @@ static int GetExtInfoStat(const struct ROMImgStat *ImageStat, struct RomDirFileF
139143
int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
140144
{
141145
unsigned int CommentLength;
142-
char LocalhostName[32], cwd[128];
143-
#if defined(_WIN32) || defined(WIN32)
144-
char UserName[32] = "";
145-
#else
146-
char* UserName;
147-
#endif
146+
char LocalhostName[32] = {0}, cwd[PATH_MAX] = {0}, UserName[32] = {0};
148147
struct FileEntry *ResetFile;
149148
struct ExtInfoFieldEntry *ExtInfoEntry;
150149

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

166166
// Create a blank RESET file.
167167
ROMImg->NumFiles = 1;
@@ -452,15 +452,26 @@ static int AddExtInfoStat(struct FileEntry *file, unsigned char type, void *data
452452
return result;
453453
}
454454

455-
int AddFile(ROMIMG *ROMImg, const char *path)
455+
int AddFile(ROMIMG *ROMImg, const char *path, int upperconv)
456456
{
457+
char tbuf[9] = "\0"; // we dont need a large buf, this is for filling in the filename on ROMFS
457458
FILE *InputFile;
458459
int result;
459460
unsigned int FileDateStamp;
460461
unsigned short FileVersion;
461462
if ((InputFile = fopen(path, "rb")) != NULL) {
462463
const char* fname = strrchr(path, PATHSEP);
463464
if (fname == NULL) fname = path; else fname++;
465+
if (upperconv) {
466+
strncpy(tbuf, fname, sizeof(tbuf));
467+
tbuf[sizeof(tbuf) - 1] = '\0';
468+
if (tbuf[0] != '\0') {
469+
upperbuff(tbuf);
470+
fname = tbuf;
471+
char* T = strrchr(fname, '.');
472+
if (T != NULL) *T = '\0'; //null terminate extension
473+
}
474+
}
464475
int size;
465476
fseek(InputFile, 0, SEEK_END);
466477
size = ftell(InputFile);
@@ -476,7 +487,7 @@ int AddFile(ROMIMG *ROMImg, const char *path)
476487
file = &ROMImg->files[ROMImg->NumFiles - 1];
477488
memset(&ROMImg->files[ROMImg->NumFiles - 1], 0, sizeof(struct FileEntry));
478489

479-
strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name) - 1);
490+
strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name));
480491
file->RomDir.name[sizeof(file->RomDir.name) - 1] = '\0';
481492
file->RomDir.ExtInfoEntrySize = 0;
482493

tools/romimg/src/romimg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg);
6868
int WriteROMImg(const char *file, const ROMIMG *ROMImg);
6969
int LoadROMImg(ROMIMG *ROMImg, const char *path);
7070
void UnloadROMImg(ROMIMG *ROMImg);
71-
int AddFile(ROMIMG *ROMImg, const char *path);
71+
int AddFile(ROMIMG *ROMImg, const char *path, int upperconv);
7272
int DeleteFile(ROMIMG *ROMImg, const char *filename);
7373
int ExtractFile(const ROMIMG *ROMImg, const char *filename, const char *FileToExtract);
7474
int IsFileExists(const ROMIMG *ROMImg, const char *filename);
7575

76-
#endif /* __ROMING_H__ */
76+
#endif /* __ROMING_H__ */

0 commit comments

Comments
 (0)