Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Updated debugprints for better readability, cleaned up flash driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryzee119 committed May 14, 2020
1 parent 0a264c0 commit 44d2526
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 153 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.release/
/Xenium-Tools/bin
/Xenium-Tools/.vscode

# Prerequisites
*.d
Expand Down Expand Up @@ -36,6 +38,7 @@
*.app
*.i*86
*.x86_64
*.iso

# Debug files
*.dSYM/
Expand Down
1 change: 0 additions & 1 deletion Xenium-Tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
XBE_TITLE=xenium-tools
GEN_XISO = $(XBE_TITLE).iso
SRCS = $(wildcard $(CURDIR)/*.c)
NXDK_DIR = $(CURDIR)/../..
NXDK_SDL = y
include $(NXDK_DIR)/Makefile
3 changes: 1 addition & 2 deletions Xenium-Tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Whilst these tools will work for a genuine Xenium and OpenXenium, it is only rec

## Building
* Install [NXDK](https://github.com/XboxDev/nxdk) and its dependencies.
* Install cmake. i.e. `sudo apt-get install cmake`.
* Make sure that the NXDK_DIR variable in the Makefile points to correct place.
* Set NXDK_DIR path `export NXDK_DIR=/path/to/nxdk`
* Compile xenium-tools using `make` from within the xenium-tools directory.
* This will generate an xbe which you need to transfer to your Xbox.

Expand Down
114 changes: 23 additions & 91 deletions Xenium-Tools/am29lv160mt.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,111 +23,56 @@
//These functions should be read in confunction with the relevant datasheet
//https://www.dataman.com/media/datasheet/Spansion/AM29LV160M.pdf

//Memory calls in the range 0xFF000000 to 0xFFFFFFFF will be read from the LPC port flash rom
//if enabled during boot. (D0 held low) Otherwise from the TSOP flash memory on the motherboard.
//The CPLD on the Xenium will see these commands and read/write the flash chip as required.
//http://xboxdevwiki.net/Memory
static unsigned char LPCmemoryReadByte(unsigned long address){
unsigned char* lpc_mem_map = (unsigned char *)LPCFlashAddress;
return lpc_mem_map[address];
}

//Two successive LPC reads. DQ6 will toggle if still in progress
//Returns 1 if busy, 0 is not.
static unsigned char flashBusy(){
if(LPCmemoryReadByte(0x00)==LPCmemoryReadByte(0x00)){
return 0;
} else {
return 1;
}
return (LPCmemoryReadByte(0x00)!=LPCmemoryReadByte(0x00));
}

//memory calls in the range 0xFF000000 to 0xFFFFFFFF will be read from the LPC port flash rom
//if enabled during boot. (D0 held low) Otherwise from the TSOP flash memory on the motherboard.
//The CPLD on the Xenium will see these commands and read/write the flash chip as required.
//http://xboxdevwiki.net/Memory
unsigned char LPCmemoryReadByte(unsigned long address){
unsigned char rx[0];
memcpy(rx,(void*)(LPCFlashAddress + address), 1);
return rx[0];
static void flashReset() {
LPCmemoryWrite(0x000, 0xF0);
}

void LPCmemoryRead(unsigned char* rxbuff, unsigned long address, unsigned long len){
memcpy(rxbuff,(void*)(LPCFlashAddress + address), len);
}

void LPCmemoryWrite(unsigned long address, unsigned char data) {
memcpy((void*)(LPCFlashAddress + address),&data, 1);
}

void flashSectorErase(unsigned char sector) {
//Sector address should fall in the sector you want to erase.
void flashSectorErase(unsigned long sector_address) {
LPCmemoryWrite(0xAAA, 0xAA);
LPCmemoryWrite(0x555, 0x55);
LPCmemoryWrite(0xAAA, 0x80);
LPCmemoryWrite(0xAAA, 0xAA);
LPCmemoryWrite(0x555, 0x55);

unsigned long SA;

if(sector<=30){
sector=sector<<3;
SA=((unsigned long)sector)<<12;
}
else if(sector == 31){
sector = 0b11111000;
SA=((unsigned long)sector)<<12;
}
else if (sector == 32){
sector = 0b11111100;
SA=((unsigned long)sector)<<12;
}
else if (sector == 33){
sector = 0b11111101;
SA=((unsigned long)sector)<<12;
}
else if (sector == 34){
sector = 0b11111110;
SA=((unsigned long)sector)<<12;
} else {
return;
}

LPCmemoryWrite(SA, 0x30);
LPCmemoryWrite(sector_address, 0x30);
while(flashBusy());
}

void flashFullErase() {
LPCmemoryWrite(0xAAAA, 0xAA);
LPCmemoryWrite(0x5555, 0x55);
LPCmemoryWrite(0xAAAA, 0x80);
LPCmemoryWrite(0xAAAA, 0xAA);
LPCmemoryWrite(0x5555, 0x55);
LPCmemoryWrite(0xAAAA, 0x10);
while(flashBusy()){
Sleep(500);
}
}

void flashReset() {
LPCmemoryWrite(0x000, 0xF0);
}


/*
* The next three functions are used together.
* flashProgramUnlock unlocks to chip ready for writing
* flashProgramBypass writes to the chip after its unlocked
* flashProgramLock relocks the memory chip
*/
void flashProgramUnlock() {
LPCmemoryWrite(0xAAA, 0xAA);
LPCmemoryWrite(0x555, 0x55);
LPCmemoryWrite(0xAAA, 0x20);
}
void flashProgramBypass(unsigned long startAddress, unsigned char* data, unsigned long len) {
for (unsigned long i = 0; i < len; i++) {
LPCmemoryWrite(0x001, 0xA0);
LPCmemoryWrite(startAddress++, data[i]);
while(flashBusy());
LPCmemoryWrite(0xAAA, 0x80);
LPCmemoryWrite(0xAAA, 0xAA);
LPCmemoryWrite(0x555, 0x55);
LPCmemoryWrite(0xAAA, 0x10);
while(flashBusy()){
Sleep(500);
}

}
void flashProgramLock() {
LPCmemoryWrite(0x000, 0x90);
LPCmemoryWrite(0x000, 0x00);
while(flashBusy());
}


//Writes a single byte to a previously erased section.
//This function can be sent in isolated provided the byte as already been erased.
void flashProgramByte(unsigned long address, unsigned char data) {
Expand All @@ -138,7 +83,6 @@ void flashProgramByte(unsigned long address, unsigned char data) {
while(flashBusy());
}


unsigned char getManufID() {
unsigned char manuf;
LPCmemoryWrite(0xAAA, 0xAA);
Expand All @@ -149,7 +93,6 @@ unsigned char getManufID() {
return manuf;
}


//Returns the deviceID of the flash memory chip
//Some memory devices has the deviceID located
//at address 1. So if the read fails I try at address 1 instead
Expand All @@ -159,18 +102,7 @@ unsigned char getDevID() {
LPCmemoryWrite(0x555, 0x55);
LPCmemoryWrite(0xAAA, 0x90);
devID = LPCmemoryReadByte(0x02);
LPCmemoryReadByte(0x02);
LPCmemoryReadByte(0x02);
flashReset();
if(devID != XENIUM_DEVICE_ID){
LPCmemoryWrite(0xAAA, 0xAA);
LPCmemoryWrite(0x555, 0x55);
LPCmemoryWrite(0xAAA, 0x90);
devID = LPCmemoryReadByte(0x01);
LPCmemoryReadByte(0x01);
LPCmemoryReadByte(0x01);
flashReset();
}
return devID;
}

Expand Down
7 changes: 1 addition & 6 deletions Xenium-Tools/am29lv160mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@

#define LPCFlashAddress 0xFF000000u

unsigned char LPCmemoryReadByte(unsigned long address);
void LPCmemoryRead(unsigned char* rxbuff, unsigned long address, unsigned long len);
void LPCmemoryWrite(unsigned long address, unsigned char data);
void flashSectorErase(unsigned char sector);
void flashSectorErase(unsigned long sector_address);
void flashFullErase(void);
void flashReset(void);
void flashProgramUnlock(void);
void flashProgramBypass(unsigned long startAddress, unsigned char* data, unsigned long len);
void flashProgramLock(void);
void flashProgramByte(unsigned long address, unsigned char data);
unsigned char getManufID(void);
unsigned char getDevID(void);
Binary file modified Xenium-Tools/bin/default.xbe
Binary file not shown.
Loading

0 comments on commit 44d2526

Please sign in to comment.