Skip to content

Commit 389b2bb

Browse files
committed
add: Add ioprpgen library
1 parent 9904d0c commit 389b2bb

8 files changed

Lines changed: 402 additions & 5 deletions

File tree

ee/Makefile

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,35 @@
66
# Licenced under Academic Free License version 2.0
77
# Review ps2sdk README & LICENSE files for further details.
88

9-
SUBDIRS = startup erl kernel libcglue libpthreadglue libprofglue rpc debug \
10-
eedebug sbv dma graph math3d \
11-
packet packet2 draw libgs \
12-
libvux font input inputx network iopreboot \
9+
SUBDIRS = \
10+
startup \
11+
erl \
12+
kernel \
13+
libcglue \
14+
libpthreadglue \
15+
libprofglue \
16+
rpc \
17+
debug \
18+
eedebug \
19+
sbv \
20+
dma \
21+
graph \
22+
math3d \
23+
packet \
24+
packet2 \
25+
draw \
26+
libgs \
27+
libvux \
28+
font \
29+
input \
30+
inputx \
31+
network \
32+
iopreboot \
33+
ioprpgen \
1334
mpeg \
14-
elf-loader elf-loader-nocolour elf-loader2 \
35+
elf-loader \
36+
elf-loader-nocolour \
37+
elf-loader2
1538

1639
include $(PS2SDKSRC)/Defs.make
1740
include $(PS2SDKSRC)/Rules.make

ee/ioprpgen/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
EE_OBJS = ioprpgen.o
10+
11+
include $(PS2SDKSRC)/Defs.make
12+
include $(PS2SDKSRC)/ee/Rules.lib.make
13+
include $(PS2SDKSRC)/ee/Rules.make
14+
include $(PS2SDKSRC)/ee/Rules.release

ee/ioprpgen/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# IOPRP image generator
2+
3+
This library generates IOPRP images at runtime for usage with iopreboot.
4+
5+
## Usage
6+
7+
See "ioprpgen" sample for usage example.

ee/ioprpgen/include/ioprpgen.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
# _____ ___ ____ ___ ____
3+
# ____| | ____| | | |____|
4+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5+
#-----------------------------------------------------------------------
6+
# Copyright ps2dev - http://www.ps2dev.org
7+
# Licenced under Academic Free License version 2.0
8+
# Review ps2sdk README & LICENSE files for further details.
9+
*/
10+
11+
/**
12+
* @file
13+
* Definitions for IOPRP generation library.
14+
*/
15+
16+
#ifndef __IOPRPGEN__
17+
#define __IOPRPGEN__
18+
19+
#include <tamtypes.h>
20+
21+
struct ioprpgen_ctx;
22+
23+
typedef int (*ioprpgen_write_cb_t)(void *userdata, const struct ioprpgen_ctx *ctx, const void *buf, u32 size);
24+
25+
struct ioprpgen_ctx
26+
{
27+
ioprpgen_write_cb_t m_write_cb;
28+
void *m_write_cb_userdata;
29+
};
30+
31+
struct ioprpgen_memwrite_ctx
32+
{
33+
void *m_write_ptr;
34+
u32 m_write_ptr_size;
35+
u32 m_write_ptr_curpos;
36+
};
37+
38+
struct ioprpgen_entry
39+
{
40+
const char *m_name;
41+
const void *m_data;
42+
u32 m_data_size;
43+
};
44+
45+
/** Setup ioprpgen context
46+
*
47+
* @param ctx Pointer to context
48+
* @param memwrite_ctx Pointer to memwrite context (ensure it has the same lifetime as ctx)
49+
* @param buf Output buffer
50+
* @param size Size of the output buffer
51+
* @return 1 on success, 0 on failure.
52+
*/
53+
extern void ioprpgen_setup_membuf(struct ioprpgen_ctx *ctx, struct ioprpgen_memwrite_ctx *memwrite_ctx, void *buf, u32 size);
54+
/** Generate IOPRP image using provided entries
55+
*
56+
* @param ctx Pointer to context prepared by ioprpgen_setup_membuf
57+
* @param entries Pointer to NULL-terminated list of entries
58+
* @return 0 on failure, other value for size
59+
*/
60+
extern u32 ioprpgen_write_ioprp(const struct ioprpgen_ctx *ctx, const struct ioprpgen_entry *entries);
61+
62+
#endif /* __IOPRPGEN__ */

