Index: MSPDebugStack_OS_Package/Makefile =================================================================== --- MSPDebugStack_OS_Package.orig/Makefile 2013-08-13 14:15:06.000000000 +1200 +++ MSPDebugStack_OS_Package/Makefile 2013-08-13 14:39:42.000000000 +1200 @@ -78,6 +78,9 @@ OUTPUT := libmsp430.so +dumpdb: dumpdb.o $(OBJS) + $(CXX) -o $@ $^ $(LIBDIRS) $(LIBS) + all: libbsl.a $(OBJS) $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(OUTPUT) -o $(OUTPUT) $(OBJS) $(LIBDIRS) -Wl,-Bstatic $(STATIC_LIBS) -Wl,-Bdynamic $(LIBS) Index: MSPDebugStack_OS_Package/dumpdb.cpp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ MSPDebugStack_OS_Package/dumpdb.cpp 2013-08-13 14:34:50.000000000 +1200 @@ -0,0 +1,8 @@ +#include +#include "TemplateDeviceDb/Registration.h" + +int main() +{ + TI::DLL430::TemplateDeviceDb::Registration().dumpDatabase(); + return 0; +} Index: MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/TemplateDeviceDb/Registration.cpp =================================================================== --- MSPDebugStack_OS_Package.orig/DLL430_v3/src/TI/DLL430/TemplateDeviceDb/Registration.cpp 2013-08-13 14:35:00.000000000 +1200 +++ MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/TemplateDeviceDb/Registration.cpp 2013-09-08 12:50:45.000000000 +1200 @@ -43,6 +43,7 @@ #include "boost/date_time/posix_time/posix_time.hpp" #include "boost/foreach.hpp" #include +#include #include @@ -92,31 +93,382 @@ DeviceMap::instance().insert(std::make_pair(match, devCreator)); } +static void dump_id(const char *name, const IdCodeImpl& code) +{ + printf("\t\t.%s\t\t= {\n", name); + printf("\t\t\t.ver_id\t\t= 0x%04x,\n", code.verId_); + printf("\t\t\t.ver_sub_id\t= 0x%04x,\n", code.verSubId_); + printf("\t\t\t.revision\t= 0x%02x,\n", code.revisison_); + printf("\t\t\t.fab\t\t= 0x%02x,\n", code.fab_); + printf("\t\t\t.self\t\t= 0x%04x,\n", code.self_); + printf("\t\t\t.config\t\t= 0x%02x,\n", (uint8_t)code.config_); + printf("\t\t\t.fuses\t\t= 0x%02x,\n", code.fuses_); + printf("\t\t\t.activation_key\t= 0x%08x,\n", code.activationKey_); + printf("\t\t},\n"); +} + +static void dump_eem(const EemInfoImpl& eem) +{ + printf("\t\t.eem\t\t= {\n"); + printf("\t\t\t.state_storage\t\t= 0x%02x,\n", eem.stateStorage_); + printf("\t\t\t.cycle_counter\t\t= 0x%02x,\n", eem.cycleCounter_); + printf("\t\t\t.cycle_counter_ops\t= 0x%02x,\n", + eem.cycleCounterOperations_); + printf("\t\t\t.trig_emulation_level\t= 0x%02x,\n", + eem.trigger_.emulation_level_); + printf("\t\t\t.trig_mem\t\t= 0x%02x,\n", eem.trigger_.mem_); + printf("\t\t\t.trig_reg\t\t= 0x%02x,\n", eem.trigger_.reg_); + printf("\t\t\t.trig_combinations\t= 0x%02x,\n", + eem.trigger_.combinations_); + printf("\t\t\t.trig_options\t\t= 0x%02x,\n", + eem.trigger_.options_); + printf("\t\t\t.trig_dma\t\t= 0x%02x,\n", eem.trigger_.dma_); + printf("\t\t\t.trig_read_write\t= 0x%02x,\n", + eem.trigger_.readwrite_); + printf("\t\t\t.trig_reg_ops\t\t= 0x%02x,\n", + eem.trigger_.regOperations_); + printf("\t\t\t.trig_comp_level\t= 0x%02x,\n", + eem.trigger_.compLevel_); + printf("\t\t\t.trig_mem_cond_level\t= 0x%02x,\n", + eem.trigger_.mem_condLevel_); + printf("\t\t\t.trig_mem_umask_level\t= 0x%02x,\n", + eem.trigger_.mem_umaskLevel_); + printf("\t\t\t.seq_states\t\t= 0x%02x,\n", + eem.sequencer_.states_); + printf("\t\t\t.seq_start\t\t= 0x%02x,\n", + eem.sequencer_.start_); + printf("\t\t\t.seq_end\t\t= 0x%02x,\n", + eem.sequencer_.end_); + printf("\t\t\t.seq_reset\t\t= 0x%02x,\n", + eem.sequencer_.reset_); + printf("\t\t\t.seq_blocked\t\t= 0x%02x,\n", + eem.sequencer_.blocked_); + printf("\t\t},\n"); +} + +static void dump_voltage(const VoltageInfoImpl& voltage) +{ + printf("\t\t.voltage\t= {\n"); + printf("\t\t\t.vcc_min\t= %d,\n", voltage.vccMin_); + printf("\t\t\t.vcc_max\t= %d,\n", voltage.vccMax_); + printf("\t\t\t.vcc_flash_min\t= %d,\n", voltage.vccFlashMin_); + printf("\t\t\t.vcc_secure_min\t= %d,\n", voltage.vccSecureMin_); + printf("\t\t\t.vpp_secure_min\t= %d,\n", voltage.vppSecureMin_); + printf("\t\t\t.vpp_secure_max\t= %d,\n", voltage.vppSecureMax_); + printf("\t\t\t.has_test_vpp\t= %d,\n", voltage.hasTestVpp_); + printf("\t\t},\n"); +} + +static void dtimer(int index, const ClockPair& p) +{ + if (!p.name_.size()) + printf("\t\t\t{0},\n"); + else + printf("\t\t\t{\"%s\", 0x%02x},\n", + p.name_.c_str(), p.value_); +} + +#if 0 +static void dname(const ClockName& n) +{ + if (!n.size()) + return; + + printf("\t\t\t\"%s\",\n", n.c_str()); +} +#endif + +static void dump_clocks(const ClockInfoImpl& clocks) +{ + const EemTimerImpl& t = clocks.eemTimer_; + const EemClocksImpl& n = clocks.eemClockNames_; + + printf("\t\t.clock_control\t= 0x%02x,\n", clocks.clockControl_); + printf("\t\t.mclk_control\t= 0x%04x,\n", clocks.mclkCntrl0_); + + printf("\t\t.clock_map\t= {\n"); + dtimer(0, t._0_); dtimer(1, t._1_); + dtimer(2, t._2_); dtimer(3, t._3_); + dtimer(4, t._4_); dtimer(5, t._5_); + dtimer(6, t._6_); dtimer(7, t._7_); + dtimer(8, t._8_); dtimer(9, t._9_); + dtimer(10, t._10_); dtimer(11, t._11_); + dtimer(12, t._12_); dtimer(13, t._13_); + dtimer(14, t._14_); dtimer(15, t._15_); + dtimer(16, t._16_); dtimer(17, t._17_); + dtimer(18, t._18_); dtimer(19, t._19_); + dtimer(20, t._20_); dtimer(21, t._21_); + dtimer(22, t._22_); dtimer(23, t._23_); + dtimer(24, t._24_); dtimer(25, t._25_); + dtimer(26, t._26_); dtimer(27, t._27_); + dtimer(28, t._28_); dtimer(29, t._29_); + dtimer(30, t._30_); dtimer(31, t._31_); + printf("\t\t},\n"); + +#if 0 + printf("\t\t.names\t\t= {\n"); + dname(n._0_); dname(n._1_); dname(n._2_); dname(n._3_); + dname(n._4_); dname(n._5_); dname(n._6_); dname(n._7_); + dname(n._8_); dname(n._9_); dname(n._10_); dname(n._11_); + dname(n._12_); dname(n._13_); dname(n._14_); dname(n._15_); + printf("\t\t},\n"); +#endif +} + +static void dump_functions(const std::map& m) +{ + printf("\t\t.v3_functions\t= {\n"); + for (std::map::const_iterator + i = m.begin(); i != m.end(); ++i) + printf("\t\t\t[0x%02x]\t= 0x%02x,\n", i->first, i->second); + printf("\t\t},\n"); +} + +static void dump_funclet(const std::map funclets, + const FuncletMappingImpl& fmap, + FuncletCode::Type type, const char *name) +{ + const std::map::const_iterator i = + fmap.getMap().find(type); + + if (i == fmap.getMap().end()) + return; + if (i->second == FuncletCode()) + return; + + const std::map::const_iterator j = + funclets.find(i->second); + + if (j == funclets.end()) { + fprintf(stderr, "UNKNOWN FUNCLET!\n"); + abort(); + } + + printf("\t\t.v3_%s\t= &%s,\n", name, j->second.c_str()); +} + +static void dump_funclet_code(const char *name, const FuncletCode& code) +{ + const uint16_t *data = code.code(); + const size_t len = code.codeSize() >> 1; + size_t i = 0; + + printf("static const struct chipinfo_funclet %s = {\n", name); + printf("\t.code_size\t= %d,\n", len); + printf("\t.max_payload\t= %d,\n", code.maxPayloadSize()); + printf("\t.entry_point\t= 0x%04x,\n", code.programStartOffset()); + printf("\t.code\t\t= {\n"); + + while (i < len) { + size_t r = 4; + + if (i + r > len) + r = len - i; + + printf("\t\t"); + for (size_t j = 0; j < r; j++) { + const uint16_t w = data[i + j]; + + if (j) + printf(" "); + + printf("0x%04x,", w); + } + printf("\n"); + + i += r; + } + + printf("\t}\n"); + printf("};\n\n"); +} + +static void dump_features(const FeaturesImpl& f, + const ExtendedFeaturesImpl& e) +{ + printf("\t\t.clock_sys\t= CHIPINFO_CLOCK_SYS_"); + switch (f.clock_) { + case BC_1xx: printf("BC_1XX"); break; + case BC_2xx: printf("BC_2XX"); break; + case FLLPLUS: printf("FLL_PLUS"); break; + case MOD_OSC: printf("MOD_OSC"); break; + } + printf(",\n"); + + printf("\t\t.features\t= 0"); + + if (f.i2c_) + printf("\n\t\t\t| CHIPINFO_FEATURE_I2C"); + if (f.lcfe_) + printf("\n\t\t\t| CHIPINFO_FEATURE_LCFE"); + if (f.quickMemRead_) + printf("\n\t\t\t| CHIPINFO_FEATURE_QUICK_MEM_READ"); + if (f.sflldh_) + printf("\n\t\t\t| CHIPINFO_FEATURE_SFLLDH"); + if (f.hasFram_) + printf("\n\t\t\t| CHIPINFO_FEATURE_FRAM"); + if (f.noBsl_) + printf("\n\t\t\t| CHIPINFO_FEATURE_NO_BSL"); + + if (e.tmr_) + printf("\n\t\t\t| CHIPINFO_FEATURE_TMR"); + if (e.jtag_) + printf("\n\t\t\t| CHIPINFO_FEATURE_JTAG"); + if (e.dtc_) + printf("\n\t\t\t| CHIPINFO_FEATURE_DTC"); + if (e.sync_) + printf("\n\t\t\t| CHIPINFO_FEATURE_SYNC"); + if (e.instr_) + printf("\n\t\t\t| CHIPINFO_FEATURE_INSTR"); + if (e._1377_) + printf("\n\t\t\t| CHIPINFO_FEATURE_1337"); + if (e.psach_) + printf("\n\t\t\t| CHIPINFO_FEATURE_PSACH"); + + printf(",\n"); +} + +static void dump_power(const PowerSettingsImpl& p) +{ + printf("\t\t.power\t\t= {\n"); + printf("\t\t\t.reg_mask\t\t= 0x%05x,\n", p.powerTestRegMask_); + printf("\t\t\t.enable_lpm5\t\t= 0x%05x,\n", p.testRegEnableLpmx5_); + printf("\t\t\t.disable_lpm5\t\t= 0x%05x,\n", p.testRegDisableLpmx5_); + printf("\t\t\t.reg_mask_3v\t\t= 0x%05x,\n", p.powerTestReg3VMask_); + printf("\t\t\t.enable_lpm5_3v\t\t= 0x%05x,\n", p.testReg3VEnableLpmx5_); + printf("\t\t\t.disable_lpm5_3v\t= 0x%05x,\n", p.testReg3VDisableLpmx5_); + printf("\t\t},\n"); +} + +static void dump_memory(const DeviceCreatorBase::DeviceTypePtr& dev) +{ + const int num = dev->getMemorySize(); + int i; + + printf("\t\t.memory\t\t= {\n"); + for (i = 0; i < num; i++) { + const MemoryInfoImpl mem = dev->getMemoryAt(i); + + printf("\t\t\t{\n"); + printf("\t\t\t\t.name\t\t= \"%s\",\n", mem.name_.c_str()); + printf("\t\t\t\t.type\t\t= CHIPINFO_MEMTYPE_"); + switch(mem.flags_ >> 8) { + case 0: printf("FLASH"); break; + case 1: printf("ROM"); break; + case 2: printf("RAM"); break; + case 3: printf("REGISTER"); break; + } + printf(",\n"); + + printf("\t\t\t\t.bits\t\t= %d,\n", mem.flags_ & 0x7f); + printf("\t\t\t\t.mapped\t\t= %d,\n", (mem.flags_ >> 7) & 1); + printf("\t\t\t\t.size\t\t= %d,\n", mem.size_); + printf("\t\t\t\t.offset\t\t= 0x%05x,\n", mem.offset_); + printf("\t\t\t\t.seg_size\t= %d,\n", mem.seg_size_); + printf("\t\t\t\t.bank_size\t= %d,\n", mem.bank_size_); + printf("\t\t\t\t.banks\t\t= %d,\n", mem.banks_); + printf("\t\t\t},\n"); + } + printf("\t\t\t{0}\n"); + printf("\t\t},\n"); +} + void Registration::dumpDatabase() const { - std::ofstream out("dbdump.txt"); - out << "Device name,ID,Fuses,EEM level\n"; - out << std::hex << std::uppercase << std::setfill('0'); + std::map funclets; + funclets[FuncletCode( eraseFuncletCodeDCO, sizeof(eraseFuncletCodeDCO), 4 )] = "erase_dco"; + funclets[FuncletCode( eraseFuncletCodeXDCO, sizeof(eraseFuncletCodeXDCO), 4 )] = "erase_xdco"; + funclets[FuncletCode( eraseFuncletCodeXv2, sizeof(eraseFuncletCodeXv2) )] = "erase_xv2"; + funclets[FuncletCode( eraseFuncletCodeXv2FRAM, sizeof(eraseFuncletCodeXv2FRAM) )] = "erase_xv2_fram"; + funclets[FuncletCode( eraseFuncletCodeFLL, sizeof(eraseFuncletCodeFLL), 4 )] = "erase_fll"; + funclets[FuncletCode( eraseFuncletCodeXFLL, sizeof(eraseFuncletCodeXFLL), 4 )] = "erase_xfll"; + + funclets[FuncletCode( writeFuncletCodeDCO, sizeof(writeFuncletCodeDCO), 128 )] = "write_dco"; + funclets[FuncletCode( writeFuncletCodeXDCO, sizeof(writeFuncletCodeXDCO), 256 )] = "write_xdco"; + funclets[FuncletCode( writeFuncletCodeXv2, sizeof(writeFuncletCodeXv2) )] = "write_xv2"; + funclets[FuncletCode( writeFuncletCodeXv2WordMode, sizeof(writeFuncletCodeXv2WordMode) )] = "write_xv2_word"; + funclets[FuncletCode( writeFuncletCodeXv2FRAM, sizeof(writeFuncletCodeXv2FRAM) )] = "write_xv2_fram"; + funclets[FuncletCode( writeFuncletCode430I, sizeof(writeFuncletCode430I), 128 )] = "write_430i"; + funclets[FuncletCode( writeFuncletCodeFLL, sizeof(writeFuncletCodeFLL), 128 )] = "write_fll"; + funclets[FuncletCode( writeFuncletCodeXFLL, sizeof(writeFuncletCodeXFLL), 256 )] = "write_xfll"; + + funclets[FuncletCode( UnlockBslFuncletCodeXv2, sizeof(UnlockBslFuncletCodeXv2))] = "bsl_unlock_xv2"; + + printf( +"/* MSP430 chip database\n" +" *\n" +" * THIS FILE WAS GENERATED FROM MSP430.DLL (slac460f.zip)\n" +" *\n" +" * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/\n" +" *\n" +" * Redistribution and use in source and binary forms, with or without\n" +" * modification, are permitted provided that the following conditions\n" +" * are met:\n" +" *\n" +" * Redistributions of source code must retain the above copyright\n" +" * notice, this list of conditions and the following disclaimer.\n" +" *\n" +" * Redistributions in binary form must reproduce the above copyright\n" +" * notice, this list of conditions and the following disclaimer in the\n" +" * documentation and/or other materials provided with the\n" +" * distribution.\n" +" *\n" +" * Neither the name of Texas Instruments Incorporated nor the names of\n" +" * its contributors may be used to endorse or promote products derived\n" +" * from this software without specific prior written permission.\n" +" *\n" +" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" +" * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" +" * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" +" * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" +" * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" +" * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" +" * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" +" * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" +" * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" +" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" +" * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" +" */\n\n"); + + for (std::map::const_iterator i = funclets.begin(); + i != funclets.end(); ++i) + dump_funclet_code(i->second.c_str(), i->first); + + printf("const struct chipinfo chipinfo_db[] = {"); BOOST_FOREACH(const DeviceMapImpl::value_type& entry, DeviceMap::instance()) { DeviceCreatorBase::DeviceTypePtr device = entry.second->create(); - const IdCodeImpl& code = device->match_.value_; - out << device->description_; - out << ",0x" << std::setw(4) << code.verId_; - out << ",0x" << std::setw(2) << (unsigned)code.fuses_; - out << "," << (unsigned)device->eemInfo_.trigger_.emulation_level_; - - const unsigned numMemoryAreas = device->getMemorySize(); - for (unsigned i = 0; i < numMemoryAreas; ++i) - { - MemoryInfoImpl memory = device->getMemoryAt(i); - out << "," << memory.name_ << std::setw(4) << " (0x" << memory.offset_ << "-0x" << (memory.offset_ + memory.size_ - 1) << ")"; - } + printf("\t{\n"); + printf("\t\t.name\t\t= \"%s\",\n", device->description_.c_str()); + printf("\t\t.bits\t\t= %d,\n", device->bits_); + printf("\t\t.psa\t\t= CHIPINFO_PSA_%s,\n", + device->flags_ ? "ENHANCED" : "REGULAR"); + + dump_clocks(device->clockInfo_); + dump_id("id", device->match_.value_); + dump_id("id_mask", device->match_.mask_); + dump_eem(device->eemInfo_); + dump_voltage(device->voltageInfo_); + dump_functions(device->fnctMap_.GetMap()); + dump_funclet(funclets, device->funcletMapping_, + FuncletCode::ERASE, "erase"); + dump_funclet(funclets, device->funcletMapping_, + FuncletCode::WRITE, "write"); + dump_funclet(funclets, device->funcletMapping_, + FuncletCode::BSLUNLOCK, "unlock"); + dump_features(device->featuresInfo_, + device->extFeaturesInfo_); + dump_power(device->powerSettings_); + dump_memory(device); - out << std::endl; + printf("\t},\n\n"); } + + /* Terminator */ + printf("\t{0}\n"); + printf("};\n"); } size_t Registration::FindAndPrepareDevice(const IdCodeImpl& idCode) Index: MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/FuncletCode.h =================================================================== --- MSPDebugStack_OS_Package.orig/DLL430_v3/src/TI/DLL430/FuncletCode.h 2013-08-14 10:38:49.000000000 +1200 +++ MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/FuncletCode.h 2013-08-14 10:39:57.000000000 +1200 @@ -58,6 +58,21 @@ uint16_t programStartOffset() const { return code_ ? code_[0] : 0; } size_t maxPayloadSize() const { return maxPayload_; } + bool operator<(const FuncletCode& b) const + { + if (codeSize_ < b.codeSize_) + return true; + if (codeSize_ > b.codeSize_) + return false; + + if (maxPayload_ < b.maxPayload_) + return true; + if (maxPayload_ > b.maxPayload_) + return false; + + return memcmp(code_, b.code_, codeSize_ + 2) < 0; + } + bool operator==(const FuncletCode& b) const { return (codeSize_ == b.codeSize_) &&