rework build process

This commit is contained in:
Zack Buhman 2024-09-01 22:59:03 -05:00
parent 3459842128
commit 04cfb2ea0e
34 changed files with 225 additions and 99 deletions

View File

@ -1,23 +1,16 @@
OPT = -Os
all: main.nds
res/%.h: res/%.data
$(BUILD_BINARY_H)
res/%.pal.h: res/%.data.pal
$(BUILD_BINARY_H)
MAIN_OBJ = \
OBJ = \
header.o \
start.o \
main.o \
res/player.data.o \
res/player.data.pal.o \
res/bowser.data.o \
res/bowser.data.pal.o
arm9/arm9.bin.o \
arm7/arm7.bin.o
main.elf: $(MAIN_OBJ)
all: cartridge.bin
include arm9.mk
cartridge.elf: $(OBJ)
TARGET = arm-none-eabi-
AARCH = -march=armv4t -mlittle-endian
OBJARCH = -O elf32-littlearm -B armv4t
LDSCRIPT = cartridge.lds
include common.mk

11
arm7/Makefile Normal file
View File

@ -0,0 +1,11 @@
OPT = -Os
OBJ = \
start.o
all: arm7.bin
arm7.elf: $(OBJ)
include arm7.mk
include ../common.mk

50
arm7/arm7.lds Normal file
View File

@ -0,0 +1,50 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
MEMORY
{
ram : ORIGIN = 0x02000000, LENGTH = 4M
}
SECTIONS
{
. = ORIGIN(ram) + 0x8000;
.text ALIGN(4) :
{
KEEP(*(.text.start))
*(.text)
*(.text.*)
*(.glue_7t)
*(.glue_7)
*(.vfp11_veneer)
*(.v4_bx)
} > ram
.data ALIGN(4) :
{
*(.data)
*(.data.*)
} > ram
.rodata ALIGN(4) :
{
*(.rodata)
*(.rodata.*)
} > ram
.ctors ALIGN(4) :
{
KEEP(*(.ctors))
KEEP(*(.ctors.*))
} > ram
.bss ALIGN(4) (NOLOAD) :
{
*(.bss)
*(.bss.*)
*(COMMON)
} > ram
INCLUDE "../debug.lds"
}
INCLUDE "../symbols.lds"

5
arm7/arm7.mk Normal file
View File

@ -0,0 +1,5 @@
TARGET = arm-none-eabi-
AARCH = -march=armv4t -mlittle-endian
CARCH = -march=armv4t -mtune=arm7tdmi -mlittle-endian -mno-thumb-interwork
OBJARCH = -O elf32-littlearm -B armv4t
LDSCRIPT = arm7.lds

4
arm7/start.s Normal file
View File

@ -0,0 +1,4 @@
.section .text.start
.global _start
_start:
b _start

18
arm9/Makefile Normal file
View File

@ -0,0 +1,18 @@
OPT = -Os
OBJ = \
start.o \
main.o \
../res/player.data.o \
../res/player.data.pal.o \
../res/bowser.data.o \
../res/bowser.data.pal.o
all: arm9.bin
arm9.elf: $(OBJ)
CFLAGS += -I../include
include arm9.mk
include ../common.mk

View File

