Skip to content

Commit

Permalink
Merge pull request #27 from samueldr/feature/initrd-support
Browse files Browse the repository at this point in the history
Add basic initrd support
  • Loading branch information
Wolfvak authored Sep 28, 2021
2 parents 4098b02 + af406f4 commit d07e6ad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arm9/include/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const char* GetWorkDir();
/** Checks if there is enough space free on the SD card **/
bool DebugCheckFreeSpace(size_t required);

/** Checks path exists */
bool FileExists(const char* path);

/** Opens existing files */
bool FileOpen(const char* path);
bool DebugFileOpen(const char* path);
Expand Down
8 changes: 8 additions & 0 deletions arm9/source/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ bool DebugCheckFreeSpace(size_t required)
return true;
}

bool FileExists(const char* path)
{
FILINFO fno;

return f_stat(path, &fno) == FR_OK;
}


bool FileOpen(const char* path)
{
unsigned flags = FA_READ | FA_WRITE | FA_OPEN_EXISTING;
Expand Down
10 changes: 10 additions & 0 deletions arm9/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ int main(int argc, char *argv[])
goto error;
}

if (FileExists(INITRAMFS_FILENAME)) {
if (!load_file(INITRAMFS_FILENAME, INITRAMFS_ADDR)) {
Debug("Failed to load " INITRAMFS_FILENAME);
goto error;
}
}
else {
Debug("Note: initramfs file not present (" INITRAMFS_FILENAME ")");
}

dtb_filename = is_lgr() ? KTR_DTB_FILENAME : CTR_DTB_FILENAME;
if (!load_file(dtb_filename, DTB_ADDR)) {
Debug("Failed to load %s", dtb_filename);
Expand Down
2 changes: 2 additions & 0 deletions common/linux_config.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* Linux settings */
#define DTB_ADDR (0x20000000)
#define ZIMAGE_ADDR (0x20008000)
#define INITRAMFS_ADDR (0x27800000)
#define MACHINE_NUMBER (0xFFFFFFFF)
#define ARM9LINUXFW_ADDR (0x08080000)
#define SYNC_ADDR (0x1FFFFFF0)

#define LINUXIMAGE_FILENAME "linux/zImage"
#define INITRAMFS_FILENAME "linux/initramfs.cpio.gz"
#define CTR_DTB_FILENAME "linux/nintendo3ds_ctr.dtb"
#define KTR_DTB_FILENAME "linux/nintendo3ds_ktr.dtb"
#define ARM9LINUXFW_FILENAME "linux/arm9linuxfw.bin"
Expand Down

0 comments on commit d07e6ad

Please sign in to comment.