Other Parts Discussed in Thread: CCSTUDIO
Hi all,
I am having issues with creating a JavaScript DSS script that writes data directly to the internal flash memory of a TMS320F280049C. I am trying to write a debug script that will allow one to debug an application that executes after a bootloader. I am using a modified version of the F280049C flash kernel that TI provides, which uses a 'key' at the beginning of the application section of flash to indicate whether there is a valid application. I need to write this key manually in the DSS script, as this will be erased when the program is loaded into flash in the debug session.
The DSS script is attached below. After resetting, erasing, and loading a program, I attempt to write the key value manually to flash in lines 213 to 227. The default F280049C GEL script specifies the destination address as read-only, so the memory.map.add API call is used to indicate that we should have R/W permissions in the 0th internal flash bank (0x80000-0x8FFFF). We can successfully read the address 0x82004 as being empty (0xFFFF). However when trying to load data in from a binary file containing the hex value 0x5B5B using the memory.loadRaw call, I get the following error in the Rhino JS debugger:
loadRaw: ENTRY nPage: 1 nAddress: 0x82004 sFilename: data.txt nTypeSize: 16 bByteSwap: false
waitUntil: ENTRY timeout: infinite
SEVERE: C28xx_CPU1: Data verification failed at address 0x82004
I have not been able to figure out what the issue is. Clearly we are able to write data to flash in the memory.loadProgram call, but not using memory.loadRaw. I have been through the Data Verification Errors page, but this has not presented any solutions. I should note that the code security module has not been activated on the device, so we do not need a password to access the flash.
Performing the equivalent actions in CCS also does not work; modifying the GEL file to give the 0th flash bank write permissions and then using the memory browser to fill the address; this also produces a Data Verification failure.
The device under debug is a TMS320F280049C on a TI F280049C LaunchPad development kit. I am using CCS v10.3.0 on Windows 10 Pro, v10.0.19042.
importPackage(Packages.com.ti.ccstudio.scripting.environment); importPackage(Packages.com.ti.debug.engine.scripting); importPackage(Packages.java.lang); importPackage(Packages.java.io); var env; var debugServer = null; var debugSession = null; // Project build configuration var ProjectConfig = "debug_launchpad"; // Base directory where this project is located // While debugging the script, just using the boot loader to simplify the process var ProjectDirectory = "C:/work/f28004x-boot-loader"; // File paths relative to ProjectDirectory var ExecutableFile = ProjectConfig+"/F28004x Boot Loader.out"; var TargetConfigFile = "targetConfigs/TMS320F280049C.ccxml"; var LogFile = "ccs/debugLog.xml"; var LogFileStyle = "ccs/DefaultStylesheet.xsl"; var DataFile = "data.txt" // Address to load application image key var AppKeyAddrHex = "82004"; var AppKeyAddrLong= Long.parseLong(AppKeyAddrHex, 16); // Application image key to indicate a valid application is loaded var AppKeyHex = "5B5B"; var AppKeyLong = Long.parseLong(AppKeyHex, 16); // Execute the debug script RunDebug(); function getErrorCode(exception) { var ex2 = exception.javaException; if (ex2 instanceof Packages.com.ti.ccstudio.scripting.environment.ScriptingException) { return ex2.getErrorID(); } return 0; } /** * This function is called to perform some clean up * before exiting the script */ function quit(retVal) { /* Close debug session */ if (debugSession != null) { debugSession.terminate(); } /* Stop the server */ if (debugServer != null) { debugServer.stop(); } delete env; /* Terminate JVM and return main return value */ java.lang.System.exit(retVal); } function RunDebug(){ /* Create base scripting environment */ env = ScriptingEnvironment.instance(); env.traceSetConsoleLevel(TraceLevel.ALL); env.traceWrite("Begin scripting session"); env.setCurrentDirectory(ProjectDirectory); /* Does the data file exist? */ dataFileObj = new File(DataFile); var test = dataFileObj.exists(); if (test == false) { env.traceWrite("No data file"); quit(1); } /* Create the trace log file */ try { env.traceBegin(LogFile, LogFileStyle); env.traceSetFileLevel(TraceLevel.ALL); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite("Cannot create log file. Error " + errCode+"\n"); quit (1); } /* Open the Debug Server */ try { debugServer = env.getServer("DebugServer.1"); debugServer.setConfig(TargetConfigFile); /* The second parameter specifies the core, '*' indicates the default core */ debugSession = debugServer.openSession("*", "*"); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite("Failed to open session. Error " + errCode+"\n"); quit (1); } /* Print out all debugSession options */ try { debugSession.options.printOptions(".*"); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite("Could not print options. Error " + errCode+"\n"); quit (1); } /* Set options */ try { if ( debugSession.options.optionExist("AutoRunToLabelOnReset") ) { debugSession.options.setBoolean( "AutoRunToLabelOnReset", false); } if ( debugSession.options.optionExist("AutoRunToLabelOnRestart") ) { debugSession.options.setBoolean( "AutoRunToLabelOnRestart", false); } if ( debugSession.options.optionExist("HaltOnConnect") ) { debugSession.options.setBoolean( "HaltOnConnect", true); } if ( debugSession.options.optionExist("FlashEraseSelection") ) { // We will manually specify the sectors to erase debugSession.options.setString( "FlashEraseSelection", "Selected Sectors Only"); // Flash bank 0 debugSession.options.setBoolean( "FlashC28Bank0Sector0", true); debugSession.options.setBoolean( "FlashC28Bank0Sector1", true); debugSession.options.setBoolean( "FlashC28Bank0Sector2", true); debugSession.options.setBoolean( "FlashC28Bank0Sector3", true); debugSession.options.setBoolean( "FlashC28Bank0Sector4", true); debugSession.options.setBoolean( "FlashC28Bank0Sector5", true); debugSession.options.setBoolean( "FlashC28Bank0Sector6", true); debugSession.options.setBoolean( "FlashC28Bank0Sector7", true); debugSession.options.setBoolean( "FlashC28Bank0Sector8", true); debugSession.options.setBoolean( "FlashC28Bank0Sector9", true); debugSession.options.setBoolean( "FlashC28Bank0Sector10", true); debugSession.options.setBoolean( "FlashC28Bank0Sector11", true); debugSession.options.setBoolean( "FlashC28Bank0Sector12", true); debugSession.options.setBoolean( "FlashC28Bank0Sector13", true); debugSession.options.setBoolean( "FlashC28Bank0Sector14", true); debugSession.options.setBoolean( "FlashC28Bank0Sector15", true); // Flash bank 1 debugSession.options.setBoolean( "FlashC28Bank1Sector0", false); debugSession.options.setBoolean( "FlashC28Bank1Sector1", false); debugSession.options.setBoolean( "FlashC28Bank1Sector2", true); debugSession.options.setBoolean( "FlashC28Bank1Sector3", true); debugSession.options.setBoolean( "FlashC28Bank1Sector4", true); debugSession.options.setBoolean( "FlashC28Bank1Sector5", true); debugSession.options.setBoolean( "FlashC28Bank1Sector6", true); debugSession.options.setBoolean( "FlashC28Bank1Sector7", true); debugSession.options.setBoolean( "FlashC28Bank1Sector8", true); debugSession.options.setBoolean( "FlashC28Bank1Sector9", true); debugSession.options.setBoolean( "FlashC28Bank1Sector10", true); debugSession.options.setBoolean( "FlashC28Bank1Sector11", true); debugSession.options.setBoolean( "FlashC28Bank1Sector12", true); debugSession.options.setBoolean( "FlashC28Bank1Sector13", true); debugSession.options.setBoolean( "FlashC28Bank1Sector14", true); debugSession.options.setBoolean( "FlashC28Bank1Sector15", true); } if ( debugSession.options.optionExist("FlashDownloadSetting") ) { // Dont erase on program; erase manually debugSession.options.setString( "FlashDownloadSetting", "Program Only"); } } catch (ex) { errCode = getErrorCode(ex); env.traceWrite ("Could not set options. Error "+errCode+"\n"); quit (1); } /* Connect to target */ try { env.traceWrite("Connecting to target: " + debugSession.getBoardName()); debugSession.target.connect(); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite ("Failed to connect to target device. Error "+errCode+"\n"); quit (1); } /* Reset target */ try { env.traceWrite("Resetting target"); debugSession.target.reset(); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite ("Failed to reset target device. Error "+errCode+"\n"); quit (1); } /* Erase flash */ try { env.traceWrite("Erasing flash"); debugSession.flash.erase(); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite ("Failed to erase flash. Error "+errCode+"\n"); quit (1); } /* Load program */ try { env.traceWrite("Loading: " + ExecutableFile); debugSession.memory.loadProgram(ExecutableFile); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite ("Failed to load program. Error "+errCode+"\n"); quit (1); } /* Write key to indicate a valid application is loaded */ try { // Tell the debugger that we can read/write into flash bank 0 debugSession.memory.map.add(0x00080000,0,0x10000,true,true); // Test the address before writing var testValue = debugSession.memory.readData(1,AppKeyAddrLong,16,false); env.traceWrite ("Test value before = "+testValue+"\n"); // Write key data to address debugSession.memory.loadRaw(1, AppKeyAddrLong, "data.txt", 16, false); // Test the address after writing var testValue = debugSession.memory.readData(1,AppKeyAddrLong,16,false); env.traceWrite ("Test value after = "+testValue+"\n"); } catch (ex) { errCode = getErrorCode(ex); env.traceWrite ("Failed to write application key to flash. Error "+errCode+"\n"); quit (1); } env.traceWrite("Running\n"); }