Skip to content

Commit 08181ea

Browse files
authored
Merge pull request #510 from israpps/ioprp
add romimg to tools & recipe for IOPRP Images
2 parents f5db5e0 + 59af0e9 commit 08181ea

File tree

12 files changed

+1219
-0
lines changed

12 files changed

+1219
-0
lines changed

samples/Makefile.eeglobal_sample

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,12 @@ $(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+

tools/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SUBDIRS = \
1111
bin2c \
1212
ps2-irxgen \
1313
ps2adpcm \
14+
romimg \
1415
# gensymtab
1516

1617
include $(PS2SDKSRC)/Defs.make

tools/romimg/Makefile

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 2001-2022, ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
# ROMIMG was made by @sp193
9+
10+
TOOLS_OBJS = main.o platform.o romimg.o SonyRX.o
11+
12+
include $(PS2SDKSRC)/Defs.make
13+
include $(PS2SDKSRC)/tools/Rules.bin.make
14+
include $(PS2SDKSRC)/tools/Rules.make
15+
include $(PS2SDKSRC)/tools/Rules.release

tools/romimg/src/ELF.h

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
typedef unsigned char u8;
2+
typedef unsigned short int u16;
3+
typedef unsigned int u32;
4+
5+
/* ELF-loading stuff */
6+
#define ELF_MAGIC 0x464c457f
7+
#define ELF_TYPE_IRX 0xFF80 /* SCE IOP Relocatable eXcutable file version 1.0 */
8+
#define ELF_TYPE_ERX2 0xFF91 /* SCE EE Relocatable eXcutable file version 2.0 */
9+
#define ELF_PT_LOAD 1
10+
11+
/*------------------------------*/
12+
typedef struct
13+
{
14+
u8 ident[16]; /* Structure of a ELF header */
15+
u16 type;
16+
u16 machine;
17+
u32 version;
18+
u32 entry;
19+
u32 phoff;
20+
u32 shoff;
21+
u32 flags;
22+
u16 ehsize;
23+
u16 phentsize;
24+
u16 phnum;
25+
u16 shentsize;
26+
u16 shnum;
27+
u16 shstrndx;
28+
} elf_header_t;
29+
/*------------------------------*/
30+
typedef struct
31+
{
32+
u32 type; /* Structure of a header a sections in an ELF */
33+
u32 offset;
34+
void *vaddr;
35+
u32 paddr;
36+
u32 filesz;
37+
u32 memsz;
38+
u32 flags;
39+
u32 align;
40+
} elf_pheader_t;
41+
42+
typedef struct
43+
{
44+
u32 name;
45+
u32 type;
46+
u32 flags;
47+
u32 addr;
48+
u32 offset;
49+
u32 size;
50+
u32 link;
51+
u32 info;
52+
u32 addralign;
53+
u32 entsize;
54+
} elf_shdr_t;
55+
56+
typedef struct
57+
{
58+
u32 offset;
59+
u32 info;
60+
} elf_rel;
61+
62+
typedef struct
63+
{
64+
u32 offset;
65+
u32 info;
66+
u32 addend;
67+
} elf_rela;
68+
69+
enum ELF_SHT_types {
70+
SHT_NULL = 0,
71+
SHT_PROGBITS,
72+
SHT_SYMTAB,
73+
SHT_STRTAB,
74+
SHT_RELA,
75+
SHT_HASH,
76+
SHT_DYNAMIC,
77+
SHT_NOTE,
78+
SHT_NOBITS,
79+
SHT_REL,
80+
SHT_SHLIB,
81+
SHT_DYNSYM
82+
};
83+
84+
typedef struct iopmod_struct
85+
{
86+
u32 moduleinfo;
87+
u32 entry;
88+
u32 gp_value;
89+
u32 text_size;
90+
u32 data_size;
91+
u32 bss_size;
92+
u16 version;
93+
char modname[];
94+
} iopmod_t;
95+
96+
typedef struct eemod_struct
97+
{
98+
u32 moduleinfo;
99+
u32 entry;
100+
u32 gp_value;
101+
u32 text_size;
102+
u32 data_size;
103+
u32 bss_size;
104+
u32 ERX_lib_addr;
105+
u32 ERX_lib_size;
106+
u32 ERX_stub_addr;
107+
u32 ERX_stub_size;
108+
u16 version;
109+
char modname[];
110+
} eemod_t;
111+
112+
#define SHT_LOPROC 0x70000000
113+
#define SHT_LOPROC_IOPMOD_TAB 0x80
114+
#define SHT_LOPROC_EEMOD_TAB 0x90
115+
#define SHT_HIPROC 0x7fffffff
116+
#define SHT_LOUSER 0x80000000
117+
#define SHT_HIUSER 0xffffffff
118+
119+
#define SHF_WRITE 0x1
120+
#define SHF_ALLOC 0x2
121+
#define SHF_EXECINSTR 0x4
122+
#define SHF_MASKPROC 0xf0000000

tools/romimg/src/SonyRX.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
SonyRX.c - Contains functions for handling Sony Relocatable eXecutable files (e.g. IRX and ERX files).
3+
*/
4+
5+
#include <errno.h>
6+
#include <stdio.h>
7+
#include <malloc.h>
8+
#include <string.h>
9+
10+
#include "ELF.h"
11+
#include "SonyRX.h"
12+
13+
int IsSonyRXModule(const char *path)
14+
{
15+
FILE *file;
16+
elf_header_t header;
17+
elf_shdr_t SectionHeader;
18+
int result;
19+
20+
result = 0;
21+
if ((file = fopen(path, "rb")) != NULL) {
22+
fread(&header, 1, sizeof(elf_header_t), file);
23+
if (*(u32 *)header.ident == ELF_MAGIC && (header.type == ELF_TYPE_ERX2 || header.type == ELF_TYPE_IRX)) {
24+
unsigned int i;
25+
for (i = 0; i < header.shnum; i++) {
26+
fseek(file, header.shoff + i * header.shentsize, SEEK_SET);
27+
fread(&SectionHeader, 1, sizeof(elf_shdr_t), file);
28+
29+
if ((SectionHeader.type == (SHT_LOPROC | SHT_LOPROC_EEMOD_TAB)) || (SectionHeader.type == (SHT_LOPROC | SHT_LOPROC_IOPMOD_TAB))) {
30+
result = 1;
31+
break;
32+
}
33+
}
34+
}
35+
36+
fclose(file);
37+
}
38+
39+
return result;
40+
}
41+
42+
int GetSonyRXModInfo(const char *path, char *description, unsigned int MaxLength, unsigned short int *version)
43+
{
44+
FILE *file;
45+
int result;
46+
elf_header_t header;
47+
elf_shdr_t SectionHeader;
48+
49+
result = ENOENT;
50+
if ((file = fopen(path, "rb")) != NULL) {
51+
fread(&header, 1, sizeof(elf_header_t), file);
52+
if (*(u32 *)header.ident == ELF_MAGIC && (header.type == ELF_TYPE_ERX2 || header.type == ELF_TYPE_IRX)) {
53+
unsigned int i;
54+
for (i = 0; i < header.shnum; i++) {
55+
fseek(file, header.shoff + i * header.shentsize, SEEK_SET);
56+
fread(&SectionHeader, 1, sizeof(elf_shdr_t), file);
57+
58+
if (SectionHeader.type == (SHT_LOPROC | SHT_LOPROC_EEMOD_TAB) || SectionHeader.type == (SHT_LOPROC | SHT_LOPROC_IOPMOD_TAB)) {
59+
void *buffer;
60+
if ((buffer = malloc(SectionHeader.size)) != NULL) {
61+
fseek(file, SectionHeader.offset, SEEK_SET);
62+
fread(buffer, 1, SectionHeader.size, file);
63+
64+
if (SectionHeader.type == (SHT_LOPROC | SHT_LOPROC_IOPMOD_TAB)) {
65+
*version = ((iopmod_t *)buffer)->version;
66+
strncpy(description, ((iopmod_t *)buffer)->modname, MaxLength - 1);
67+
description[MaxLength - 1] = '\0';
68+
} else if (SectionHeader.type == (SHT_LOPROC | SHT_LOPROC_EEMOD_TAB)) {
69+
*version = ((eemod_t *)buffer)->version;
70+
strncpy(description, ((eemod_t *)buffer)->modname, MaxLength - 1);
71+
description[MaxLength - 1] = '\0';
72+
}
73+
74+
result = 0;
75+
76+
free(buffer);
77+
} else
78+
result = ENOMEM;
79+
break;
80+
}
81+
}
82+
} else
83+
result = EINVAL;
84+
85+
fclose(file);
86+
} else
87+
result = ENOENT;
88+
89+
return result;
90+
}

tools/romimg/src/SonyRX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int IsSonyRXModule(const char *path);
2+
int GetSonyRXModInfo(const char *path, char *description, unsigned int MaxLength, unsigned short int *version);

tools/romimg/src/dprintf.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#define REDBOLD "\033[1;31m"
2+
#define YELBOLD "\033[1;33m"
3+
#define GRNBOLD "\033[1;32m"
4+
5+
#define GREEN "\033[0;32m"
6+
#define YELLOW "\033[0;33m"
7+
#define DEFCOL "\033[0m"
8+
#include <stdio.h>
9+
#define ERROR(fmt, x...) printf(REDBOLD "ERROR: " fmt DEFCOL, ##x)
10+
#define WARNING(fmt, x...) printf(YELBOLD "WARNING: " fmt DEFCOL, ##x)
11+
// #define DEBUG
12+
#ifdef DEBUG
13+
#define DPRINTF(fmt, x...) printf(REDBOLD "%s: " fmt DEFCOL, __func__, ##x)
14+
#define PRINTLN() DPRINTF("%d\n", __LINE__)
15+
#else
16+
#define DPRINTF(x...)
17+
#define PRINTLN()
18+
#endif

0 commit comments

Comments
 (0)