Implement payload compression

This commit is contained in:
shchmue 2021-05-12 16:47:06 -06:00
parent a7712b173c
commit 918b00ce07
20 changed files with 2305 additions and 28 deletions

11
.gitignore vendored
View file

@ -1,4 +1,9 @@
.vs
.vscode
build
output
research
build/*
output/*
research/*
loader/payload_00.h
loader/payload_01.h
tools/bin2c/bin2c
tools/lz/lz77

View file

@ -8,10 +8,8 @@ include $(DEVKITARM)/base_rules
################################################################################
IPL_LOAD_ADDR := 0x40003000
LPVERSION_MAJOR := 1
LPVERSION_MINOR := 9
LPVERSION_BUGFX := 1
IPL_LOAD_ADDR := 0x40008000
include ./Versions.inc
################################################################################
@ -40,52 +38,84 @@ CUSTOMDEFINES := -DIPL_LOAD_ADDR=$(IPL_LOAD_ADDR)
CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX)
CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC)
# 0: UART_A, 1: UART_B.
#CUSTOMDEFINES += -DDEBUG_UART_PORT=0
#CUSTOMDEFINES += -DDEBUG
# UART Logging: Max baudrate 12.5M.
# DEBUG_UART_PORT - 0: UART_A, 1: UART_B, 2: UART_C.
#CUSTOMDEFINES += -DDEBUG_UART_BAUDRATE=115200 -DDEBUG_UART_INVERT=0 -DDEBUG_UART_PORT=0
#TODO: Considering reinstating some of these when pointer warnings have been fixed.
WARNINGS := -Wall -Wno-array-bounds -Wno-stringop-overread -Wno-stringop-overflow
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
CFLAGS = $(ARCH) -Os -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11 $(WARNINGS) $(CUSTOMDEFINES)
CFLAGS = $(ARCH) -O2 -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -std=gnu11 $(WARNINGS) $(CUSTOMDEFINES)
LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=IPL_LOAD_ADDR=$(IPL_LOAD_ADDR)
LDRDIR := $(wildcard loader)
TOOLSLZ := $(wildcard tools/lz)
TOOLSB2C := $(wildcard tools/bin2c)
TOOLS := $(TOOLSLZ) $(TOOLSB2C)
################################################################################
.PHONY: all clean
.PHONY: all clean $(LDRDIR) $(TOOLS)
all: $(OUTPUTDIR)/$(TARGET).bin
@echo -n "Payload size is "
all: $(OUTPUTDIR)/$(TARGET).bin $(LDRDIR)
@echo "--------------------------------------"
@echo -n "Uncompr size: "
$(eval BIN_SIZE = $(shell wc -c < $(OUTPUTDIR)/$(TARGET)_unc.bin))
@echo $(BIN_SIZE)" Bytes"
@echo "Uncompr Max: 140288 Bytes + 3 KiB BSS"
@if [ ${BIN_SIZE} -gt 140288 ]; then echo "\e[1;33mUncompr size exceeds limit!\e[0m"; fi
@echo -n "Payload size: "
$(eval BIN_SIZE = $(shell wc -c < $(OUTPUTDIR)/$(TARGET).bin))
@echo $(BIN_SIZE)
@echo "Max size is 126296 Bytes."
@echo $(BIN_SIZE)" Bytes"
@echo "Payload Max: 126296 Bytes"
@if [ ${BIN_SIZE} -gt 126296 ]; then echo "\e[1;33mPayload size exceeds limit!\e[0m"; fi
@echo "--------------------------------------"
clean:
clean: $(TOOLS)
@rm -rf $(BUILDDIR)
@rm -rf $(OUTPUTDIR)
$(OUTPUTDIR)/$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf
$(LDRDIR): $(OUTPUTDIR)/$(TARGET).bin
@$(TOOLSLZ)/lz77 $(OUTPUTDIR)/$(TARGET).bin
mv $(OUTPUTDIR)/$(TARGET).bin $(OUTPUTDIR)/$(TARGET)_unc.bin
@mv $(OUTPUTDIR)/$(TARGET).bin.00.lz payload_00
@mv $(OUTPUTDIR)/$(TARGET).bin.01.lz payload_01
@$(TOOLSB2C)/bin2c payload_00 > $(LDRDIR)/payload_00.h
@$(TOOLSB2C)/bin2c payload_01 > $(LDRDIR)/payload_01.h
@rm payload_00
@rm payload_01
@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS) -$(MAKEFLAGS) PAYLOAD_NAME=$(TARGET)
$(TOOLS):
@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS) -$(MAKEFLAGS)
$(OUTPUTDIR)/$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf $(TOOLS)
@mkdir -p "$(@D)"
$(OBJCOPY) -S -O binary $< $@
$(BUILDDIR)/$(TARGET)/$(TARGET).elf: $(OBJS)
$(CC) $(LDFLAGS) -T $(SOURCEDIR)/link.ld $^ -o $@
@$(CC) $(LDFLAGS) -T $(SOURCEDIR)/link.ld $^ -o $@
@echo "Lockpick_RCM was built with the following flags:\nCFLAGS: "$(CFLAGS)"\nLDFLAGS: "$(LDFLAGS)
$(BUILDDIR)/$(TARGET)/%.o: $(SOURCEDIR)/%.c
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
@echo Building $@
@$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: $(SOURCEDIR)/%.S
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@
@echo Building $@
@$(CC) $(CFLAGS) -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.c
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
@echo Building $@
@$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.S
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@
@echo Building $@
@$(CC) $(CFLAGS) -c $< -o $@

4
Versions.inc Normal file
View file

@ -0,0 +1,4 @@
# LP Version.
LPVERSION_MAJOR := 1
LPVERSION_MINOR := 9
LPVERSION_BUGFX := 1

View file

@ -20,7 +20,7 @@
#include <soc/clock.h>
#include <utils/util.h>
#define CONFIG_ENABLE_AHB_REDIRECT
//#define CONFIG_ENABLE_AHB_REDIRECT
void mc_config_tsec_carveout(u32 bom, u32 size1mb, bool lock)
{

View file

@ -19,10 +19,10 @@
//#define IPL_STACK_TOP 0x4003FF00
/* --- BIT/BCT: 0x40000000 - 0x40003000 --- */
/* --- IPL: 0x40003000 - 0x40028000 --- */
/* --- IPL: 0x40008000 - 0x40028000 --- */
#define LDR_LOAD_ADDR 0x40007000
#define IPL_LOAD_ADDR 0x40003000
#define IPL_LOAD_ADDR 0x40008000
#define IPL_SZ_MAX 0x20000 // 128KB.
/* --- XUSB EP context and TRB ring buffers --- */

