DSPRelated.com
Forums

c5402 DSK flashu utility bug

Started by wavetrain3000 July 27, 2002
I'm using the flashu utility with the c5402 DSK, and it's
not programming the entire .hex file properly. The .hex file
has about 16658 words (map below), but after running flashu
the first 14246 words are properly programmed, followed by
several words of 0, then the rest of the flash part is still
uninitialized.

This was all working fine until I split off the ".external"
since the codebase didn't fit in internal ram anymore, and it
works if I delete some code from the other sections to make it
all smaller. But the complete .hex file always gets truncated,
and not on any natural boundary like 16k, either.

This is using CCS 1.2, and flashu rev 0.

Does anyone have a newer version of flashu, or any other
suggestion before I write my own flash programmer? Thanks

Ken Sinclair
Wavetrain - Wireless computing and embedded system development

CONTENTS: 00008000..0000c112 BOOT TABLE
.vectors : dest000300 size000078
width000002
.text : dest000380 size0023c4
width000002
.cinit : dest002744 size000114
width000002
.const : dest003192 size000dab
width000002
.external : dest004000 size000e03
width000002



Hi Ken,

Even if the flashu can write the entire HEX image in
the flash, you may found that the onchip BOOT program
cannot copy data to external memory in the DSK5402.
This is due to the fact that external memory access is
disabled during flash access in the DSK5402.

-----
Ben
--- wavetrain3000 <> wrote:
> I'm using the flashu utility with the c5402 DSK, and
> it's
> not programming the entire .hex file properly. The
> .hex file
> has about 16658 words (map below), but after running
> flashu
> the first 14246 words are properly programmed,
> followed by
> several words of 0, then the rest of the flash part
> is still
> uninitialized.
>
> This was all working fine until I split off the
> ".external"
> since the codebase didn't fit in internal ram
> anymore, and it
> works if I delete some code from the other sections
> to make it
> all smaller. But the complete .hex file always gets
> truncated,
> and not on any natural boundary like 16k, either.
>
> This is using CCS 1.2, and flashu rev 0.
>
> Does anyone have a newer version of flashu, or any
> other
> suggestion before I write my own flash programmer?
> Thanks
>
> Ken Sinclair
> Wavetrain - Wireless computing and embedded system
> development >
>
> CONTENTS: 00008000..0000c112 BOOT TABLE
> .vectors : dest000300
> size000078
> width000002
> .text : dest000380
> size0023c4
> width000002
> .cinit : dest002744
> size000114
> width000002
> .const : dest003192
> size000dab
> width000002
> .external : dest004000
> size000e03
> width000002 >
> _____________________________________
> Note: If you do a simple "reply" with your email
> client, only the author of this message will receive
> your answer. You need to do a "reply all" if you
> want your answer to be distributed to the entire
> group.
>
> _____________________________________
> About this discussion group:
>
> To Join: Send an email to > To Post: Send an email to
>
> To Leave: Send an email to > Archives: http://www.yahoogroups.com/group/c54x
>
> Other Groups: http://www.dsprelated.com > ">http://docs.yahoo.com/info/terms/


=====
___________________________________________________________
~ ~ _/_/_/_/ _/_/_/_/ _/_/ _/
. . _/ _/ _/ _/ _/ _/ Benjamin Chan
' _/_/_/ _/_/_/ _/ _/ _/ []
o _/ _/ _/ _/ _/_/
_/_/_/_/ _/_/_/_/ _/ _/

__________________________________________________




--- In c54x@y..., Benjamin Chan <benbencc@y...> wrote:
> Hi Ken,
>
> Even if the flashu can write the entire HEX image in
> the flash, you may found that the onchip BOOT program
> cannot copy data to external memory in the DSK5402.
> This is due to the fact that external memory access is
> disabled during flash access in the DSK5402.

Thanks, I dealt with that issue and the broken flashu utility
by writing DSP-side code to write the boot table to flash,
along with an image of external memory that gets restored
immediately after initialization.

I've included the code below, free of copyright, in hopes that
it saves somebody else some time. It's a bit specific to our
memory layout but should be adaptable.

Ken Sinclair
Wavetrain - Wireless computing and embedded system design
//// Flash boot image

/// The flash boot image consists of two pieces: one a conventional
boot table
/// containing an image of the DSP's internal memory, and one a
snapshot of
/// relevant external memory. At reset, the boot table is loaded by
the ROM
/// bootloader, to begin execution out of internal memory. After
initialization,
/// the external image is restored.
///
/// To save a flash boot image, load the DSP from CCS through the HPI
port,
/// then call flashSave();