ee/ioprpgen/samples/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
SAMPLE_DIR = ioprpgen
10+
11+
include $(PS2SDKSRC)/Defs.make
12+
include $(PS2SDKSRC)/samples/Rules.samples
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
EE_BIN = ioprpgen_sample.elf
10+
EE_OBJS = ioprpgen_sample.o sifinit_irx.o threadman_irx.o igreeting_irx.o
11+
EE_LIBS = -lioprpgen -liopreboot -lc -lpatches -ldebug
12+
13+
all: $(EE_BIN)
14+
$(EE_STRIP) --strip-all $(EE_BIN)
15+
16+
clean:
17+
rm -f $(EE_BIN) $(EE_OBJS) *_irx.c
18+
19+
%_irx.c: $(PS2SDK)/iop/irx/%.irx
20+
bin2c $< $@ $(basename $(notdir $@))
21+
22+
run: $(EE_BIN)
23+
ps2client execee host:$(EE_BIN)
24+
25+
reset:
26+
ps2client reset
27+
28+
include $(PS2SDK)/samples/Makefile.pref
29+
include $(PS2SDK)/samples/Makefile.eeglobal
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
# _____ ___ ____ ___ ____
3+
# ____| | ____| | | |____|
4+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5+
#-----------------------------------------------------------------------
6+
# Copyright ps2dev - http://www.ps2dev.org
7+
# Licenced under Academic Free License version 2.0
8+
# Review ps2sdk README & LICENSE files for further details.
9+
*/
10+
11+
#include <debug.h>
12+
#include <iopcontrol.h>
13+
#include <iopcontrol_special.h>
14+
#include <ioprpgen.h>
15+
#include <kernel.h>
16+
#include <malloc.h>
17+
#include <sifrpc.h>
18+
#include <stdio.h>
19+
#include <stdlib.h>
20+
#include <string.h>
21+
22+
extern unsigned char igreeting_irx[];
23+
extern unsigned int size_igreeting_irx;
24+
25+
extern unsigned char threadman_irx[];
26+
extern unsigned int size_threadman_irx;
27+
28+
extern unsigned char sifinit_irx[];
29+
extern unsigned int size_sifinit_irx;
30+
31+
int main(int ac, char **av)
32+
{
33+
struct ioprpgen_ctx ctx;
34+
struct ioprpgen_memwrite_ctx memwrite_ctx;
35+
struct ioprpgen_entry entries[3];
36+
int sz;
37+
int sz2;
38+
void *buf;
39+
40+
(void)ac;
41+
(void)av;
42+
43+
init_scr();
44+
scr_printf("Preparing IOPRP image\n");
45+
memset(&entries, 0, sizeof(entries));
46+
entries[0].m_name = "IGREETING";
47+
entries[0].m_data = igreeting_irx;
48+
entries[0].m_data_size = size_igreeting_irx;
49+
entries[1].m_name = "SIFINIT";
50+
entries[1].m_data = sifinit_irx;
51+
entries[1].m_data_size = size_sifinit_irx;
52+
// Ensure the end is NULL terminated
53+
entries[2].m_name = NULL;
54+
entries[2].m_data = NULL;
55+
entries[2].m_data_size = 0;
56+
ioprpgen_setup_membuf(&ctx, &memwrite_ctx, NULL, 0);
57+
sz = ioprpgen_write_ioprp(&ctx, entries);
58+
if ( !sz )
59+
{
60+
scr_printf("Error getting size of IOPRP image\n");
61+
SleepThread();
62+
return 0;
63+
}
64+
buf = memalign(64, sz);
65+
if ( !buf )
66+
{
67+
scr_printf("Error allocating memory for IOPRP image\n");
68+
SleepThread();
69+
return 0;
70+
}
71+
ioprpgen_setup_membuf(&ctx, &memwrite_ctx, buf, sz);
72+
sz2 = ioprpgen_write_ioprp(&ctx, entries);
73+
if ( sz != sz2 )
74+
{
75+
scr_printf("Error generating IOPRP image\n");
76+
SleepThread();
77+
return 0;
78+
}
79+
sceSifInitRpc(0);
80+
SifIopRebootBuffer(buf, sz);
81+
while ( !SifIopSync() )
82+
;
83+
free(buf);
84+
sceSifInitRpc(0);
85+
scr_printf("Successfully rebooted IOP with IOPRP image!\n");
86+
SleepThread();
87+
return 0;
88+
}

0 commit comments

Comments
 (0)