Skip to content

Commit

Permalink
Combined and Booled Intel Flash Unlock/Lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gampyg28 committed May 20, 2020
1 parent 8c09dcf commit ba2b3ea
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 63 deletions.
4 changes: 2 additions & 2 deletions Kernels/Build.cmd
Expand Up @@ -128,10 +128,10 @@ call :Detrailslash "%GCC_LOCATION%" GCC_LOCATION
call :Detrailslash "%BIN_LOCATION%" BIN_LOCATION

rem *** All that for this ...
"%GCC_LOCATION%\m68k-elf-gcc.exe" -c -fomit-frame-pointer -std=gnu99 -mcpu=68332 -O0 main.c write-kernel.c crc.c common.c common-readwrite.c flash.c flash-intel.c flash-amd.c
"%GCC_LOCATION%\m68k-elf-gcc.exe" -c -fomit-frame-pointer -std=gnu99 -mcpu=68332 -O0 main.c write-kernel.c crc.c common.c common-readwrite.c flash-intel.c flash-amd.c
if %errorlevel% neq 0 goto :EOF

"%GCC_LOCATION%\m68k-elf-ld.exe" -Map kernel.map --section-start .kernel_code=0x%BASE_ADDRESS% -T kernel.ld main.o write-kernel.o crc.o common.o common-readwrite.o -o kernel.elf flash.o flash-intel.o flash-amd.o
"%GCC_LOCATION%\m68k-elf-ld.exe" -Map kernel.map --section-start .kernel_code=0x%BASE_ADDRESS% -T kernel.ld main.o write-kernel.o crc.o common.o common-readwrite.o -o kernel.elf flash-intel.o flash-amd.o
if %errorlevel% neq 0 goto :EOF

"%GCC_LOCATION%\m68k-elf-objcopy.exe" -O binary --only-section=.kernel_code --only-section=.rodata kernel.elf kernel.bin
Expand Down
4 changes: 4 additions & 0 deletions Kernels/common.h
Expand Up @@ -5,6 +5,10 @@
#define EXTERN extern
#endif

#define bool _Bool
#define true 1
#define false 0

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned uint32_t;
Expand Down
34 changes: 29 additions & 5 deletions Kernels/flash-intel.c
Expand Up @@ -5,6 +5,29 @@
#include "common.h"
#include "flash.h"

///////////////////////////////////////////////////////////////////////////////
// Unlock / Lock Intel flash memory.
///////////////////////////////////////////////////////////////////////////////
void FlashUnlock(bool unlock)
{
SIM_CSBARBT = 0x0007;
SIM_CSORBT = 0x6820;
SIM_CSBAR0 = 0x0007;

if(unlock)
{
// Unlock
SIM_CSOR0 = 0x7060;
HARDWARE_IO |= 0x0001;
}
else
{
// Lock
SIM_CSOR0 = 0x1060;
HARDWARE_IO &= 0xFFFE;
}
}

///////////////////////////////////////////////////////////////////////////////
// Get the manufacturer and type of flash chip.
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -37,7 +60,7 @@ uint8_t Intel_EraseBlock(uint32_t address)
{
unsigned short status = 0;

FlashUnlock();
FlashUnlock(true);

uint16_t *flashBase = (uint16_t*)address;
*flashBase = 0x5050; // TODO: Move these commands to defines
Expand All @@ -60,7 +83,7 @@ uint8_t Intel_EraseBlock(uint32_t address)
*flashBase = READ_ARRAY_COMMAND;
*flashBase = READ_ARRAY_COMMAND;

FlashLock();
FlashUnlock(false);

// Return zero if successful, anything else is an error code.
if (status == 0x80)
Expand All @@ -83,7 +106,7 @@ uint8_t Intel_WriteToFlash(unsigned int payloadLengthInBytes, unsigned int start

if (!testWrite)
{
FlashUnlock();
FlashUnlock(true);
}

unsigned short* payloadArray = (unsigned short*) payloadBytes;
Expand Down Expand Up @@ -132,7 +155,7 @@ uint8_t Intel_WriteToFlash(unsigned int payloadLengthInBytes, unsigned int start
{
*address = 0xFFFF;
*address = 0xFFFF;
FlashLock();
FlashUnlock(false);
}

return errorCode;
Expand All @@ -145,7 +168,7 @@ uint8_t Intel_WriteToFlash(unsigned int payloadLengthInBytes, unsigned int start
unsigned short* address = (unsigned short*)startAddress;
*address = 0xFFFF;
*address = 0xFFFF;
FlashLock();
FlashUnlock(false);
}

// Check the last value we got from the status register.
Expand All @@ -156,3 +179,4 @@ uint8_t Intel_WriteToFlash(unsigned int payloadLengthInBytes, unsigned int start

return errorCode;
}

53 changes: 0 additions & 53 deletions Kernels/flash.c

This file was deleted.

4 changes: 2 additions & 2 deletions Kernels/flash.h
Expand Up @@ -42,8 +42,8 @@ char volatile * const SIM_CSBAR6 = SIM_BASE + 0x64;
char volatile * const SIM_CSOR6 = SIM_BASE + 0x66;*/

// Lock and unlock refers to the internal +12v supply to the flash chip, needed for erasing and writing.
void FlashLock();
void FlashUnlock();
// true to unlock, false to lock.
void FlashUnlock(bool unlock);

// Functions prefixed with Intel512 work with this chip ID
#define FLASH_ID_INTEL_512 0x00894471
Expand Down
1 change: 0 additions & 1 deletion Kernels/kernel.ld
Expand Up @@ -12,7 +12,6 @@ SECTIONS
crc.o (.text)
common.o (.text)
common-readwrite.o (.text)
flash.o (.text)
flash-intel.o (.text)
flash-amd.o (.text)
}
Expand Down

0 comments on commit ba2b3ea

Please sign in to comment.