Mercurial > pihelp
comparison main.c @ 41:d07aa7644c66
bit more fiddling
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 28 Jun 2013 23:16:00 +0800 |
parents | 9e888708f33d |
children | 082c8294c86b |
comparison
equal
deleted
inserted
replaced
40:5a7a0ef8a958 | 41:d07aa7644c66 |
---|---|
172 //PORTB = 0xff; // XXX change when using SPI | 172 //PORTB = 0xff; // XXX change when using SPI |
173 //PORTD = 0xff; | 173 //PORTD = 0xff; |
174 //PORTC = 0xff; | 174 //PORTC = 0xff; |
175 | 175 |
176 DDR_PI_WARNING |= _BV(PIN_PI_WARNING); | 176 DDR_PI_WARNING |= _BV(PIN_PI_WARNING); |
177 | |
178 DDR_PI_RESET &= ~_BV(PIN_PI_RESET); | |
177 | 179 |
178 #if 0 | 180 #if 0 |
179 // set pullup | 181 // set pullup |
180 PORTD |= _BV(PD2); | 182 PORTD |= _BV(PD2); |
181 // INT0 setup | 183 // INT0 setup |
301 | 303 |
302 static void | 304 static void |
303 hmac_file(const char* fn) | 305 hmac_file(const char* fn) |
304 { | 306 { |
305 uint8_t res; | 307 uint8_t res; |
306 struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, 0, 0, 0); | 308 |
309 struct sd_raw_info disk_info; | |
310 sd_raw_get_info(&disk_info); | |
311 sd_serial = disk_info.serial; | |
312 printf_P(PSTR("serial %lx\n"), sd_serial); | |
313 | |
314 struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, sd_raw_write, sd_raw_write_interval, 1); | |
307 | 315 |
308 if (!partition) | 316 if (!partition) |
309 { | 317 { |
310 sprintf(conf_start, "part"); | 318 sprintf(conf_start, "part"); |
311 return; | 319 return; |
323 { | 331 { |
324 sprintf(conf_start, "bad direc"); | 332 sprintf(conf_start, "bad direc"); |
325 return; | 333 return; |
326 } | 334 } |
327 | 335 |
328 struct sd_raw_info disk_info; | |
329 sd_raw_get_info(&disk_info); | |
330 sd_serial = disk_info.serial; | |
331 | |
332 struct fat_dir_struct* dd = fat_open_dir(fs, &directory); | 336 struct fat_dir_struct* dd = fat_open_dir(fs, &directory); |
333 if (!dd) | 337 if (!dd) |
334 { | 338 { |
335 sprintf(conf_start, "bad dd"); | 339 sprintf(conf_start, "bad dd"); |
336 return; | 340 return; |
340 { | 344 { |
341 sprintf(conf_start, "bad fd"); | 345 sprintf(conf_start, "bad fd"); |
342 return; | 346 return; |
343 } | 347 } |
344 | 348 |
345 fat_read_file(fd, conf_start, sizeof(conf_start)-1); | 349 fat_read_file(fd, (uint8_t*)conf_start, sizeof(conf_start)-1); |
346 conf_start[sizeof(conf_start)-1] = '\0'; | 350 conf_start[sizeof(conf_start)-1] = '\0'; |
347 | 351 |
348 fat_close_file(fd); | 352 fat_close_file(fd); |
349 fd = NULL; | 353 fd = NULL; |
350 fat_close_dir(dd); | 354 fat_close_dir(dd); |
370 static void | 374 static void |
371 cmd_testsd(const char *param) | 375 cmd_testsd(const char *param) |
372 { | 376 { |
373 PORT_PI_RESET &= ~_BV(PIN_PI_RESET); | 377 PORT_PI_RESET &= ~_BV(PIN_PI_RESET); |
374 DDR_PI_RESET |= _BV(PIN_PI_RESET); | 378 DDR_PI_RESET |= _BV(PIN_PI_RESET); |
375 _delay_ms(200); | 379 long_delay(200); |
380 | |
381 printf_P(PSTR("about to raw init\n")); | |
376 | 382 |
377 sd_raw_init(); | 383 sd_raw_init(); |
384 printf_P(PSTR("done raw init\n")); | |
378 hmac_file(param); | 385 hmac_file(param); |
386 printf_P(PSTR("conf_start '%s'\n"), conf_start); | |
379 sd_raw_deinit(); | 387 sd_raw_deinit(); |
380 | 388 |
381 _delay_ms(200); | 389 long_delay(200); |
382 | 390 |
383 DDR_PI_RESET &= ~_BV(PIN_PI_RESET); | 391 DDR_PI_RESET &= ~_BV(PIN_PI_RESET); |
384 } | 392 } |
385 | 393 |
386 static void cmd_reset() __attribute__ ((noreturn)); | 394 static void cmd_reset() __attribute__ ((noreturn)); |
765 printf_P(PSTR("Programming...\n")); | 773 printf_P(PSTR("Programming...\n")); |
766 long_delay(100); | 774 long_delay(100); |
767 | 775 |
768 // disable wdt | 776 // disable wdt |
769 wdt_disable(); | 777 wdt_disable(); |
778 MCUSR = 0; | |
770 | 779 |
771 // disable interrupts | 780 // disable interrupts |
772 TIMSK0 = 0; | 781 TIMSK0 = 0; |
773 TIMSK1 = 0; | 782 TIMSK1 = 0; |
774 TIMSK2 = 0; | 783 TIMSK2 = 0; |
1008 LOCAL_PSTR(newboot); | 1017 LOCAL_PSTR(newboot); |
1009 LOCAL_PSTR(oldboot); | 1018 LOCAL_PSTR(oldboot); |
1010 LOCAL_PSTR(status); | 1019 LOCAL_PSTR(status); |
1011 LOCAL_PSTR(random); | 1020 LOCAL_PSTR(random); |
1012 LOCAL_PSTR(prog); | 1021 LOCAL_PSTR(prog); |
1013 LOCAL_PSTR(testsd); | |
1014 LOCAL_HELP(set_params, "<long_limit> <short_limit> <newboot_limit>"); | 1022 LOCAL_HELP(set_params, "<long_limit> <short_limit> <newboot_limit>"); |
1015 LOCAL_HELP(set_key, "20_byte_hex>"); | 1023 LOCAL_HELP(set_key, "20_byte_hex>"); |
1016 LOCAL_HELP(oneshot, "<timeout>"); | 1024 LOCAL_HELP(oneshot, "<timeout>"); |
1017 LOCAL_HELP(prog, "<password>"); | 1025 LOCAL_HELP(prog, "<password>"); |
1018 LOCAL_HELP(random, "<admux> <nbytes>"); | 1026 LOCAL_HELP(random, "<admux> <nbytes>"); |
1019 LOCAL_HELP(hmac, "<key_index> <20_byte_hex_data>"); | 1027 LOCAL_HELP(hmac, "<key_index> <20_byte_hex_data>"); |
1020 LOCAL_HELP(decrypt, "<key_index> <20_byte_hmac|16_byte_aes_block>"); | 1028 LOCAL_HELP(decrypt, "<key_index> <20_byte_hmac|16_byte_aes_block>"); |
1021 LOCAL_HELP(testsd, "<filename>"); | |
1022 | 1029 |
1023 static const struct handler { | 1030 static const struct handler { |
1024 PGM_P name; | 1031 PGM_P name; |
1025 void(*cmd)(const char *param); | 1032 void(*cmd)(const char *param); |
1026 // existence of arg_help indicates if the cmd takes a parameter. | 1033 // existence of arg_help indicates if the cmd takes a parameter. |
1038 {set_params_str, cmd_set_params, set_params_help}, | 1045 {set_params_str, cmd_set_params, set_params_help}, |
1039 {set_key_str, cmd_set_avr_key, set_key_help}, | 1046 {set_key_str, cmd_set_avr_key, set_key_help}, |
1040 {random_str, cmd_random, random_help}, | 1047 {random_str, cmd_random, random_help}, |
1041 {vcc_str, cmd_vcc, NULL}, | 1048 {vcc_str, cmd_vcc, NULL}, |
1042 {reset_str, cmd_reset, NULL}, | 1049 {reset_str, cmd_reset, NULL}, |
1043 {testsd_str, cmd_testsd, testsd_help}, | |
1044 {prog_str, cmd_prog, prog_help}, | 1050 {prog_str, cmd_prog, prog_help}, |
1045 }; | 1051 }; |
1046 | 1052 |
1047 if (readbuf[0] == '\0') | 1053 if (readbuf[0] == '\0') |
1048 { | 1054 { |
1232 } | 1238 } |
1233 else | 1239 else |
1234 { | 1240 { |
1235 // pull it low | 1241 // pull it low |
1236 DDR_PI_RESET |= _BV(PIN_PI_BOOT); | 1242 DDR_PI_RESET |= _BV(PIN_PI_BOOT); |
1237 | |
1238 } | 1243 } |
1239 } | 1244 } |
1240 | 1245 |
1241 static void | 1246 static void |
1242 check_flags() | 1247 check_flags() |