+ fprintf(stderr,"Waiting for Proxmark to appear on USB... ");
+ while(!(devh=OpenProxmark(0))) { sleep(1); }
+ fprintf(stderr,"Found.\n");
+
+ unsigned int state = EnterFlashState();
+
+ if( !(state & DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM) ) {
+ fprintf(stderr, "Proxmark would not enter flash state, abort\n");
+ exit(-1);
+ }
+
+ offset=-1; length=0;
+ int current_area = 0;
+ while(find_next_area(argv[1], &offset, &length)) {
+ int i;
+ struct partition *p = NULL;
+ for(i=0; i<sizeof(partitions)/sizeof(partitions[0]); i++) {
+ if(strncmp(partitions[i].name, argv[1] + offset, length) == 0) {
+ /* Check if the name matches the bootrom partition, and if so, require "bootrom" to
+ * be written in full. The other names may be abbreviated.
+ */
+ if(!partitions[i].precious || (strlen(partitions[i].name) == length)) {
+ p = &partitions[i];
+ }
+ break;
+ }
+ }
+
+ if(p == NULL) {
+ fprintf(stderr, "Warning: area name '");
+ fwrite(argv[1]+offset, length, 1, stderr);
+ fprintf(stderr, "' unknown, ignored\n");
+ } else {
+ fprintf(stderr, "Flashing %s from %s\n", p->name, argv[2+current_area]);
+ PrepareFlash(p, argv[2+current_area], state);
+ }
+ current_area++;
+ }
+
+ UsbCommand c;