65
loader/Makefile Normal file
View file

@ -0,0 +1,65 @@
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/base_rules
################################################################################
LDR_LOAD_ADDR := 0x40007000
IPL_MAGIC := 0x43544349 #"ICTC"
include ../Versions.inc
################################################################################
TARGET := loader
BUILDDIR := ../build
OUTPUTDIR := ../output
BDKDIR := bdk
BDKINC := -I../$(BDKDIR)
VPATH += $(dir $(wildcard ../$(BDKDIR)/*/)) $(dir $(wildcard ../$(BDKDIR)/*/*/))
# Main and graphics.
OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \
start.o loader.o lz.o \
)
################################################################################
CUSTOMDEFINES := -DBL_MAGIC=$(IPL_MAGIC)
CUSTOMDEFINES += -DBL_VER_MJ=$(BLVERSION_MAJOR) -DBL_VER_MN=$(BLVERSION_MINOR) -DBL_VER_HF=$(BLVERSION_HOTFX) -DBL_RESERVED=$(BLVERSION_RSVD)
#TODO: Considering reinstating some of these when pointer warnings have been fixed.
WARNINGS := -Wall -Wno-array-bounds -Wno-stringop-overflow
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork
CFLAGS = $(ARCH) -O2 -g -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -std=gnu11 $(WARNINGS) $(CUSTOMDEFINES)
LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections -Xlinker --defsym=LDR_LOAD_ADDR=$(LDR_LOAD_ADDR)
################################################################################
.PHONY: all clean
all: $(TARGET).bin $(TOOLSLZ) $(TOOLSB2C)
clean:
@rm -rf $(OBJS)
$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf
$(OBJCOPY) -S -O binary $< $(OUTPUTDIR)/$(PAYLOAD_NAME).bin
$(BUILDDIR)/$(TARGET)/$(TARGET).elf: $(OBJS)
@$(CC) $(LDFLAGS) -T link.ld $^ -o $@
$(BUILDDIR)/$(TARGET)/%.o: %.c
@$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: %.S
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJS): $(BUILDDIR)/$(TARGET)
$(BUILDDIR)/$(TARGET):
@mkdir -p "$(BUILDDIR)"
@mkdir -p "$(BUILDDIR)/$(TARGET)"
@mkdir -p "$(OUTPUTDIR)"

21
loader/link.ld Normal file
View file

