Skip to content

Commit 56a6eb7

Browse files
authored
Merge pull request #645 from fjtrujy/std_tools
Stop using `u8`, `u16` and `u32` in the roming tool
2 parents 4726a79 + fa557a4 commit 56a6eb7

File tree

5 files changed

+78
-59
lines changed

5 files changed

+78
-59
lines changed

tools/romimg/src/ELF.h

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
typedef unsigned char u8;
2-
typedef unsigned short int u16;
3-
typedef unsigned int u32;
1+
#ifndef __ELF_H__
2+
#define __ELF_H__
3+
4+
#include <stdint.h>
45

56
/* ELF-loading stuff */
67
#define ELF_MAGIC 0x464c457f
@@ -11,59 +12,59 @@ typedef unsigned int u32;
1112
/*------------------------------*/
1213
typedef struct
1314
{
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;
15+
uint8_t ident[16]; /* Structure of a ELF header */
16+
uint16_t type;
17+
uint16_t machine;
18+
uint32_t version;
19+
uint32_t entry;
20+
uint32_t phoff;
21+
uint32_t shoff;
22+
uint32_t flags;
23+
uint16_t ehsize;
24+
uint16_t phentsize;
25+
uint16_t phnum;
26+
uint16_t shentsize;
27+
uint16_t shnum;
28+
uint16_t shstrndx;
2829
} elf_header_t;
2930
/*------------------------------*/
3031
typedef struct
3132
{
32-
u32 type; /* Structure of a header a sections in an ELF */
33-
u32 offset;
33+
uint32_t type; /* Structure of a header a sections in an ELF */
34+
uint32_t offset;
3435
void *vaddr;
35-
u32 paddr;
36-
u32 filesz;
37-
u32 memsz;
38-
u32 flags;
39-
u32 align;
36+
uint32_t paddr;
37+
uint32_t filesz;
38+
uint32_t memsz;
39+
uint32_t flags;
40+
uint32_t align;
4041
} elf_pheader_t;
4142

4243
typedef struct
4344
{
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;
45+
uint32_t name;
46+
uint32_t type;
47+
uint32_t flags;
48+
uint32_t addr;
49+
uint32_t offset;
50+
uint32_t size;
51+
uint32_t link;
52+
uint32_t info;
53+
uint32_t addralign;
54+
uint32_t entsize;
5455
} elf_shdr_t;
5556

5657
typedef struct
5758
{
58-
u32 offset;
59-
u32 info;
59+
uint32_t offset;
60+
uint32_t info;
6061
} elf_rel;
6162

6263
typedef struct
6364
{
64-
u32 offset;
65-
u32 info;
66-
u32 addend;
65+
uint32_t offset;
66+
uint32_t info;
67+
uint32_t addend;
6768
} elf_rela;
6869

6970
enum ELF_SHT_types {
@@ -83,29 +84,29 @@ enum ELF_SHT_types {
8384

8485
typedef struct iopmod_struct
8586
{
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;
87+
uint32_t moduleinfo;
88+
uint32_t entry;
89+
uint32_t gp_value;
90+
uint32_t text_size;
91+
uint32_t data_size;
92+
uint32_t bss_size;
93+
uint16_t version;
9394
char modname[];
9495
} iopmod_t;
9596

9697
typedef struct eemod_struct
9798
{
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;
99+
uint32_t moduleinfo;
100+
uint32_t entry;
101+
uint32_t gp_value;
102+
uint32_t text_size;
103+
uint32_t data_size;
104+
uint32_t bss_size;
105+
uint32_t ERX_lib_addr;
106+
uint32_t ERX_lib_size;
107+
uint32_t ERX_stub_addr;
108+
uint32_t ERX_stub_size;
109+
uint16_t version;
109110
char modname[];
110111
} eemod_t;
111112

@@ -120,3 +121,5 @@ typedef struct eemod_struct
120121
#define SHF_ALLOC 0x2
121122
#define SHF_EXECINSTR 0x4
122123
#define SHF_MASKPROC 0xf0000000
124+
125+
#endif /* __ELF_H__ */

tools/romimg/src/SonyRX.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int IsSonyRXModule(const char *path)
2020
result = 0;
2121
if ((file = fopen(path, "rb")) != NULL) {
2222
if (fread(&header, 1, sizeof(elf_header_t), file) != 0) {
23-
if (*(u32 *)header.ident == ELF_MAGIC && (header.type == ELF_TYPE_ERX2 || header.type == ELF_TYPE_IRX)) {
23+
if (*(uint32_t *)header.ident == ELF_MAGIC && (header.type == ELF_TYPE_ERX2 || header.type == ELF_TYPE_IRX)) {
2424
unsigned int i;
2525
for (i = 0; i < header.shnum; i++) {
2626
fseek(file, header.shoff + i * header.shentsize, SEEK_SET);
@@ -50,7 +50,7 @@ int GetSonyRXModInfo(const char *path, char *description, unsigned int MaxLength
5050
result = ENOENT;
5151
if ((file = fopen(path, "rb")) != NULL) {
5252
if (fread(&header, 1, sizeof(elf_header_t), file) != 0) {
53-
if (*(u32 *)header.ident == ELF_MAGIC && (header.type == ELF_TYPE_ERX2 || header.type == ELF_TYPE_IRX)) {
53+
if (*(uint32_t *)header.ident == ELF_MAGIC && (header.type == ELF_TYPE_ERX2 || header.type == ELF_TYPE_IRX)) {
5454
unsigned int i;
5555
for (i = 0; i < header.shnum; i++) {
5656
fseek(file, header.shoff + i * header.shentsize, SEEK_SET);

tools/romimg/src/SonyRX.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
#ifndef __SONY_RX_H__
2+
#define __SONY_RX_H__
3+
14
int IsSonyRXModule(const char *path);
25
int GetSonyRXModInfo(const char *path, char *description, unsigned int MaxLength, unsigned short int *version);
6+
7+
#endif /* __SONY_RX_H__ */

tools/romimg/src/platform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef __PLATFORM_H__
2+
#define __PLATFORM_H__
3+
14
int GetUsername(char *buffer, unsigned int BufferSize);
25
int GetLocalhostName(char *buffer, unsigned int BufferSize);
36
unsigned int GetSystemDate(void);
@@ -9,3 +12,5 @@ int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize);
912
#else
1013
#define PATHSEP '/'
1114
#endif
15+
16+
#endif /* __PLATFORM_H__ */

tools/romimg/src/romimg.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
1717
All sections and files are (must be?) aligned to 16-byte boundaries, and all records within each section must be aligned to 4-byte boundaries.
1818
*/
19+
20+
#ifndef __ROMING_H__
21+
#define __ROMING_H__
22+
1923
#include "dprintf.h"
2024
#if defined(_WIN32) || defined(WIN32)
2125
#define RMIMG_PTRCAST unsigned int
@@ -68,3 +72,5 @@ int AddFile(ROMIMG *ROMImg, const char *path);
6872
int DeleteFile(ROMIMG *ROMImg, const char *filename);
6973
int ExtractFile(const ROMIMG *ROMImg, const char *filename, const char *FileToExtract);
7074
int IsFileExists(const ROMIMG *ROMImg, const char *filename);
75+
76+
#endif /* __ROMING_H__ */

0 commit comments

Comments
 (0)