mirror of https://github.com/zeldaret/mm.git
osFlash (#158)
* some matches * Decompile code_0x80186A70 Add defines for KSEG0/1 and (Un)Cached RDRAM * format * cleanup * moved osFlash and imported data * implement fixes * format again * Update include/functions.h Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> * Update include/variables.h Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> * Update src/libultra/flash/osFlash.c Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> * Update src/libultra/flash/osFlash.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * returns are needed * format * Update src/libultra/flash/osFlash.c Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> * Update src/libultra/flash/osFlash.c Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> * Update src/libultra/flash/osFlash.c Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> * Update src/libultra/flash/osFlash.c Co-authored-by: Kenix3 <kenixwhisperwind@gmail.com> * Update src/libultra/flash/osFlash.c Co-authored-by: Kenix3 <kenixwhisperwind@gmail.com> * Update src/libultra/flash/osFlash.c Co-authored-by: Kenix3 <kenixwhisperwind@gmail.com> * should be fixed Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain> Co-authored-by: MMDecomp <mmdecomp@gmail.com> Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> Co-authored-by: Kenix3 <kenixwhisperwind@gmail.com>
This commit is contained in:
parent
78153a1bf4
commit
ad4c16d40f
2
Makefile
2
Makefile
|
@ -153,6 +153,8 @@ build/src/libultra/io/%.o: OPTFLAGS := -O2
|
|||
build/src/libultra/libc/%.o: OPTFLAGS := -O2
|
||||
build/src/libultra/gu/%.o: OPTFLAGS := -O2
|
||||
build/src/libultra/rmon/%.o: OPTFLAGS := -O2
|
||||
build/src/libultra/flash/%.o: OPTFLAGS := -g
|
||||
build/src/libultra/flash/%.o: MIPS_VERSION := -mips1
|
||||
|
||||
# file flags
|
||||
build/src/boot_O2_g3/fault.o: CFLAGS += -trapuv
|
||||
|
|
|
@ -416,7 +416,7 @@ void __osViInit(void);
|
|||
void __osViSwapContext(void);
|
||||
OSMesgQueue* osPiGetCmdQueue(void);
|
||||
f32 __cosf(f32 __x);
|
||||
// void osEPiReadIo(void);
|
||||
s32 osEPiReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data);
|
||||
void osViSetSpecialFeatures(u32 func);
|
||||
s16 coss(u16 x);
|
||||
void osSetTime(OSTime ticks);
|
||||
|
@ -439,7 +439,7 @@ u32 __osGetFpcCsr(void);
|
|||
// void corrupted_init(void);
|
||||
// void corrupted(void);
|
||||
u32 osAiGetLength(void);
|
||||
// void osEPiWriteIo(void);
|
||||
s32 osEPiWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data);
|
||||
void osMapTLBRdb(void);
|
||||
void osYieldThread(void);
|
||||
// void guTranslate(void);
|
||||
|
@ -3494,19 +3494,21 @@ void SysFlashrom_ThreadEntry(s80185D40* param_1);
|
|||
// void func_80185F04(void);
|
||||
// void func_80185F64(void);
|
||||
s32 func_80185F90(u32 param_1);
|
||||
// void func_80186A70(void);
|
||||
// void func_80186B78(void);
|
||||
// void func_80186CAC(void);
|
||||
// void func_80186D60(void);
|
||||
// void func_80186E64(void);
|
||||
// void func_80186EC8(void);
|
||||
// void func_80187018(void);
|
||||
// void func_80187080(void);
|
||||
// void func_80187124(void);
|
||||
// void func_80187284(void);
|
||||
// void func_801872FC(void);
|
||||
// void func_801873BC(void);
|
||||
// void func_8018752C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6);
|
||||
u32 osFlashGetAddr(u32 pageNum);
|
||||
OSPiHandle* osFlashReInit(u8 latency, u8 pulse, u8 pageSize, u8 relDuration, u32 start);
|
||||
void osFlashChange(u32 flashNum);
|
||||
OSPiHandle* osFlashInit(void);
|
||||
void osFlashReadStatus(u8* flashStatus);
|
||||
void osFlashReadId(u32* flashType, u32* flashVendor);
|
||||
void osFlashClearStatus(void);
|
||||
s32 osFlashAllErase(void);
|
||||
void osFlashAllEraseThrough(void);
|
||||
s32 osFlashCheckEraseEnd(void);
|
||||
s32 osFlashSectorErase(u32 pageNum);
|
||||
void osFlashSectorEraseThrough(u32 pageNum);
|
||||
s32 osFlashWriteBuffer(OSIoMesg* mb, s32 priority, void* dramAddr, OSMesgQueue* mq);
|
||||
s32 osFlashWriteArray(u32 pageNum);
|
||||
s32 osFlashReadArray(OSIoMesg* mb, s32 priority, u32 pageNum, void* dramAddr, u32 pageCount, OSMesgQueue* mq);
|
||||
// void func_801877D0(void);
|
||||
// void func_80187B64(void);
|
||||
// void func_80187BEC(void);
|
||||
|
|
|
@ -8,13 +8,10 @@
|
|||
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
||||
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
#define HW_REG(reg, type) *(volatile type*)((reg) | 0xa0000000)
|
||||
|
||||
// TODO: After uintptr_t cast change should have an AVOID_UB target that just toggles the KSEG0 bit in the address
|
||||
// rather than add/sub 0x80000000
|
||||
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) + 0x80000000)
|
||||
#define PHYSICAL_TO_VIRTUAL2(addr) ((uintptr_t)(addr)-0x80000000)
|
||||
#define VIRTUAL_TO_PHYSICAL(addr) (uintptr_t)((u8*)(addr)-0x80000000)
|
||||
// TODO: After uintptr_t cast change should have an AVOID_UB target that just toggles the KSEG0 bit in the address rather than add/sub 0x80000000
|
||||
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) + RDRAM_CACHED)
|
||||
#define PHYSICAL_TO_VIRTUAL2(addr) ((uintptr_t)(addr) - RDRAM_CACHED)
|
||||
#define VIRTUAL_TO_PHYSICAL(addr) (uintptr_t)((u8*)(addr) - RDRAM_CACHED)
|
||||
#define SEGMENTED_TO_VIRTUAL(addr) (void*)(PHYSICAL_TO_VIRTUAL(gSegments[SEGMENT_NUMBER(addr)]) + SEGMENT_OFFSET(addr))
|
||||
|
||||
#define GET_ACTIVE_CAM(globalCtx) ((globalCtx)->cameraPtrs[(globalCtx)->activeCamera])
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
#ifndef _ULTRA64_HARDWARE_H_
|
||||
#define _ULTRA64_HARDWARE_H_
|
||||
|
||||
#define HW_REG(reg, type) *(volatile type*)((reg) | 0xa0000000)
|
||||
// Segment Wrapper
|
||||
// Uncached RDRAM
|
||||
#define KSEG1 0xA0000000 // 0xA0000000 - 0xBFFFFFFF Physical memory, uncached, unmapped
|
||||
#define RDRAM_UNCACHED KSEG1
|
||||
|
||||
// Cached RDRAM
|
||||
#define KSEG0 0x80000000 // 0x80000000 - 0x9FFFFFFF Physical memory, cached, unmapped
|
||||
#define RDRAM_CACHED KSEG0
|
||||
|
||||
// Volatile access wrapper, enforcing uncached memory
|
||||
#define HW_REG(reg, type) *(volatile type*)((reg) | KSEG1)
|
||||
|
||||
#define AI_DRAM_ADDR_REG 0x04500000
|
||||
#define AI_LEN_REG 0x04500004
|
||||
|
|
|
@ -3538,12 +3538,6 @@ extern StackEntry sys_flashromStackEntry;
|
|||
extern OSThread sys_flashromOSThread;
|
||||
extern s80185D40 D_801FD008;
|
||||
extern OSMesg D_801FD034;
|
||||
// extern UNK_TYPE1 D_801FD040;
|
||||
extern OSIoMesg D_801FD050;
|
||||
extern OSMesgQueue D_801FD068;
|
||||
extern OSPiHandle D_801FD080;
|
||||
// extern UNK_TYPE1 D_801FD0F4;
|
||||
// extern UNK_TYPE1 D_801FD0F8;
|
||||
// extern UNK_TYPE1 D_801FD120;
|
||||
// extern UNK_TYPE1 D_801FD140;
|
||||
// extern UNK_TYPE1 D_801FD158;
|
||||
|
|
|
@ -1694,4 +1694,43 @@ typedef struct {
|
|||
/* 0x04 */ const char* name;
|
||||
} FlagSetEntry; // size = 0x08
|
||||
|
||||
// TODO: Dedicated Header?
|
||||
#define FRAM_BASE_ADDRESS 0x08000000 // FRAM Base Address in Cart Memory
|
||||
#define FRAM_STATUS_REGISTER FRAM_BASE_ADDRESS // FRAM Base Address in Cart Memory
|
||||
#define FRAM_COMMAND_REGISTER 0x10000 // Located at 0x08010000 on the Cart
|
||||
|
||||
enum fram_command {
|
||||
/* Does nothing for FRAM_COMMAND_SET_MODE_READ_AND_STATUS, FRAM_MODE_NOP, FRAM_COMMAND_SET_MODE_STATUS_AND_STATUS
|
||||
Initializes fram to 0xFF in FRAM_MODE_ERASE
|
||||
Writes Contents in FLASHRAM_MODE_WRITE
|
||||
After execution, sets FRAM_MODE to FRAM_MODE_NOP */
|
||||
FRAM_COMMAND_EXECUTE = 0xD2000000,
|
||||
/* flashram->erase_offset = (command & 0xffff) * 128; */
|
||||
FRAM_COMMAND_SET_ERASE_SECTOR_OFFSET = 0x4B000000,
|
||||
/* flashram->mode = FLASHRAM_MODE_ERASE;
|
||||
flashram->status = 0x1111800800c20000LL; */
|
||||
FRAM_COMMAND_SET_MODE_ERASE_AND_STATUS = 0x78000000,
|
||||
/* flashram->erase_offset = (command & 0xffff) * 128;
|
||||
flashram->status = 0x1111800400c20000LL; */
|
||||
FRAM_COMMAND_SET_ERASE_SECTOR_OFFSET_AND_STATUS = 0xA5000000,
|
||||
/* flashram->mode = FLASHRAM_MODE_WRITE; */
|
||||
FRAM_COMMAND_SET_MODE_WRITE = 0xB4000000,
|
||||
/* flashram->mode = FLASHRAM_MODE_STATUS;
|
||||
flashram->status = 0x1111800100c20000LL; */
|
||||
FRAM_COMMAND_SET_MODE_STATUS_AND_STATUS = 0xE1000000,
|
||||
/* flashram->mode = FLASHRAM_MODE_READ;
|
||||
flashram->status = 0x11118004f0000000LL; */
|
||||
FRAM_COMMAND_SET_MODE_READ_AND_STATUS = 0xF0000000,
|
||||
/* unk */
|
||||
FRAM_COMMAND_UNK_ERASE_OPERATION = 0x3C000000
|
||||
};
|
||||
|
||||
enum fram_mode {
|
||||
FRAM_MODE_NOP = 0,
|
||||
FRAM_MODE_ERASE,
|
||||
FRAM_MODE_WRITE,
|
||||
FRAM_MODE_READ,
|
||||
FRAM_MODE_STATUS
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
3
spec
3
spec
|
@ -638,8 +638,7 @@ beginseg
|
|||
include "build/src/code/sys_flashrom.o"
|
||||
include "build/data/code/sys_flashrom.bss.o"
|
||||
include "build/asm/code/code_80185F90.text.o" // handwritten
|
||||
include "build/src/code/osFlash.o"
|
||||
include "build/data/code/osFlash.bss.o"
|
||||
include "build/src/libultra/flash/osFlash.o"
|
||||
pad_text
|
||||
pad_text
|
||||
pad_text
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186A70.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186AB8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186B28.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186B30.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186B38.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186B68.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186B70.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186B78.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186CAC.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186D60.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186E64.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80186EC8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80187018.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80187080.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80187124.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_80187284.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_801872FC.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_801873BC.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/osFlash/func_8018752C.s")
|
|
@ -0,0 +1,325 @@
|
|||
#include "ultra64.h"
|
||||
#include "global.h"
|
||||
|
||||
static s32 framDeviceInfo[4];
|
||||
static OSIoMesg framDeviceInfoQuery;
|
||||
static OSMesgQueue __osFlashMessageQ;
|
||||
static OSPiHandle __osFlashHandler;
|
||||
static OSMesg __osFlashMsgBuf;
|
||||
static s32 __osFlashVersion;
|
||||
static UNK_TYPE1 D_801FD0FC[0x14];
|
||||
|
||||
typedef enum {
|
||||
FLASH_OLD,
|
||||
FLASH_NEW,
|
||||
} FlashVersion;
|
||||
|
||||
u32 osFlashGetAddr(u32 pageNum) {
|
||||
s32 addr = (__osFlashVersion == FLASH_OLD) ? pageNum << 6 : pageNum << 7;
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
OSPiHandle* osFlashReInit(u8 latency, u8 pulse, u8 pageSize, u8 relDuration, u32 start) {
|
||||
__osFlashHandler.baseAddress = RDRAM_UNCACHED | start;
|
||||
__osFlashHandler.type++;
|
||||
__osFlashHandler.latency = latency;
|
||||
__osFlashHandler.pulse = pulse;
|
||||
__osFlashHandler.pageSize = pageSize;
|
||||
__osFlashHandler.relDuration = relDuration;
|
||||
__osFlashHandler.domain = 1;
|
||||
|
||||
return &__osFlashHandler;
|
||||
}
|
||||
|
||||
void osFlashChange(u32 flash_num) {
|
||||
__osFlashHandler.baseAddress = RDRAM_UNCACHED | (FRAM_STATUS_REGISTER + (flash_num << 17));
|
||||
__osFlashHandler.type = 8 + flash_num;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
OSPiHandle* osFlashInit(void) {
|
||||
u32 flashType;
|
||||
u32 flashVendor;
|
||||
|
||||
osCreateMesgQueue(&__osFlashMessageQ, &__osFlashMsgBuf, 1);
|
||||
|
||||
if (__osFlashHandler.baseAddress == (RDRAM_UNCACHED | FRAM_BASE_ADDRESS)) {
|
||||
return &__osFlashHandler;
|
||||
}
|
||||
|
||||
__osFlashHandler.type = 8;
|
||||
__osFlashHandler.baseAddress = (RDRAM_UNCACHED | FRAM_BASE_ADDRESS);
|
||||
__osFlashHandler.latency = 5;
|
||||
__osFlashHandler.pulse = 12;
|
||||
__osFlashHandler.pageSize = 15;
|
||||
__osFlashHandler.relDuration = 2;
|
||||
__osFlashHandler.domain = 1;
|
||||
__osFlashHandler.speed = 0;
|
||||
bzero(&__osFlashHandler.transferInfo, sizeof(__OSTranxInfo));
|
||||
|
||||
osEPiLinkHandle(&__osFlashHandler);
|
||||
osFlashReadId(&flashType, &flashVendor);
|
||||
|
||||
if (flashVendor == 0x00C2001E || flashVendor == 0x00C20001 || flashVendor == 0x00C20000) {
|
||||
__osFlashVersion = FLASH_OLD;
|
||||
} else {
|
||||
__osFlashVersion = FLASH_NEW;
|
||||
}
|
||||
|
||||
return &__osFlashHandler;
|
||||
}
|
||||
|
||||
void osFlashReadStatus(u8* flashStatus) {
|
||||
u32 outFlashStatus;
|
||||
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER, FRAM_COMMAND_EXECUTE);
|
||||
// read status using IO
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &outFlashStatus);
|
||||
|
||||
// why twice ?
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER, FRAM_COMMAND_EXECUTE);
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &outFlashStatus);
|
||||
|
||||
*flashStatus = outFlashStatus & 0xFF;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void osFlashReadId(u32* flashType, u32* flashVendor) {
|
||||
u8 flashStatus;
|
||||
|
||||
// why read status?
|
||||
osFlashReadStatus(&flashStatus);
|
||||
|
||||
// select silicon id read mode
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_MODE_STATUS_AND_STATUS);
|
||||
|
||||
// read silicon id using DMA
|
||||
framDeviceInfoQuery.hdr.pri = 0;
|
||||
framDeviceInfoQuery.hdr.retQueue = &__osFlashMessageQ;
|
||||
framDeviceInfoQuery.dramAddr = framDeviceInfo;
|
||||
framDeviceInfoQuery.devAddr = 0;
|
||||
framDeviceInfoQuery.size = 8;
|
||||
|
||||
osInvalDCache(framDeviceInfo, sizeof(framDeviceInfo));
|
||||
osEPiStartDma(&__osFlashHandler, &framDeviceInfoQuery, OS_READ);
|
||||
osRecvMesg(&__osFlashMessageQ, NULL, OS_MESG_BLOCK);
|
||||
|
||||
*flashType = framDeviceInfo[0];
|
||||
*flashVendor = framDeviceInfo[1];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void osFlashClearStatus(void) {
|
||||
// select status mode
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER, FRAM_COMMAND_EXECUTE);
|
||||
// clear status
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
s32 osFlashAllErase(void) {
|
||||
u32 status;
|
||||
OSTimer timer;
|
||||
OSMesgQueue mq;
|
||||
OSMesg msg;
|
||||
|
||||
// start chip erase operation
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_UNK_ERASE_OPERATION);
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_MODE_ERASE_AND_STATUS);
|
||||
|
||||
// wait for completion by polling erase-busy flag
|
||||
osCreateMesgQueue(&mq, &msg, 1);
|
||||
do {
|
||||
osSetTimer(&timer, OS_USEC_TO_CYCLES(15000), 0, &mq, &msg);
|
||||
osRecvMesg(&mq, &msg, OS_MESG_BLOCK);
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status);
|
||||
} while ((status & 2) == 2);
|
||||
|
||||
// check erase operation status, clear status
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status);
|
||||
osFlashClearStatus();
|
||||
|
||||
if (((status & 0xFF) == 0x08) || ((status & 0xFF) == 0x48) || ((status & 0x08) == 0x08)) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void osFlashAllEraseThrough(void) {
|
||||
// start chip erase operation
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_UNK_ERASE_OPERATION);
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_MODE_ERASE_AND_STATUS);
|
||||
}
|
||||
|
||||
s32 osFlashCheckEraseEnd(void) {
|
||||
u8 status;
|
||||
|
||||
// check if erase operation is completed
|
||||
osFlashReadStatus(&status);
|
||||
if ((status & 0x02) == 0x02) {
|
||||
return 2; // busy
|
||||
} else {
|
||||
// check erase operation status, clear status
|
||||
osFlashReadStatus(&status);
|
||||
}
|
||||
osFlashClearStatus();
|
||||
|
||||
if (((status & 0xFF) == 0x08) || ((status & 0xFF) == 0x48) || ((status & 0x08) == 0x08)) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
s32 osFlashSectorErase(u32 pageNum) {
|
||||
u32 status;
|
||||
OSTimer timer;
|
||||
OSMesgQueue mq;
|
||||
OSMesg msg;
|
||||
|
||||
// start sector erase operation
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_ERASE_SECTOR_OFFSET | pageNum);
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_MODE_ERASE_AND_STATUS);
|
||||
|
||||
// wait for completion by polling erase-busy flag
|
||||
osCreateMesgQueue(&mq, &msg, 1);
|
||||
do {
|
||||
osSetTimer(&timer, OS_USEC_TO_CYCLES(12500), 0, &mq, &msg);
|
||||
osRecvMesg(&mq, &msg, OS_MESG_BLOCK);
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status);
|
||||
} while ((status & 2) == 2);
|
||||
|
||||
// check erase operation status, clear status
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status);
|
||||
osFlashClearStatus();
|
||||
|
||||
if (((status & 0xFF) == 0x08) || ((status & 0xFF) == 0x48) || ((status & 0x08) == 0x08)) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void osFlashSectorEraseThrough(u32 pageNum) {
|
||||
// start sector erase operation
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_ERASE_SECTOR_OFFSET | pageNum);
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_MODE_ERASE_AND_STATUS);
|
||||
}
|
||||
|
||||
s32 osFlashWriteBuffer(OSIoMesg* mb, s32 priority, void* dramAddr, OSMesgQueue* mq) {
|
||||
s32 ret;
|
||||
|
||||
// select load page mode
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER, FRAM_COMMAND_SET_MODE_WRITE);
|
||||
|
||||
// DMA 128-byte page
|
||||
mb->hdr.pri = priority;
|
||||
mb->hdr.retQueue = mq;
|
||||
mb->dramAddr = dramAddr;
|
||||
mb->devAddr = 0;
|
||||
mb->size = 0x80;
|
||||
|
||||
ret = osEPiStartDma(&__osFlashHandler, mb, OS_WRITE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 osFlashWriteArray(u32 pageNum) {
|
||||
u32 status;
|
||||
OSTimer timer;
|
||||
OSMesgQueue mq;
|
||||
OSMesg msg;
|
||||
|
||||
// only needed for new flash ?
|
||||
if (__osFlashVersion == FLASH_NEW) {
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_MODE_WRITE);
|
||||
}
|
||||
|
||||
// start program page operation
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_ERASE_SECTOR_OFFSET_AND_STATUS | pageNum);
|
||||
|
||||
// wait for completion by polling write-busy flag
|
||||
osCreateMesgQueue(&mq, &msg, 1);
|
||||
do {
|
||||
osSetTimer(&timer, OS_USEC_TO_CYCLES(200), 0, &mq, &msg);
|
||||
osRecvMesg(&mq, &msg, OS_MESG_BLOCK);
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status);
|
||||
} while ((status & 0x01) == 0x01);
|
||||
|
||||
// check program operation status, clear status
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &status);
|
||||
osFlashClearStatus();
|
||||
|
||||
if (((status & 0xFF) == 0x04) || ((status & 0xFF) == 0x44) || ((status & 0x04) == 0x04)) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
s32 osFlashReadArray(OSIoMesg* mb, s32 priority, u32 pageNum, void* dramAddr, u32 pageCount, OSMesgQueue* mq) {
|
||||
s32 ret;
|
||||
u32 dummy;
|
||||
u32 last_page;
|
||||
u32 pages;
|
||||
|
||||
// select read array mode
|
||||
osEPiWriteIo(&__osFlashHandler, __osFlashHandler.baseAddress | FRAM_COMMAND_REGISTER,
|
||||
FRAM_COMMAND_SET_MODE_READ_AND_STATUS);
|
||||
|
||||
// dummy read to initiate "fast-page" reads ?
|
||||
osEPiReadIo(&__osFlashHandler, __osFlashHandler.baseAddress, &dummy);
|
||||
|
||||
// DMA requested pages
|
||||
mb->hdr.pri = priority;
|
||||
mb->hdr.retQueue = mq;
|
||||
mb->dramAddr = dramAddr;
|
||||
|
||||
last_page = pageNum + pageCount - 1;
|
||||
|
||||
if ((last_page & 0xF00) != (pageNum & 0xF00)) {
|
||||
|
||||
pages = 256 - (pageNum & 0xFF);
|
||||
pageCount -= pages;
|
||||
mb->size = pages << 7;
|
||||
mb->devAddr = osFlashGetAddr(pageNum);
|
||||
osEPiStartDma(&__osFlashHandler, mb, OS_READ);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
pageNum = (pageNum + 256) & 0xF00;
|
||||
mb->dramAddr = (void*)((uintptr_t)mb->dramAddr + mb->size);
|
||||
}
|
||||
|
||||
while (pageCount > 256) {
|
||||
pages = 256;
|
||||
pageCount -= 256;
|
||||
mb->size = pages << 7;
|
||||
mb->devAddr = osFlashGetAddr(pageNum);
|
||||
osEPiStartDma(&__osFlashHandler, mb, OS_READ);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
pageNum += 256;
|
||||
mb->dramAddr = (void*)((uintptr_t)mb->dramAddr + mb->size);
|
||||
}
|
||||
|
||||
mb->size = pageCount << 7;
|
||||
mb->devAddr = osFlashGetAddr(pageNum);
|
||||
ret = osEPiStartDma(&__osFlashHandler, mb, OS_READ);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -3463,25 +3463,21 @@
|
|||
0x80185F04:("func_80185F04",),
|
||||
0x80185F64:("func_80185F64",),
|
||||
0x80185F90:("func_80185F90",),
|
||||
0x80186A70:("func_80186A70",),
|
||||
0x80186AB8:("func_80186AB8",),
|
||||
0x80186B28:("func_80186B28",),
|
||||
0x80186B30:("func_80186B30",),
|
||||
0x80186B38:("func_80186B38",),
|
||||
0x80186B68:("func_80186B68",),
|
||||
0x80186B70:("func_80186B70",),
|
||||
0x80186B78:("func_80186B78",),
|
||||
0x80186CAC:("func_80186CAC",),
|
||||
0x80186D60:("func_80186D60",),
|
||||
0x80186E64:("func_80186E64",),
|
||||
0x80186EC8:("func_80186EC8",),
|
||||
0x80187018:("func_80187018",),
|
||||
0x80187080:("func_80187080",),
|
||||
0x80187124:("func_80187124",),
|
||||
0x80187284:("func_80187284",),
|
||||
0x801872FC:("func_801872FC",),
|
||||
0x801873BC:("func_801873BC",),
|
||||
0x8018752C:("func_8018752C",),
|
||||
0x80186A70:("osFlashGetAddr",),
|
||||
0x80186AB8:("osFlashReInit",),
|
||||
0x80186B38:("osFlashChange",),
|
||||
0x80186B78:("osFlashInit",),
|
||||
0x80186CAC:("osFlashReadStatus",),
|
||||
0x80186D60:("osFlashReadId",),
|
||||
0x80186E64:("osFlashClearStatus",),
|
||||
0x80186EC8:("osFlashAllErase",),
|
||||
0x80187018:("osFlashAllEraseThrough",),
|
||||
0x80187080:("osFlashCheckEraseEnd",),
|
||||
0x80187124:("osFlashSectorErase",),
|
||||
0x80187284:("osFlashSectorEraseThrough",),
|
||||
0x801872FC:("osFlashWriteBuffer",),
|
||||
0x801873BC:("osFlashWriteArray",),
|
||||
0x8018752C:("osFlashReadArray",),
|
||||
0x801877D0:("func_801877D0",),
|
||||
0x80187B64:("func_80187B64",),
|
||||
0x80187BEC:("func_80187BEC",),
|
||||
|
|
|
@ -364,7 +364,7 @@
|
|||
0x8009F888:("viCounterMsg","OSIoMesg","",0x18),
|
||||
0x8009F8A0:("viRetrace","u16","",0x2),
|
||||
0x8009F8B0:("dmadata","DmaEntry","[1568]",0x6200),
|
||||
0x80186028:("D_80186028","UNK_TYPE1","",0x1),
|
||||
0x80186028:("D_80186028","s16","[1316]",0xa48),
|
||||
0x801AAAB0:("D_801AAAB0","UNK_TYPE1","",0x1),
|
||||
0x801ABAB0:("D_801ABAB0","UNK_TYPE1","",0x1),
|
||||
0x801AD370:("D_801AD370","UNK_TYPE1","",0x1),
|
||||
|
@ -4327,12 +4327,12 @@
|
|||
0x801FCE58:("sys_flashromOSThread","OSThread","",0x1b0),
|
||||
0x801FD008:("D_801FD008","s80185D40","",0x2c),
|
||||
0x801FD034:("D_801FD034","OSMesg","",0x4),
|
||||
0x801FD040:("D_801FD040","UNK_TYPE1","",0x1),
|
||||
0x801FD040:("D_801FD040","s32","",0x10),
|
||||
0x801FD050:("D_801FD050","OSIoMesg","",0x18),
|
||||
0x801FD068:("D_801FD068","OSMesgQueue","",0x18),
|
||||
0x801FD080:("D_801FD080","OSPiHandle","",0x74),
|
||||
0x801FD0F4:("D_801FD0F4","UNK_TYPE1","",0x1),
|
||||
0x801FD0F8:("D_801FD0F8","UNK_TYPE1","",0x1),
|
||||
0x801FD068:("__osFlashMessageQ","OSMesgQueue","",0x18),
|
||||
0x801FD080:("__osFlashHandler","OSPiHandle","",0x74),
|
||||
0x801FD0F4:("__osFlashMsgBuf","OSMesg","",0x4),
|
||||
0x801FD0F8:("__osFlashVersion","u32","",0x4),
|
||||
0x801FD120:("D_801FD120","UNK_TYPE1","",0x1),
|
||||
0x801FD140:("D_801FD140","UNK_TYPE1","",0x1),
|
||||
0x801FD158:("D_801FD158","UNK_TYPE1","",0x1),
|
||||
|
|
Loading…
Reference in New Issue