@ -0,0 +1,21 @@
ENTRY(_start)
SECTIONS {
PROVIDE(__ipl_start = LDR_LOAD_ADDR);
. = __ipl_start;
.text : {
*(.text._start);
KEEP(*(._boot_cfg));
KEEP(*(._octopus));
*(.text*);
}
.data : {
*(.data*);
*(.rodata*);
*(._payload_00);
*(._payload_01);
}
__ldr_end = .;
. = ALIGN(0x10);
__ipl_end = .;
}

101
loader/loader.c Normal file
View file

@ -0,0 +1,101 @@
/*
* Copyright (c) 2019 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include "payload_00.h"
#include "payload_01.h"
#include <memory_map.h>
#include <libs/compr/lz.h>
#include <soc/clock.h>
#include <soc/t210.h>
// 0x4003D000: Safe for panic preserving, 0x40038000: Safe for debugging needs.
#define IPL_RELOC_TOP 0x40038000
#define IPL_PATCHED_RELOC_SZ 0x94
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
const volatile char __attribute__((section ("._octopus"))) octopus[] =
"\n"
" ___\n"
" .-' `'.\n"
" / \\\n"
" | ;\n"
" | | ___.--,\n"
" _.._ |0) = (0) | _.---'`__.-( (_.\n"
" __.--'`_.. '.__.\\ '--. \\_.-' ,.--'` `\"\"`\n"
" ( ,.--'` ',__ /./; ;, '.__.'` __\n"
" _`) ) .---.__.' / | |\\ \\__..--\"\" \"\"\"--.,_\n"
" `---' .'.''-._.-'`_./ /\\ '. \\ _.--''````'''--._`-.__.'\n"
" | | .' _.-' | | \\ \\ '. `----`\n"
" \\ \\/ .' \\ \\ '. '-._)\n"
" \\/ / \\ \\ `=.__`'-.\n"
" / /\\ `) ) / / `\"\".`\\\n"
" , _.-'.'\\ \\ / / ( ( / /\n"
" `--'` ) ) .-'.' '.'. | (\n"
" (/` ( (` ) ) '-; [switchbrew]\n";
void loader_main()
{
// Preliminary BPMP clocks init.
CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 0x10; // Set HCLK div to 2 and PCLK div to 1.
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SYS) = 0; // Set SCLK div to 1.
CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20004444; // Set clk source to Run and PLLP_OUT2 (204MHz).
CLOCK(CLK_RST_CONTROLLER_SUPER_SCLK_DIVIDER) = 0x80000000; // Enable SUPER_SDIV to 1.
CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 2; // Set HCLK div to 1 and PCLK div to 3.
CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20003333; // Set SCLK to PLLP_OUT (408MHz).
// Get Loader and Payload size.
u32 payload_size = sizeof(payload_00) + sizeof(payload_01); // Actual payload size.
payload_size += (u32)payload_01 - (u32)payload_00 - sizeof(payload_00); // Add array alignment.
u32 *payload_addr = (u32 *)payload_00;
// Relocate payload to a safer place.
u32 bytes = ALIGN(payload_size, 4) >> 2;
u32 *addr = payload_addr + bytes - 1;
u32 *dst = (u32 *)(IPL_RELOC_TOP - 4);
while (bytes)
{
*dst = *addr;
dst--;
addr--;
bytes--;
}
// Set source address of the first part.
u8 *src_addr = (void *)(IPL_RELOC_TOP - ALIGN(payload_size, 4));
// Uncompress first part.
u32 dst_pos = LZ_Uncompress((const u8 *)src_addr, (u8*)IPL_LOAD_ADDR, sizeof(payload_00));
// Set source address of the second part. Includes array alignment.
src_addr += (u32)payload_01 - (u32)payload_00;
// Uncompress second part.
LZ_Uncompress((const u8 *)src_addr, (u8*)IPL_LOAD_ADDR + dst_pos, sizeof(payload_01));
// Copy over boot configuration storage.
memcpy((u8 *)(IPL_LOAD_ADDR + IPL_PATCHED_RELOC_SZ), &b_cfg, sizeof(boot_cfg_t));
// Chainload into uncompressed payload.
void (*ipl_ptr)() = (void *)IPL_LOAD_ADDR;
(*ipl_ptr)();
// Halt if we managed to get out of execution.
while (true)
;
}

73
loader/start.S Normal file
View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2018 naehrwert
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
.section .text._start
.arm
.extern _reloc_ipl
.type _reloc_ipl, %function
.extern memset
.type memset, %function
.extern loader_main
.type loader_main, %function
.globl _start
.type _start, %function
_start:
ADR R0, _start
LDR R1, =__ipl_start
CMP R0, R1
BEQ _real_start
/* If we are not in the right location already, copy a relocator to upper IRAM. */
ADR R2, _reloc_ipl
LDR R3, =0x4003FF00
MOV R4, #(_real_start - _reloc_ipl)
_copy_loop:
LDMIA R2!, {R5}
STMIA R3!, {R5}
SUBS R4, #4
BNE _copy_loop
/* Use the relocator to copy ourselves into the right place. */
LDR R2, =__ipl_end
SUB R2, R2, R1
LDR R3, =_real_start
LDR R4, =0x4003FF00
BX R4
_reloc_ipl:
LDMIA R0!, {R4-R7}
STMIA R1!, {R4-R7}
SUBS R2, #0x10
BNE _reloc_ipl
/* Jump to the relocated entry. */
BX R3
_real_start:
/* Initially, we place our stack in IRAM but will move it to SDRAM later. */
LDR SP, =0x40007000
LDR R0, =__ldr_end
BL loader_main
B .
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0