enum {
// DSP internal registers (0x0000..0x0080) and stack
(0x0080..0x0300) are
// not included in the internal block. Everything else in the internal
// RAM (0x0300..0x4000) is saved in the flash boot table. The reset
// vector is at 0x0300, so that's where we start execution.
internalBlockStart = 0x0300,
internalBlockLength = 0x4000-internalBlockStart,
// The low external block is only used for program access, so all code
// storage and constants are there. The high block (0x8000..0xFFFF) is
// used for a dynamic heap, and not saved in the flash image.
externalBlockStart = 0x4000,
externalBlockLength = 0x4000
};

/// The internal bootable is stored in flash memory at index 0 (i.e.
page 0)
/// mapped to addresses 0x8000 at reset for access by the bootloader.
#define internalFlashBase 0
/// The external block image is stored in flash memory at index 65536
(i.e. page 2);
/// it could be anywhere that doesn't conflict with the internal bootable.
#define externalFlashBase 0x10000L

/// Save the entire contents of internal RAM, excluding only the
internal registers
/// and the stack, as a single-section boot table in the flash rom.
void flashSaveBootable() {
const unsigned int header[] =
{ 0x10AAu, // Denotes 16-bit boot table
0x7FFFu, // SWWSR contents
0x8806u, // BSCR contents
0, // (high word of start address)
internalBlockStart, // Low word of start address
internalBlockLength, // Block Length
0, // (high word of block address)
0x0300u // Low word of block address
};
const unsigned int last[] = { 0, 0, 0, 0 };
const unsigned int pointer[] = { 0x8000u };
trace(5, "Saving bootable...");
// Write 8 word header
flashWrite((int*)header, 8, 0);
// Write internal block
flashWrite((int*)internalBlockStart, internalBlockLength, 8);
// Write zero-length block to terminate boot table
flashWrite((int*)last, 4, internalBlockLength+8);
// Write pointer to beginning where bootloader expects it
flashWrite((int*)pointer, 1, 0x7FFFL);
}

void flashSaveExternal() {
int i;
enum { bufferLength = 64 };
int buffer[bufferLength];
assert(4, externalBlockLength % bufferLength == 0, "Nonintegral
buffer multiple");
trace(5, "Saving external memory image to flash...\n");
for (i = 0x0000; i < externalBlockLength; i += bufferLength) {
long flashIndex = externalFlashBase + i;
int extramIndex = externalBlockStart + i;
// Normally page 0 of external sram is only accessible in Program Space
// from 0x4000..0x7FFF, with page 1 mapped to Data Space from
0x8000..0xFFFF.
// Here we map page 0 to data space so we can read it.
port2 = 0x0;
copyMem((int *)extramIndex, bufferLength, buffer);
port2 = 0x1;
flashWrite(buffer, bufferLength, flashIndex);
}
}

void flashRestoreExternal() {
int i;
enum { bufferLength = 64 };
int buffer[bufferLength];
assert(4, externalBlockLength % bufferLength == 0, "Nonintegral
buffer multiple");
trace(5, "Restoring external memory image from flash...\n");
for (i = 0x0000; i < externalBlockLength; i += bufferLength) {
long flashIndex = externalFlashBase + i;
int extramIndex = externalBlockStart + i;
flashRead(buffer, bufferLength, flashIndex);
// Normally page 0 of external sram is only accessible in Program Space
// from 0x4000..0x7FFF, with page 1 mapped to Data Space from
0x8000..0xFFFF.
// Here we map page 0 to data space so we can write it.
port2 = 0x0;
copyMem(buffer, bufferLength, (int *)extramIndex);
port2 = 0x1;
}
}

/// 0 if external memory has not been restored from flash. This
starts out
/// true after the CCS environment loads the initial build (since it loads
/// external memory via the HPI port).
const int flashExternalRestored = 1;

void flashSave() {
if (flashExternalRestored == 0) {
trace(5, "External memory image not available\n");
} else {
flashErase();
*(int*)&flashExternalRestored = 0;
flashSaveBootable();
flashSaveExternal();
*(int*)&flashExternalRestored = 1;
}
}

void flashRestore() {
if (flashExternalRestored == 0) {
flashRestoreExternal();
*(int*)&flashExternalRestored = 1;
}
}