Skip to content

Commit

Permalink
more aram cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor403 committed Jan 9, 2025
1 parent 0c4e864 commit d09055e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cubeboot/source/boot/sidestep.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "sidestep.h"
#include "ssaram.h"

#define ARAMSTART 0
#define ARAMSTART 0x8000
#define ARAMSIZE (10 * 1024 * 1024)

/*** A global or two ***/
Expand Down
3 changes: 0 additions & 3 deletions cubeboot/source/boot/ssaram.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

static u8 aramfix[2048] ATTRIBUTE_ALIGN(32);

#define ARAMSTART 0x8000
#define ARAM_READ 1
#define ARAM_WRITE 0

Expand Down Expand Up @@ -103,7 +102,6 @@ void ARAMClear(u32 start, u32 length)
for (i = start; i < 0x1000000 - length; i += 2048)
{
ARAMPut(buffer, (char *) i, 2048);
while (AR_GetDMAStatus());
}

free(buffer);
Expand Down Expand Up @@ -156,7 +154,6 @@ void ARAMPut(unsigned char *src, char *dst, int len)
memcpy(aramfix, src + offset, 2048);
DCFlushRange(aramfix, 2048);
__ARWriteDMA((u32) aramfix, (u32) dst + offset, 2048);
while (AR_GetDMAStatus());
offset += 2048;
}

Expand Down
62 changes: 62 additions & 0 deletions cubeboot/source/sram.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <stdbool.h>
#include <ogc/system.h>

#include "flippy_sync.h"

extern syssram* __SYS_LockSram(void);
extern syssramex* __SYS_LockSramEx(void);
extern u32 __SYS_UnlockSram(u32 write);
extern u32 __SYS_UnlockSramEx(u32 write);
extern u32 __SYS_SyncSram(void);

#define DEVICE_ID_J 0x13 // FlippyDrive
#define DEVICE_ID_K 0x14 // FlippyDrive Flash

void set_sram_swiss(bool syncSram) {
bool writeSram = false;
syssramex *sramex = __SYS_LockSramEx();

if (sramex->__padding0 != 0) {
sramex->__padding0 = DEVICE_ID_J;
writeSram = true;
}

__SYS_UnlockSramEx(writeSram);
while (syncSram && !__SYS_SyncSram());
}

#define SWISS_GLOBAL_CONFIG_PATH "/swiss/settings/global.ini"

void create_swiss_config() {
// mkdir all
dvd_custom_mkdir("/swiss");
dvd_custom_mkdir("/swiss/settings");

// check swiss global config
dvd_custom_open(SWISS_GLOBAL_CONFIG_PATH, FILE_TYPE_FLAG_FILE, IPC_FILE_FLAG_DISABLESPEEDEMU);

GCN_ALIGNED(file_status_t) status;
int ret = dvd_custom_status(&status);
if (ret != 0) return;

// file exists
if(status.result == 0 && status.fd != 0) {
dvd_custom_close(status.fd);
return;
}

// create swiss global config
ret = dvd_custom_open(SWISS_GLOBAL_CONFIG_PATH, FILE_TYPE_FLAG_FILE, IPC_FILE_FLAG_DISABLESPEEDEMU | IPC_FILE_FLAG_WRITE);
if (ret != 0) return;

// TODO: what do we put in this file?
// I have checked and it can safely generate defaults from an empty file

// file created!
if(status.result == 0 && status.fd != 0) {
dvd_custom_close(status.fd);
return;
}

return;
}
5 changes: 5 additions & 0 deletions cubeboot/source/sram.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdbool.h>
#include <ogc/system.h>

void set_sram_swiss(bool syncSram);
void create_swiss_config();
25 changes: 25 additions & 0 deletions cubeboot/source/tinf_crc32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
static const unsigned int tinf_crc32tab[16] = {
0x00000000, 0x1DB71064, 0x3B6E20C8, 0x26D930AC, 0x76DC4190,
0x6B6B51F4, 0x4DB26158, 0x5005713C, 0xEDB88320, 0xF00F9344,
0xD6D6A3E8, 0xCB61B38C, 0x9B64C2B0, 0x86D3D2D4, 0xA00AE278,
0xBDBDF21C
};

unsigned int tinf_crc32(const void *data, unsigned int length)
{
const unsigned char *buf = (const unsigned char *) data;
unsigned int crc = 0xFFFFFFFF;
unsigned int i;

if (length == 0) {
return 0;
}

for (i = 0; i < length; ++i) {
crc ^= buf[i];
crc = tinf_crc32tab[crc & 0x0F] ^ (crc >> 4);
crc = tinf_crc32tab[crc & 0x0F] ^ (crc >> 4);
}

return crc ^ 0xFFFFFFFF;
}
1 change: 1 addition & 0 deletions cubeboot/source/tinf_crc32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unsigned int tinf_crc32(const void *data, unsigned int length);

0 comments on commit d09055e

Please sign in to comment.