@ -2,63 +2,50 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
MEMORY
{
rom : ORIGIN = 0x00000000, LENGTH = 4M
ram : ORIGIN = 0x02000000, LENGTH = 4M
}
SECTIONS
{
. = ORIGIN(rom);
.text.header ALIGN(4) :
{
KEEP(*(.text.header))
} > rom
. = ORIGIN(ram);
.text.arm7 ALIGN(4) :
{
KEEP(*(.text.7start))
} > ram AT> rom
.text ALIGN(4) :
{
KEEP(*(.text.9start))
KEEP(*(.text.start))
*(.text)
*(.text.*)
*(.glue_7t)
*(.glue_7)
*(.vfp11_veneer)
*(.v4_bx)
} > ram AT> rom
} > ram
.data ALIGN(4) :
{
*(.data)
*(.data.*)
} > ram AT> rom
} > ram
.rodata ALIGN(4) :
{
*(.rodata)
*(.rodata.*)
} > ram AT> rom
} > ram
.ctors ALIGN(4) :
{
KEEP(*(.ctors))
KEEP(*(.ctors.*))
} > ram AT> rom
} > ram
.bss ALIGN(4) (NOLOAD) :
{
*(.bss)
*(.bss.*)
*(COMMON)
} > ram AT> rom
} > ram
INCLUDE "debug.lds"
INCLUDE "../debug.lds"
}
INCLUDE "symbols.lds"
INCLUDE "addresses_arm9.lds"
INCLUDE "../symbols.lds"
INCLUDE "addresses.lds"

View File

