+
+static const struct {
+ const char *name;
+ int code_size;
+ int block_size;
+} MCUs[] = {
+ {"at90usb162", 15872, 128},
+ {"atmega32u4", 32256, 128},
+ {"at90usb646", 64512, 256},
+ {"at90usb1286", 130048, 256},
+#if defined(USE_LIBUSB) || defined(USE_APPLE_IOKIT) || defined(USE_WIN32)
+ {"mkl26z64", 63488, 512},
+ {"mk20dx128", 131072, 1024},
+ {"mk20dx256", 262144, 1024},
+ {"mk66fx1m0", 1048576, 1024},
+ {"mk64fx512", 524288, 1024},
+ {"imxrt1062", 2031616, 1024},
+
+ // Add duplicates that match friendly Teensy Names
+ // Match board names in boards.txt
+ {"TEENSY", 15872, 128},
+ {"TEENSYPP", 64512, 256},
+ {"TEENSY2", 32256, 128},
+ {"TEENSY2PP", 130048, 256},
+ {"TEENSYLC", 63488, 512},
+ {"TEENSY30", 131072, 1024},
+ {"TEENSY31", 262144, 1024},
+ {"TEENSY32", 262144, 1024},
+ {"TEENSY35", 524288, 1024},
+ {"TEENSY36", 1048576, 1024},
+ {"TEENSY40", 2031616, 1024},
+ {"TEENSY41", 8126464, 1024},
+#endif
+ {NULL, 0, 0},
+};
+
+
+void list_mcus()
+{
+ int i;
+ printf("Supported MCUs are:\n");
+ for(i=0; MCUs[i].name != NULL; i++)
+ printf(" - %s\n", MCUs[i].name);
+ exit(1);
+}
+
+
+void read_mcu(char *name)
+{
+ int i;
+
+ if(name == NULL) {
+ fprintf(stderr, "No MCU specified.\n");
+ list_mcus();
+ }
+
+ for(i=0; MCUs[i].name != NULL; i++) {
+ if(strcasecmp(name, MCUs[i].name) == 0) {
+ code_size = MCUs[i].code_size;
+ block_size = MCUs[i].block_size;
+ return;
+ }
+ }
+
+ fprintf(stderr, "Unknown MCU type \"%s\"\n", name);
+ list_mcus();
+}
+
+
+void parse_flag(char *arg)
+{
+ int i;
+ for(i=1; arg[i]; i++) {
+ switch(arg[i]) {
+ case 'w': wait_for_device_to_appear = 1; break;
+ case 'r': hard_reboot_device = 1; break;
+ case 's': soft_reboot_device = 1; break;
+ case 'n': reboot_after_programming = 0; break;
+ case 'v': verbose = 1; break;
+ case 'b': boot_only = 1; break;
+ default:
+ fprintf(stderr, "Unknown flag '%c'\n\n", arg[i]);
+ usage(NULL);
+ }
+ }
+}
+
+