View file

@ -202,7 +202,7 @@ static bool _derive_tsec_keys(tsec_ctxt_t *tsec_ctxt, u32 kb, key_derivation_ctx
int res = 0;
u32 retries = 0;
mc_disable_ahb_redirect();
// mc_disable_ahb_redirect();
while (tsec_query(keys->tsec_keys, kb, tsec_ctxt) < 0) {
memset(keys->tsec_keys, 0, sizeof(keys->tsec_keys));
@ -213,7 +213,7 @@ static bool _derive_tsec_keys(tsec_ctxt_t *tsec_ctxt, u32 kb, key_derivation_ctx
}
}
mc_enable_ahb_redirect();
// mc_enable_ahb_redirect();
if (res < 0) {
EPRINTFARGS("ERROR %x dumping TSEC.\n", res);

16
tools/bin2c/Makefile Normal file
View file

@ -0,0 +1,16 @@
NATIVE_CC ?= gcc
ifeq (, $(shell which $(NATIVE_CC) 2>/dev/null))
$(error "Native GCC is missing. Please install it first. If it's path is custom, set it with export NATIVE_CC=<path to native gcc toolchain>")
endif
.PHONY: all clean
all: bin2c
@echo > /dev/null
clean:
@rm -f bin2c
bin2c: bin2c.c
@$(NATIVE_CC) -o $@ bin2c.c

83
tools/bin2c/bin2c.c Normal file
View file

@ -0,0 +1,83 @@
/*
* This is bin2c program, which allows you to convert binary file to
* C language array, for use as embedded resource, for instance you can
* embed graphics or audio file directly into your program.
* This is public domain software, use it on your own risk.
* Contact Serge Fukanchik at fuxx@mail.ru if you have any questions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
/* Replace . with _ */
char*
make_ident ( char* name )
{
char* ret;
char* p;
ret = strdup ( name );
for ( p = ret; p[0]; p++ )
{
if ( !isalnum ( p[0] ) ) p[0] = '_';
}
return ret;
}
int
main ( int argc, char* argv[] )
{
unsigned char buf[BUFSIZ];
char* ident;
FILE *fd;
size_t size, i, total, blksize = BUFSIZ;
int need_comma = 0;
if ( argc != 2 )
{
fprintf ( stderr, "Usage: %s binary_file > output_file\n", argv[0] );
return -1;
}
fd = fopen ( argv[1], "rb" );
if ( fd == NULL )
{
fprintf ( stderr, "%s: can't open %s for reading\n", argv[0], argv[1] );
return -1;
}
fseek(fd, 0, SEEK_END);
size = ftell(fd);
rewind(fd);
ident = make_ident ( argv[1] );
printf ( "static const unsigned char __attribute__((section (\"._%s\"))) %s[] = {", ident, ident );
for ( total = 0; total < size; )
{
if ( size - total < blksize ) blksize = size - total;
if ( fread ( buf, 1, blksize, fd ) != blksize )
{
fprintf ( stderr, "%s: file read error\n", argv[0] );
return -1;
}
for ( i = 0; i < blksize; i++ )
{
if ( need_comma ) printf ( ", " );
else need_comma = 1;
if ( ( total % 11 ) == 0 ) printf ( "\n\t" );
printf ( "0x%.2x", buf[i] );
total++;
}
}
printf ( "\n};\n" );
fclose ( fd );
free ( ident );
return 0;
}

641
tools/emc.def Normal file
View file

@ -0,0 +1,641 @@
EMC_DBG 8
EMC_CFG C
EMC_CONFIG_SAMPLE_DELAY 5f0
EMC_CFG_UPDATE 5f4
EMC_ADR_CFG 10
EMC_REFCTRL 20
EMC_PIN 24
EMC_TIMING_CONTROL 28
EMC_RC 2c
EMC_RFC 30
EMC_RFCPB 590
EMC_RAS 34
EMC_RP 38
EMC_R2W 3c
EMC_W2R 40
EMC_R2P 44
EMC_W2P 48
EMC_CCDMW 5c0
EMC_RD_RCD 4c
EMC_WR_RCD 50
EMC_RRD 54
EMC_REXT 58
EMC_WDV 5c
EMC_QUSE 60
EMC_QRST 64
EMC_ISSUE_QRST 428
EMC_QSAFE 68
EMC_RDV 6c
EMC_REFRESH 70
EMC_BURST_REFRESH_NUM 74
EMC_PDEX2WR 78
EMC_PDEX2RD 7c
EMC_PDEX2CKE 118
EMC_PCHG2PDEN 80
EMC_ACT2PDEN 84
EMC_AR2PDEN 88
EMC_RW2PDEN 8c
EMC_CKE2PDEN 11c
EMC_TXSR 90
EMC_TCKE 94
EMC_TFAW 98
EMC_TRPAB 9c
EMC_TCLKSTABLE a0
EMC_TCLKSTOP a4
EMC_TREFBW a8
EMC_TPPD ac
EMC_PDEX2MRR b4
EMC_ODT_WRITE b0
EMC_WEXT b8
EMC_RFC_SLR c0
EMC_MRS_WAIT_CNT2 c4
EMC_MRS_WAIT_CNT c8
EMC_MRS cc
EMC_EMRS d0
EMC_REF d4
EMC_PRE d8
EMC_NOP dc
EMC_SELF_REF e0
EMC_DPD e4
EMC_MRW e8
EMC_MRR ec
EMC_CMDQ f0
EMC_MC2EMCQ f4
EMC_FBIO_SPARE 100
EMC_FBIO_CFG5 104
EMC_CFG_RSV 120
EMC_ACPD_CONTROL 124
EMC_MPC 128
EMC_EMRS2 12c
EMC_EMRS3 130
EMC_MRW2 134
EMC_MRW3 138
EMC_MRW4 13c
EMC_MRW5 4a0
EMC_MRW6 4a4
EMC_MRW7 4a8
EMC_MRW8 4ac
EMC_MRW9 4b0
EMC_MRW10 4b4
EMC_MRW11 4b8
EMC_MRW12 4bc
EMC_MRW13 4c0
EMC_MRW14 4c4
EMC_MRW15 4d0
EMC_CFG_SYNC 4d4
EMC_CLKEN_OVERRIDE 140
EMC_R2R 144
EMC_W2W 148
EMC_EINPUT 14c
EMC_EINPUT_DURATION 150
EMC_PUTERM_EXTRA 154
E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SWIZZLE_RANK0_BYTE3 410
EMC_SWIZZLE_RANK1_BYTE0 418
EMC_SWIZZLE_RANK1_BYTE1 41c
EMC_SWIZZLE_RANK1_BYTE2 420
EMC_SWIZZLE_RANK1_BYTE3 424
EMC_TR_TIMING_0 3b4
EMC_TR_CTRL_0 3b8
EMC_TR_CTRL_1 3bc
EMC_TR_DVFS 460
EMC_SWITCH_BACK_CTRL 3c0
EMC_TR_RDV 3c4
EMC_TR_QPOP 3f4
EMC_TR_RDV_MASK 3f8
EMC_TR_QSAFE 3fc
EMC_TR_QRST 400
EMC_IBDLY 468
EMC_OBDLY 46c
EMC_TXDSRVTTGEN 480
EMC_WE_DURATION 48c
EMC_WS_DURATION 490
EMC_WEV 494
EMC_WSV 498
EMC_CFG_3 49c
EMC_CFG_PIPE_2 554
EMC_CFG_PIPE_CLK 558
EMC_CFG_PIPE_1 55c
EMC_CFG_PIPE 560
EMC_QPOP 564
EMC_QUSE_WIDTH 568
EMC_PUTERM_WIDTH 56c
EMC_PROTOBIST_CONFIG_ADR_1 5d0
EMC_PROTOBIST_CONFIG_ADR_2 5d4
EMC_PROTOBIST_MISC 5d8
EMC_PROTOBIST_WDATA_LOWER 5dc
EMC_PROTOBIST_WDATA_UPPER 5e0
EMC_PROTOBIST_RDATA 5ec
EMC_DLL_CFG_0 5e4
EMC_DLL_CFG_1 5e8
EMC_TRAINING_CMD e00
EMC_TRAINING_CTRL e04
EMC_TRAINING_STATUS e08
EMC_TRAINING_QUSE_CORS_CTRL e0c
EMC_TRAINING_QUSE_FINE_CTRL e10
EMC_TRAINING_QUSE_CTRL_MISC e14
EMC_TRAINING_WRITE_FINE_CTRL e18
EMC_TRAINING_WRITE_CTRL_MISC e1c
EMC_TRAINING_WRITE_VREF_CTRL e20
EMC_TRAINING_READ_FINE_CTRL e24
EMC_TRAINING_READ_CTRL_MISC e28
EMC_TRAINING_READ_VREF_CTRL e2c
EMC_TRAINING_CA_FINE_CTRL e30
EMC_TRAINING_CA_CTRL_MISC e34
EMC_TRAINING_CA_CTRL_MISC1 e38
EMC_TRAINING_CA_VREF_CTRL e3c
EMC_TRAINING_CA_TADR_CTRL e40
EMC_TRAINING_SETTLE e44
EMC_TRAINING_DEBUG_CTRL e48
EMC_TRAINING_DEBUG_DQ0 e4c
EMC_TRAINING_DEBUG_DQ1 e50
EMC_TRAINING_DEBUG_DQ2 e54
EMC_TRAINING_DEBUG_DQ3 e58
EMC_TRAINING_MPC e5c
EMC_TRAINING_PATRAM_CTRL e60
EMC_TRAINING_PATRAM_DQ e64
EMC_TRAINING_PATRAM_DMI e68
EMC_TRAINING_VREF_SETTLE e6c
EMC_TRAINING_RW_EYE_CENTER_IB_BYTE0 e70
EMC_TRAINING_RW_EYE_CENTER_IB_BYTE1 e74
EMC_TRAINING_RW_EYE_CENTER_IB_BYTE2 e78
EMC_TRAINING_RW_EYE_CENTER_IB_BYTE3 e7c
EMC_TRAINING_RW_EYE_CENTER_IB_MISC e80
EMC_TRAINING_RW_EYE_CENTER_OB_BYTE0 e84
EMC_TRAINING_RW_EYE_CENTER_OB_BYTE1 e88
EMC_TRAINING_RW_EYE_CENTER_OB_BYTE2 e8c
EMC_TRAINING_RW_EYE_CENTER_OB_BYTE3 e90
EMC_TRAINING_RW_EYE_CENTER_OB_MISC e94
EMC_TRAINING_RW_OFFSET_IB_BYTE0 e98
EMC_TRAINING_RW_OFFSET_IB_BYTE1 e9c
EMC_TRAINING_RW_OFFSET_IB_BYTE2 ea0
EMC_TRAINING_RW_OFFSET_IB_BYTE3 ea4
EMC_TRAINING_RW_OFFSET_IB_MISC ea8
EMC_TRAINING_RW_OFFSET_OB_BYTE0 eac
EMC_TRAINING_RW_OFFSET_OB_BYTE1 eb0
EMC_TRAINING_RW_OFFSET_OB_BYTE2 eb4
EMC_TRAINING_RW_OFFSET_OB_BYTE3 eb8
EMC_TRAINING_RW_OFFSET_OB_MISC ebc
EMC_TRAINING_OPT_CA_VREF ec0
EMC_TRAINING_OPT_DQ_OB_VREF ec4
EMC_TRAINING_OPT_DQ_IB_VREF_RANK0 ec8
EMC_TRAINING_OPT_DQ_IB_VREF_RANK1 ecc
EMC_TRAINING_QUSE_VREF_CTRL ed0
EMC_TRAINING_OPT_DQS_IB_VREF_RANK0 ed4
EMC_TRAINING_OPT_DQS_IB_VREF_RANK1 ed8
EMC_TRAINING_DRAMC_TIMING edc
EMC_PMACRO_QUSE_DDLL_RANK0_0 600
EMC_PMACRO_QUSE_DDLL_RANK0_1 604
EMC_PMACRO_QUSE_DDLL_RANK0_2 608
EMC_PMACRO_QUSE_DDLL_RANK0_3 60c
EMC_PMACRO_QUSE_DDLL_RANK0_4 610
EMC_PMACRO_QUSE_DDLL_RANK0_5 614
EMC_PMACRO_QUSE_DDLL_RANK1_0 620
EMC_PMACRO_QUSE_DDLL_RANK1_1 624
EMC_PMACRO_QUSE_DDLL_RANK1_2 628
EMC_PMACRO_QUSE_DDLL_RANK1_3 62c
EMC_PMACRO_QUSE_DDLL_RANK1_4 630
EMC_PMACRO_QUSE_DDLL_RANK1_5 634
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0 640
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1 644
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2 648
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3 64c
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_4 650
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_5 654
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0 660
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1 664
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2 668
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3 66c
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_4 670
EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_5 674
EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_0 680
EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_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EMC_PMACRO_BRICK_MAPPING_0 c80
EMC_PMACRO_BRICK_MAPPING_1 c84
EMC_PMACRO_BRICK_MAPPING_2 c88
EMC_PMACRO_DDLLCAL_CAL ce0
EMC_PMACRO_DDLL_OFFSET ce4
EMC_PMACRO_DDLL_PERIODIC_OFFSET ce8
EMC_PMACRO_BRICK_CTRL_RFU1 330
EMC_PMACRO_BRICK_CTRL_RFU2 334
EMC_PMACRO_CMD_BRICK_CTRL_FDPD 318
EMC_PMACRO_DATA_BRICK_CTRL_FDPD 31c
EMC_PMACRO_TRAINING_CTRL_0 cf8
EMC_PMACRO_TRAINING_CTRL_1 cfc
EMC_PMC_SCRATCH1 440
EMC_PMC_SCRATCH2 444
EMC_PMC_SCRATCH3 448

36
tools/fix_regs.py Normal file
View file

@ -0,0 +1,36 @@
import re
import sys
def parse_defs(fname):
f = open(fname, "r")
lines = f.readlines()
f.close()
res = {}
for l in lines:
p = [str(_.strip()) for _ in l.strip().split(" ", 1)]
res[int(p[1], 16)] = p[0]
return res
mc = parse_defs("mc.def")
emc = parse_defs("emc.def")
f = open(sys.argv[1], "r")
buf = f.read()
f.close()
def fix(m):
what = m.groups()[0]
off = int(m.groups()[1], 16)
if what == "MC":
if off in mc:
return "MC({0})".format(mc[off])
elif what == "EMC":
if off in emc:
return "EMC({0})".format(emc[off])
return "{0}(0x{1:X})".format(what, off)
buf = re.sub(r'([A-Z]+)\(0x([0-9a-fA-F]+)\)', fix, buf)
f = open(sys.argv[2], "w")
f.write(buf)
f.close()

16
tools/lz/Makefile Normal file
View file

@ -0,0 +1,16 @@
NATIVE_CC ?= gcc
ifeq (, $(shell which $(NATIVE_CC) 2>/dev/null))
$(error "Native GCC is missing. Please install it first. If it's path is custom, set it with export NATIVE_CC=<path to native gcc toolchain>")
endif
.PHONY: all clean
all: lz77
@echo > /dev/null
clean:
@rm -f lz77
lz77: lz.c lz77.c
@$(NATIVE_CC) -o $@ lz.c lz77.c

546
tools/lz/lz.c Normal file
View file

@ -0,0 +1,546 @@
//
// Name: lz.c
// Author: Marcus Geelnard
// Description: LZ77 coder/decoder implementation.
// Reentrant: Yes
// $ATH_LICENSE_NULL$
//
// The LZ77 compression scheme is a substitutional compression scheme
// proposed by Abraham Lempel and Jakob Ziv in 1977. It is very simple in
// its design, and uses no fancy bit level compression.
//
// This is my first attempt at an implementation of a LZ77 code/decoder.
//
// The principle of the LZ77 compression algorithm is to store repeated
// occurrences of strings as references to previous occurrences of the same
// string. The point is that the reference consumes less space than the
// string itself, provided that the string is long enough (in this
// implementation, the string has to be at least 4 bytes long, since the
// minimum coded reference is 3 bytes long). Also note that the term
// "string" refers to any kind of byte sequence (it does not have to be
// an ASCII string, for instance).
//
// The coder uses a brute force approach to finding string matches in the
// history buffer (or "sliding window", if you wish), which is very, very
// slow. I recon the complexity is somewhere between O(n^2) and O(n^3),
// depending on the input data.
//
// There is also a faster implementation that uses a large working buffer
// in which a "jump table" is stored, which is used to quickly find
// possible string matches (see the source code for LZ_CompressFast() for
// more information). The faster method is an order of magnitude faster,
// but still quite slow compared to other compression methods.
//
// The upside is that decompression is very fast, and the compression ratio
// is often very good.
//
// The reference to a string is coded as a (length,offset) pair, where the
// length indicates the length of the string, and the offset gives the
// offset from the current data position. To distinguish between string
// references and literal strings (uncompressed bytes), a string reference
// is preceded by a marker byte, which is chosen as the least common byte
// symbol in the input data stream (this marker byte is stored in the
// output stream as the first byte).
//
// Occurrences of the marker byte in the stream are encoded as the marker
// byte followed by a zero byte, which means that occurrences of the marker
// byte have to be coded with two bytes.
//
// The lengths and offsets are coded in a variable length fashion, allowing
// values of any magnitude (up to 4294967295 in this implementation).
//
// With this compression scheme, the worst case compression result is
// (257/256)*insize + 1.
//
//------------------------------------------------------------------------
// Copyright (c) 2003-2006 Marcus Geelnard
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
// Marcus Geelnard
// marcus.geelnard at home.se
//
//
// This file has been altered from the original version.
//
/*************************************************************************
* Constants used for LZ77 coding
*************************************************************************/
/* Maximum offset (can be any size < 2^31). Lower values give faster
compression, while higher values gives better compression. The default
value of 100000 is quite high. Experiment to see what works best for
you. */
#define LZ_MAX_OFFSET 100000
/*************************************************************************
* INTERNAL FUNCTIONS *
*************************************************************************/
/*************************************************************************
* _LZ_StringCompare() - Return maximum length string match.
*************************************************************************/
static unsigned int _LZ_StringCompare( unsigned char * str1,
unsigned char * str2, unsigned int minlen, unsigned int maxlen )
{
unsigned int len;
for( len = minlen; (len < maxlen) && (str1[len] == str2[len]); ++ len );
return len;
}
/*************************************************************************
* _LZ_WriteVarSize() - Write unsigned integer with variable number of
* bytes depending on value.
*************************************************************************/
static int _LZ_WriteVarSize( unsigned int x, unsigned char * buf )
{
unsigned int y;
int num_bytes, i, b;
/* Determine number of bytes needed to store the number x */
y = x >> 3;
for( num_bytes = 5; num_bytes >= 2; -- num_bytes )
{
if( y & 0xfe000000 ) break;
y <<= 7;
}
/* Write all bytes, seven bits in each, with 8:th bit set for all */
/* but the last byte. */
for( i = num_bytes-1; i >= 0; -- i )
{
b = (x >> (i*7)) & 0x0000007f;
if( i > 0 )
{
b |= 0x00000080;
}
*buf ++ = (unsigned char) b;
}
/* Return number of bytes written */
return num_bytes;
}
/*************************************************************************
* _LZ_ReadVarSize() - Read unsigned integer with variable number of
* bytes depending on value.
*************************************************************************/
static int _LZ_ReadVarSize( unsigned int * x, unsigned char * buf )
{
unsigned int y, b, num_bytes;
/* Read complete value (stop when byte contains zero in 8:th bit) */
y = 0;
num_bytes = 0;
do
{
b = (unsigned int) (*buf ++);
y = (y << 7) | (b & 0x0000007f);
++ num_bytes;
}
while( b & 0x00000080 );
/* Store value in x */
*x = y;
/* Return number of bytes read */
return num_bytes;
}
/*************************************************************************
* PUBLIC FUNCTIONS *
*************************************************************************/
/*************************************************************************
* LZ_Compress() - Compress a block of data using an LZ77 coder.
* in - Input (uncompressed) buffer.
* out - Output (compressed) buffer. This buffer must be 0.4% larger
* than the input buffer, plus one byte.
* insize - Number of input bytes.
* The function returns the size of the compressed data.
*************************************************************************/
int LZ_Compress( unsigned char *in, unsigned char *out,
unsigned int insize )
{
unsigned char marker, symbol;
unsigned int inpos, outpos, bytesleft, i;
unsigned int maxoffset, offset, bestoffset;
unsigned int maxlength, length, bestlength;
unsigned int histogram[ 256 ];
unsigned char *ptr1, *ptr2;
/* Do we have anything to compress? */
if( insize < 1 )
{
return 0;
}
/* Create histogram */
for( i = 0; i < 256; ++ i )
{
histogram[ i ] = 0;
}
for( i = 0; i < insize; ++ i )
{
++ histogram[ in[ i ] ];
}
/* Find the least common byte, and use it as the marker symbol */
marker = 0;
for( i = 1; i < 256; ++ i )
{
if( histogram[ i ] < histogram[ marker ] )
{
marker = i;
}
}
/* Remember the marker symbol for the decoder */
out[ 0 ] = marker;
/* Start of compression */
inpos = 0;
outpos = 1;
/* Main compression loop */
bytesleft = insize;
do
{
/* Determine most distant position */
if( inpos > LZ_MAX_OFFSET ) maxoffset = LZ_MAX_OFFSET;
else maxoffset = inpos;
/* Get pointer to current position */
ptr1 = &in[ inpos ];
/* Search history window for maximum length string match */
bestlength = 3;
bestoffset = 0;