@ -5,10 +5,10 @@
#include "obj.h"
#include "oam.h"
#include "res/player.h"
#include "res/player.pal.h"
#include "res/bowser.h"
#include "res/bowser.pal.h"
#include "../res/player.data.h"
#include "../res/player.data.pal.h"
#include "../res/bowser.data.h"
#include "../res/bowser.data.pal.h"
static inline uint16_t rgb565(const uint8_t * buf)
{
@ -430,23 +430,23 @@ void main()
| DISPCNT__character_obj_mapping_mode__1d_mapping
;
uint32_t pal_size = (uint32_t)&_binary_res_player_data_pal_size;
const uint8_t * pal = (const uint8_t *)&_binary_res_player_data_pal_start;
uint32_t pal_size = (uint32_t)&_binary_player_data_pal_size;
const uint8_t * pal = (const uint8_t *)&_binary_player_data_pal_start;
// palette ram
for (int i = 0; i < 15; i++) {
palette_ram.a.bg.palette[0].color[i] = rgb565(&pal[i * 3]);
}
uint32_t b_pal_size = (uint32_t)&_binary_res_bowser_data_pal_size;
const uint8_t * b_pal = (const uint8_t *)&_binary_res_bowser_data_pal_start;
uint32_t b_pal_size = (uint32_t)&_binary_bowser_data_pal_size;
const uint8_t * b_pal = (const uint8_t *)&_binary_bowser_data_pal_start;
// bowser palette ram
for (int i = 0; i < 16; i++) {
palette_ram.b.obj.palette[0].color[i] = rgb565(&b_pal[i * 3]);
}
const uint8_t * data = (const uint8_t *)&_binary_res_player_data_start;
const uint8_t * data = (const uint8_t *)&_binary_player_data_start;
for (int y = 0; y < 48; y++) {
uint8_t a = data[y * 8 + 7];
@ -479,7 +479,7 @@ void main()
bg_vram.a.screen.offset[0].block[31].u16[32 * 1 + 1] = 4;
bg_vram.a.screen.offset[0].block[31].u16[32 * 2 + 1] = 5;
const uint8_t * b_data = (const uint8_t *)&_binary_res_bowser_data_start;
const uint8_t * b_data = (const uint8_t *)&_binary_bowser_data_start;
for (int c_y = 0; c_y < 8; c_y++) {
for (int c_x = 0; c_x < 8; c_x++) {

View File

@ -22,7 +22,7 @@ _fill_loop.\@:
_fill_break.\@:
.endm
.section .text.9start
.section .text.start
.global _start
_start:
/*
@ -52,14 +52,8 @@ _link_bss:
_c_runtime:
/* set stack pointer */
ldr sp, =0x23ffffc
ldr sp, =__stack_end
/* jump to main */
ldr r0, =main
bx r0
.section .text.7start
.global _7start
_7start:
mov r1, #0x7
b _7start

51
cartridge.lds Normal file
View File

@ -0,0 +1,51 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
MEMORY
{
rom : ORIGIN = 0x00000000, LENGTH = 4M
}
SECTIONS
{
. = 0x00000000;
_start = .;
.text.header ALIGN(4) :
{
KEEP(*(.text.header))
} AT>rom
. = 0x02000000;
.text.arm9 ALIGN(4) :
{
KEEP(arm9/arm9.bin.o(*))
} AT>rom
. = 0x02000000 + 0x8000;
.text.arm7 ALIGN(4) :
{
KEEP(arm7/arm7.bin.o(*))
} AT>rom
/DISCARD/ :
{
*(.glue_7) *(.glue_7t) *(.vfp11_veneer) *(.v4_bx)
*(.ARM.attributes) *(.iplt) *(.rel.iplt) *(.igot.plt)
}
}
/* header symbols */
_arm9_offset = LOADADDR(.text.arm9);
_arm9_entry = ADDR(.text.arm9);
_arm9_addr = ADDR(.text.arm9);
_arm9_size = SIZEOF(.text.arm9);
_arm7_offset = LOADADDR(.text.arm7);
_arm7_entry = ADDR(.text.arm7);
_arm7_addr = ADDR(.text.arm7);
_arm7_size = SIZEOF(.text.arm7);
_rom_size = SIZEOF(.text.header) + SIZEOF(.text.arm9) + SIZEOF(.text.arm7);
_header_size = SIZEOF(.text.header);

View File

@ -80,6 +80,12 @@ endef
-include $(shell find -type f -name '*.d')
clean:
find -P \
-regextype posix-egrep \
-regex '.*\.(nds|o|d|bin|elf|gch)$$' \
-exec rm {} \;
.SUFFIXES:
.INTERMEDIATE:
.SECONDARY:

View File

@ -1,7 +1,7 @@
.section .text.header
.fill 12,1,0x0 /* Game Title */
.ascii "CODE" /* Game Code */
.ascii "game title " /* Game Title */
.ascii "NTR1" /* Game Code */
.ascii "00" /* Maker Code */
.byte 0x0 /* Unit Code */
.byte 0x0 /* Encryption Seed Select */
@ -30,7 +30,7 @@
.long 0x00586000 /* 040001a4 setting for normal commands */
.long 0x001808F8 /* 040001a4 setting for KEY1 commands */
.long 0x00000000 /* Icon/Title offset */
.short 0x8e6e /* Secure Area Checksum */
.short 0x4bff /* Secure Area Checksum */
.short 0x0d7e /* Secure Area Delay */
.long 0x02000a58 /* ARM9 auto load list hook ram address */
.long 0x02380158 /* ARM7 auto load list hook ram address */

View File

View File

@ -43,11 +43,14 @@ assert buf[0x15c] == 0x56
assert buf[0x15d] == 0xcf
logo_crc = crc16_modbus(buf[0x0c0:0xc0 + 0x9c])
print(hex(logo_crc))
print("logo", hex(logo_crc))
assert logo_crc == 0xcf56
header_crc = crc16_modbus(buf[0:0x15e])
print(hex(header_crc))
print("header", hex(header_crc))
secure_area_crc = crc16_modbus(buf[0x4000:0x8000])
print("secure area", hex(secure_area_crc))
import struct
header_crc_b = struct.pack('<H', header_crc)

View File

@ -1,7 +1,7 @@
set -eux
python format.py 0x04000000.txt graphics_engine_a 0x1000 > ../graphics_engine_a.h
python format.py 0x04001000.txt graphics_engine_b 0 > ../graphics_engine_b.h
python format.py 0x04000000.txt graphics_engine_a 0x1000 > ../include/graphics_engine_a.h
python format.py 0x04001000.txt graphics_engine_b 0 > ../include/graphics_engine_b.h
make graphics_engine_bits.csv
python format_bits.py graphics_engine_bits.csv > ../bits.h
python format_bits.py graphics_engine_bits.csv > ../include/bits.h

18
res/Makefile Normal file
View File

@ -0,0 +1,18 @@
OBJ += $(patsubst %.data,%.data.o,$(wildcard *.data))
OBJ += $(patsubst %.data.pal,%.data.pal.o,$(wildcard *.data.pal))
HEADER += $(patsubst %.data,%.data.h,$(wildcard *.data))
HEADER += $(patsubst %.data.pal,%.data.pal.h,$(wildcard *.data.pal))
TARGET=arm-none-eabi-
OBJARCH=-O elf32-littlearm -B armv5te
all: $(OBJ) $(HEADER)
include ../common.mk
%.data.h: %.data
$(BUILD_BINARY_H)
%.data.pal.h: %.data.pal
$(BUILD_BINARY_H)

5
res/bowser.data.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_bowser_data_start __asm("_binary_bowser_data_start");
extern uint32_t _binary_bowser_data_end __asm("_binary_bowser_data_end");
extern uint32_t _binary_bowser_data_size __asm("_binary_bowser_data_size");

5
res/bowser.data.pal.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_bowser_data_pal_start __asm("_binary_bowser_data_pal_start");
extern uint32_t _binary_bowser_data_pal_end __asm("_binary_bowser_data_pal_end");
extern uint32_t _binary_bowser_data_pal_size __asm("_binary_bowser_data_pal_size");

View File

@ -1,5 +0,0 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_res_bowser_data_start __asm("_binary_res_bowser_data_start");
extern uint32_t _binary_res_bowser_data_end __asm("_binary_res_bowser_data_end");
extern uint32_t _binary_res_bowser_data_size __asm("_binary_res_bowser_data_size");

View File

@ -1,5 +0,0 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_res_bowser_data_pal_start __asm("_binary_res_bowser_data_pal_start");
extern uint32_t _binary_res_bowser_data_pal_end __asm("_binary_res_bowser_data_pal_end");
extern uint32_t _binary_res_bowser_data_pal_size __asm("_binary_res_bowser_data_pal_size");

5
res/player.data.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_player_data_start __asm("_binary_player_data_start");
extern uint32_t _binary_player_data_end __asm("_binary_player_data_end");
extern uint32_t _binary_player_data_size __asm("_binary_player_data_size");

5
res/player.data.pal.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_player_data_pal_start __asm("_binary_player_data_pal_start");
extern uint32_t _binary_player_data_pal_end __asm("_binary_player_data_pal_end");
extern uint32_t _binary_player_data_pal_size __asm("_binary_player_data_pal_size");

View File

@ -1,5 +0,0 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_res_player_data_start __asm("_binary_res_player_data_start");
extern uint32_t _binary_res_player_data_end __asm("_binary_res_player_data_end");
extern uint32_t _binary_res_player_data_size __asm("_binary_res_player_data_size");

View File

@ -1,5 +0,0 @@
#pragma once
#include <stdint.h>
extern uint32_t _binary_res_player_data_pal_start __asm("_binary_res_player_data_pal_start");
extern uint32_t _binary_res_player_data_pal_end __asm("_binary_res_player_data_pal_end");
extern uint32_t _binary_res_player_data_pal_size __asm("_binary_res_player_data_pal_size");

View File

@ -17,17 +17,3 @@ __ctors_link_end = ADDR(.ctors) + SIZEOF(.ctors);
__bss_link_start = ADDR(.bss);
__bss_link_end = ADDR(.bss) + SIZEOF(.bss);
/* header symbols */
_arm9_offset = LOADADDR(.text);
_arm9_entry = ADDR(.text);
_arm9_addr = ADDR(.text);
_arm9_size = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata) + SIZEOF(.ctors);
_arm7_offset = LOADADDR(.text.arm7);
_arm7_entry = ADDR(.text.arm7);
_arm7_addr = ADDR(.text.arm7);
_arm7_size = SIZEOF(.text.arm7);
_rom_size = SIZEOF(.text.header) + SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata) + SIZEOF(.ctors) + SIZEOF(.text.arm7);
_header_size = SIZEOF(.text.header);