void BossaWindow::CreateFlash() { Samba& samba = wxGetApp().samba; Flash::Ptr& flash = wxGetApp().flash; FlashFactory flashFactory; ChipId chipId; try { chipId = samba.chipId(); } catch (exception& e) { Disconnected(); Error(wxString(e.what(), wxConvUTF8)); return; } flash = flashFactory.create(samba, chipId); if (flash.get() == NULL) { Disconnected(); Error(wxString::Format(wxT("Chip ID %s is not supported"), chipId.c_str())); return; } _statusBar->SetStatusText(wxString::Format(wxT("Device: %s"), flash->name().c_str()), 1); Connected(); }
int main(int argc, char* argv[]) { int args; char* pos; CmdOpts cmd(argc, argv, sizeof(opts) / sizeof(opts[0]), opts); if ((pos = strrchr(argv[0], '/')) || (pos = strrchr(argv[0], '\\'))) argv[0] = pos + 1; if (argc <= 1) { fprintf(stderr, "%s: you must specify at least one option\n", argv[0]); return help(argv[0]); } args = cmd.parse(); if (args < 0) return help(argv[0]); if (config.read && (config.write || config.verify)) { fprintf(stderr, "%s: read option is exclusive of write or verify\n", argv[0]); return help(argv[0]); } if (config.read || config.write || config.verify) { if (args == argc) { fprintf(stderr, "%s: missing file\n", argv[0]); return help(argv[0]); } argc--; } if (args != argc) { fprintf(stderr, "%s: extra arguments found\n", argv[0]); return help(argv[0]); } if (config.help) { printf("Usage: %s [OPTION...] [FILE]\n", argv[0]); printf("Basic Open Source SAM-BA Application (BOSSA) Version " VERSION "\n" "Flash programmer for Atmel SAM devices.\n" "Copyright (c) 2011-2012 ShumaTech (http://www.shumatech.com)\n" "\n" "Examples:\n" " bossac -e -w -v -b image.bin # Erase flash, write flash with image.bin,\n" " # verify the write, and set boot from flash\n" " bossac -r0x10000 image.bin # Read 64KB from flash and store in image.bin\n" ); printf("\nOptions:\n"); cmd.usage(stdout); printf("\nReport bugs to <*****@*****.**>\n"); return 1; } try { Samba samba; PortFactory portFactory; FlashFactory flashFactory; if (config.debug) samba.setDebug(true); bool isUsb = false; if (config.forceUsb) { if (config.forceUsbArg.compare("true")==0) isUsb = true; else if (config.forceUsbArg.compare("false")==0) isUsb = false; else { fprintf(stderr, "Invalid USB value: %s\n", config.forceUsbArg.c_str()); return 1; } } if (config.port) { bool res; if (config.forceUsb) res = samba.connect(portFactory.create(config.portArg, isUsb)); else res = samba.connect(portFactory.create(config.portArg)); if (!res) { fprintf(stderr, "No device found on %s\n", config.portArg.c_str()); return 1; } } else { string port; if (!autoScan(samba, portFactory, port)) { fprintf(stderr, "Auto scan for device failed\n"); fprintf(stderr, "Try specifying a serial port with the '-p' option\n"); return 1; } printf("Device found on %s\n", port.c_str()); } uint32_t chipId = samba.chipId(); Flash::Ptr flash = flashFactory.create(samba, chipId); if (flash.get() == NULL) { fprintf(stderr, "Flash for chip ID %08x is not supported\n", chipId); return 1; } Flasher flasher(flash); if (config.unlock) flasher.lock(config.unlockArg, false); if (config.erase) flasher.erase(); if (config.write) flasher.write(argv[args]); if (config.verify) if (!flasher.verify(argv[args])) return 2; if (config.read) flasher.read(argv[args], config.readArg); if (config.boot) { printf("Set boot flash %s\n", config.bootArg ? "true" : "false"); flash->setBootFlash(config.bootArg); } if (config.bod) { printf("Set brownout detect %s\n", config.bodArg ? "true" : "false"); flash->setBod(config.bodArg); } if (config.bor) { printf("Set brownout reset %s\n", config.borArg ? "true" : "false"); flash->setBor(config.borArg); } if (config.security) { printf("Set security\n"); flash->setSecurity(); } if (config.lock) flasher.lock(config.lockArg, true); if (config.info) flasher.info(samba); if (config.reset) samba.reset(); } catch (exception& e) { fprintf(stderr, "\n%s\n", e.what()); return 1; } catch(...) { fprintf(stderr, "\nUnhandled exception\n"); return 1; } return 0; }