Skip to content
This repository was archived by the owner on Mar 31, 2021. It is now read-only.

Commit 177f6d8

Browse files
committed
First commit
0 parents  commit 177f6d8

File tree

35 files changed

+14002
-0
lines changed

35 files changed

+14002
-0
lines changed

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
ifeq ($(strip $(DEVKITARM)),)
2+
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
3+
endif
4+
5+
include $(DEVKITARM)/base_tools
6+
7+
TARGET = firm_linux_loader
8+
ARM9_SOURCES = source_arm9 source_arm9/fatfs
9+
ARM9_INCLUDES = include_arm9 include_arm9/fatfs
10+
ARM11_SOURCES = source_arm11
11+
ARM11_INCLUDES = include_arm11
12+
13+
ARM9_SFILES = $(foreach dir, $(ARM9_SOURCES), $(wildcard $(dir)/*.s))
14+
ARM9_CFILES = $(foreach dir, $(ARM9_SOURCES), $(wildcard $(dir)/*.c))
15+
ARM11_SFILES = $(foreach dir, $(ARM11_SOURCES), $(wildcard $(dir)/*.s))
16+
ARM11_CFILES = $(foreach dir, $(ARM11_SOURCES), $(wildcard $(dir)/*.c))
17+
18+
ARM9_OBJS = $(ARM9_SFILES:.s=.arm9.o) $(ARM9_CFILES:.c=.arm9.o)
19+
ARM9_INCLUDE = $(foreach dir, $(ARM9_INCLUDES), -I$(CURDIR)/$(dir)) -Iinclude_common
20+
ARM11_OBJS = $(ARM11_SFILES:.s=.arm11.o) $(ARM11_CFILES:.c=.arm11.o)
21+
ARM11_INCLUDE = $(foreach dir, $(ARM11_INCLUDES), -I$(CURDIR)/$(dir)) -Iinclude_common
22+
23+
COMMON_ARCH = -mlittle-endian -mthumb-interwork
24+
ARM9_ARCH = -mcpu=arm946e-s -march=armv5te
25+
ARM11_ARCH = -mcpu=mpcore -march=armv6k
26+
27+
ARM9_ASFLAGS = $(ARM9_ARCH) $(COMMON_ARCH) $(ARM9_INCLUDE) -x assembler-with-cpp
28+
ARM11_ASFLAGS = $(ARM11_ARCH) $(COMMON_ARCH) $(ARM11_INCLUDE) -x assembler-with-cpp
29+
30+
ARM9_CFLAGS = -Wall -O0 -fno-builtin -nostartfiles $(ARM9_ARCH) $(ARM9_INCLUDE)
31+
ARM11_CFLAGS = -Wall -O0 -fno-builtin -nostartfiles $(ARM11_ARCH) $(ARM11_INCLUDE)
32+
33+
.PHONY: all clean copy
34+
35+
all: $(TARGET).firm
36+
37+
$(TARGET).firm: $(TARGET).arm9.elf $(TARGET).arm11.elf
38+
firmtool build $@ \
39+
-n 0x08006800 -e 0x1FF80000 \
40+
-D $(TARGET).arm9.elf $(TARGET).arm11.elf \
41+
-A 0x08006800 0x1FF80000 \
42+
-C NDMA XDMA -i
43+
44+
$(TARGET).arm9.elf: $(ARM9_OBJS)
45+
$(CC) -T link_arm9.ld $^ -o $@
46+
47+
$(TARGET).arm11.elf: $(ARM11_OBJS)
48+
$(CC) -T link_arm11.ld $^ -o $@
49+
50+
%.arm9.o: %.c
51+
$(CC) $(ARM9_CFLAGS) -c $< -o $@
52+
%.arm9.o: %.s
53+
$(CC) $(ARM9_ASFLAGS) -c $< -o $@
54+
55+
%.arm11.o: %.c
56+
$(CC) $(ARM11_CFLAGS) -c $< -o $@
57+
%.arm11.o: %.s
58+
$(CC) $(ARM11_ASFLAGS) -c $< -o $@
59+
60+
clean:
61+
@rm -f $(ARM9_OBJS) $(ARM11_OBJS) $(TARGET).arm9.elf $(TARGET).arm11.elf $(TARGET).firm
62+
63+
copy: $(TARGET).firm
64+
cp $< $(SD3DS)/luma/payloads/down_$(TARGET).firm && sync

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# FIRM Linux Loader
2+
_FIRM Linux Loader for the Nintendo 3DS_
3+
4+
## How to run this
5+
6+
You need the Linux image in order to make use of this.
7+
8+
More info at: [GBAtemp: [Release] Linux for the 3DS](https://gbatemp.net/threads/release-linux-for-the-3ds.407187/)
9+
10+
## Working folders
11+
12+
This Linux loader will first try to load the necessary Linux files from the root of the SD card, if it can't find them there, it will try to load them from inside a /linux folder placed at the root of the SD.
13+
14+
## License
15+
You may use this under the terms of the GNU General Public License GPL v2 or under the terms of any later revisions of the GPL. Refer to the provided `LICENSE.txt` file for further information.
16+
17+
## Credits
18+
* Everybody credited at [Decrypt9WIP](https://github.com/d0k3/Decrypt9WIP)

include_arm9/cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
void flushCaches(void);

include_arm9/common.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
3+
#include <inttypes.h>
4+
#include <stddef.h>
5+
#include <stdbool.h>
6+
#include <string.h>
7+
#include <ctype.h>
8+
#include <stdlib.h>
9+
#include <stdio.h>
10+
11+
#define u8 uint8_t
12+
#define u16 uint16_t
13+
#define u32 uint32_t
14+
#define u64 uint64_t
15+
16+
#define vu8 volatile u8
17+
#define vu16 volatile u16
18+
#define vu32 volatile u32
19+
#define vu64 volatile u64
20+
21+
#define max(a,b) \
22+
(((a) > (b)) ? (a) : (b))
23+
#define min(a,b) \
24+
(((a) < (b)) ? (a) : (b))
25+
#define getbe16(d) \
26+
(((d)[0]<<8) | (d)[1])
27+
#define getbe32(d) \
28+
((((u32) getbe16(d))<<16) | ((u32) getbe16(d+2)))
29+
#define getbe64(d) \
30+
((((u64) getbe32(d))<<32) | ((u64) getbe32(d+4)))
31+
#define getle16(d) (*((u16*) (d)))
32+
#define getle32(d) (*((u32*) (d)))
33+
#define getle64(d) (*((u64*) (d)))
34+
#define align(v,a) \
35+
(((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v))
36+
37+
// standard work area, size must be a multiple of 0x200 (512)
38+
#define BUFFER_ADDRESS ((u8*) 0x21000000)
39+
#define BUFFER_MAX_SIZE ((u32) (1 * 1024 * 1024))
40+
41+
// log file name
42+
#define LOG_FILE "firm_linux_loader.log"
43+
44+
static inline u32 strchrcount(const char* str, char symbol) {
45+
u32 count = 0;
46+
for (u32 i = 0; str[i] != '\0'; i++) {
47+
if (str[i] == symbol)
48+
count++;
49+
}
50+
return count;
51+
}

include_arm9/draw.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2013 Normmatt
2+
// Licensed under GPLv2 or any later version
3+
// Refer to the license.txt file included.
4+
5+
#pragma once
6+
7+
#include "common.h"
8+
9+
#define BYTES_PER_PIXEL 3
10+
#define SCREEN_HEIGHT 240
11+
#define SCREEN_WIDTH_TOP 400
12+
#define SCREEN_WIDTH_BOT 320
13+
14+
#define RGB(r,g,b) (r<<24|b<<16|g<<8|r)
15+
16+
#define COLOR_BLACK RGB(0x00, 0x00, 0x00)
17+
#define COLOR_WHITE RGB(0xFF, 0xFF, 0xFF)
18+
#define COLOR_RED RGB(0xFF, 0x00, 0x00)
19+
#define COLOR_GREEN RGB(0x00, 0xFF, 0x00)
20+
#define COLOR_BLUE RGB(0x00, 0x00, 0xFF)
21+
#define COLOR_CYAN RGB(0x00, 0xFF, 0xFF)
22+
#define COLOR_MAGENTA RGB(0xFF, 0x00, 0xFF)
23+
#define COLOR_YELLOW RGB(0xFF, 0xFF, 0x00)
24+
#define COLOR_GREY RGB(0x77, 0x77, 0x77)
25+
#define COLOR_TRANSPARENT RGB(0xFF, 0x00, 0xEF) // otherwise known as 'super fuchsia'
26+
27+
#define STD_COLOR_BG COLOR_BLACK
28+
#define STD_COLOR_FONT COLOR_WHITE
29+
30+
#define DBG_COLOR_BG COLOR_BLACK
31+
#define DBG_COLOR_FONT COLOR_WHITE
32+
33+
#define DBG_START_Y 10
34+
#define DBG_END_Y (SCREEN_HEIGHT - 10)
35+
#define DBG_START_X 10
36+
#define DBG_END_X (SCREEN_WIDTH_TOP - 10)
37+
#define DBG_STEP_Y 10
38+
39+
#define DBG_N_CHARS_Y ((DBG_END_Y - DBG_START_Y) / DBG_STEP_Y)
40+
#define DBG_N_CHARS_X (((DBG_END_X - DBG_START_X) / 8) + 1)
41+
42+
#define TOP_SCREEN0 (u8*)(*(u32*)0x23FFFE00)
43+
#define TOP_SCREEN1 (u8*)(*(u32*)0x23FFFE00)
44+
#define BOT_SCREEN0 (u8*)(*(u32*)0x23FFFE08)
45+
#define BOT_SCREEN1 (u8*)(*(u32*)0x23FFFE08)
46+
47+
48+
void ClearScreen(unsigned char *screen, int width, int color);
49+
void ClearScreenFull(bool clear_top, bool clear_bottom);
50+
51+
void DrawCharacter(unsigned char *screen, int character, int x, int y, int color, int bgcolor);
52+
void DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor);
53+
void DrawStringF(int x, int y, bool use_top, const char *format, ...);
54+
55+
void Screenshot(const char* path);
56+
void DebugClear();
57+
void DebugSet(const char **strs);
58+
void DebugColor(u32 color, const char *format, ...);
59+
void Debug(const char *format, ...);
60+
61+
void ShowProgress(u64 current, u64 total);

include_arm9/fatfs/diskio.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*-----------------------------------------------------------------------/
2+
/ Low level disk interface modlue include file (C)ChaN, 2014 /
3+
/-----------------------------------------------------------------------*/
4+
5+
#ifndef _DISKIO_DEFINED
6+
#define _DISKIO_DEFINED
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#define _USE_WRITE 1 /* 1: Enable disk_write function */
13+
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
14+
15+
#include "integer.h"
16+
17+
18+
/* Status of Disk Functions */
19+
typedef BYTE DSTATUS;
20+
21+
/* Results of Disk Functions */
22+
typedef enum {
23+
RES_OK = 0, /* 0: Successful */
24+
RES_ERROR, /* 1: R/W Error */
25+
RES_WRPRT, /* 2: Write Protected */
26+
RES_NOTRDY, /* 3: Not Ready */
27+
RES_PARERR /* 4: Invalid Parameter */
28+
} DRESULT;
29+
30+
31+
/*---------------------------------------*/
32+
/* Prototypes for disk control functions */
33+
34+
35+
DSTATUS disk_initialize (BYTE pdrv);
36+
DSTATUS disk_status (BYTE pdrv);
37+
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
38+
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
39+
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
40+
41+
42+
/* Disk Status Bits (DSTATUS) */
43+
44+
#define STA_NOINIT 0x01 /* Drive not initialized */
45+
#define STA_NODISK 0x02 /* No medium in the drive */
46+
#define STA_PROTECT 0x04 /* Write protected */
47+
48+
49+
/* Command code for disk_ioctrl fucntion */
50+
51+
/* Generic command (Used by FatFs) */
52+
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
53+
#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
54+
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
55+
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
56+
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
57+
58+
/* Generic command (Not used by FatFs) */
59+
#define CTRL_POWER 5 /* Get/Set power status */
60+
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
61+
#define CTRL_EJECT 7 /* Eject media */
62+
#define CTRL_FORMAT 8 /* Create physical format on the media */
63+
64+
/* MMC/SDC specific ioctl command */
65+
#define MMC_GET_TYPE 10 /* Get card type */
66+
#define MMC_GET_CSD 11 /* Get CSD */
67+
#define MMC_GET_CID 12 /* Get CID */
68+
#define MMC_GET_OCR 13 /* Get OCR */
69+
#define MMC_GET_SDSTAT 14 /* Get SD status */
70+
71+
/* ATA/CF specific ioctl command */
72+
#define ATA_GET_REV 20 /* Get F/W revision */
73+
#define ATA_GET_MODEL 21 /* Get model name */
74+
#define ATA_GET_SN 22 /* Get serial number */
75+
76+
#ifdef __cplusplus
77+
}
78+
#endif
79+
80+
#endif

0 commit comments

Comments
 (0)