--- 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; } } |