Mercurial > pihelp
comparison main.c @ 38:9e888708f33d
sd test code
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 27 Jun 2013 11:24:56 +0000 |
parents | c6f77df67dde |
children | d07aa7644c66 |
comparison
equal
deleted
inserted
replaced
36:c6f77df67dde | 38:9e888708f33d |
---|---|
294 return 0; | 294 return 0; |
295 | 295 |
296 return fat_open_file(fs, &file_entry); | 296 return fat_open_file(fs, &file_entry); |
297 } | 297 } |
298 | 298 |
299 static uint32_t sd_serial = 0; | |
300 static char conf_start[30]; | |
301 | |
299 static void | 302 static void |
300 hmac_file(const char* fn) | 303 hmac_file(const char* fn) |
301 { | 304 { |
302 sd_raw_init(); | 305 uint8_t res; |
303 struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, 0, 0, 0); | 306 struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, 0, 0, 0); |
307 | |
308 if (!partition) | |
309 { | |
310 sprintf(conf_start, "part"); | |
311 return; | |
312 } | |
313 | |
304 struct fat_fs_struct* fs = fat_open(partition); | 314 struct fat_fs_struct* fs = fat_open(partition); |
315 if (!fs) | |
316 { | |
317 sprintf(conf_start, "bad fs"); | |
318 return; | |
319 } | |
305 struct fat_dir_entry_struct directory; | 320 struct fat_dir_entry_struct directory; |
306 fat_get_dir_entry_of_path(fs, "/", &directory); | 321 res = fat_get_dir_entry_of_path(fs, "/", &directory); |
322 if (!res) | |
323 { | |
324 sprintf(conf_start, "bad direc"); | |
325 return; | |
326 } | |
307 | 327 |
308 struct sd_raw_info disk_info; | 328 struct sd_raw_info disk_info; |
309 sd_raw_get_info(&disk_info); | 329 sd_raw_get_info(&disk_info); |
310 printf("diskinfo size %d", disk_info.capacity); | 330 sd_serial = disk_info.serial; |
311 | 331 |
312 struct fat_dir_struct* dd = fat_open_dir(fs, &directory); | 332 struct fat_dir_struct* dd = fat_open_dir(fs, &directory); |
313 struct fat_file_struct* fd = open_file_in_dir(fs, dd, "fn"); | 333 if (!dd) |
314 | 334 { |
335 sprintf(conf_start, "bad dd"); | |
336 return; | |
337 } | |
338 struct fat_file_struct* fd = open_file_in_dir(fs, dd, fn); | |
339 if (!fd) | |
340 { | |
341 sprintf(conf_start, "bad fd"); | |
342 return; | |
343 } | |
344 | |
345 fat_read_file(fd, conf_start, sizeof(conf_start)-1); | |
346 conf_start[sizeof(conf_start)-1] = '\0'; | |
347 | |
348 fat_close_file(fd); | |
349 fd = NULL; | |
350 fat_close_dir(dd); | |
351 dd = NULL; | |
352 fat_close(fs); | |
353 fs = NULL; | |
354 partition_close(partition); | |
355 partition = NULL; | |
356 | |
357 #if 0 | |
315 char c = 0; | 358 char c = 0; |
316 char buf[512]; | 359 char buf[512]; |
317 for (int i = 0; i < 10; i++) | 360 for (int i = 0; i < 10; i++) |
318 { | 361 { |
319 fat_read_file(fd, buf, sizeof(buf)); | 362 fat_read_file(fd, buf, sizeof(buf)); |
320 c ^= buf[0]; | 363 c ^= buf[0]; |
321 } | 364 } |
322 printf("total %d\n", c); | 365 printf("total %d\n", c); |
366 #endif | |
367 } | |
368 | |
369 | |
370 static void | |
371 cmd_testsd(const char *param) | |
372 { | |
373 PORT_PI_RESET &= ~_BV(PIN_PI_RESET); | |
374 DDR_PI_RESET |= _BV(PIN_PI_RESET); | |
375 _delay_ms(200); | |
376 | |
377 sd_raw_init(); | |
378 hmac_file(param); | |
379 sd_raw_deinit(); | |
380 | |
381 _delay_ms(200); | |
382 | |
383 DDR_PI_RESET &= ~_BV(PIN_PI_RESET); | |
323 } | 384 } |
324 | 385 |
325 static void cmd_reset() __attribute__ ((noreturn)); | 386 static void cmd_reset() __attribute__ ((noreturn)); |
326 static void | 387 static void |
327 cmd_reset() | 388 cmd_reset() |
377 "watchdog_short %lu (%lu)\n" | 438 "watchdog_short %lu (%lu)\n" |
378 "newboot %lu (%lu)\n" | 439 "newboot %lu (%lu)\n" |
379 "oneshot (%lu)\n" | 440 "oneshot (%lu)\n" |
380 "uptime %lu rem %u\n" | 441 "uptime %lu rem %u\n" |
381 "boot normal %hhu\n" | 442 "boot normal %hhu\n" |
443 "disk serial %lx\n" | |
444 "disk start '%s'\n" | |
382 ), | 445 ), |
383 watchdog_long_limit, cur_watchdog_long, long_reboot_mode, | 446 watchdog_long_limit, cur_watchdog_long, long_reboot_mode, |
384 watchdog_short_limit, cur_watchdog_short, | 447 watchdog_short_limit, cur_watchdog_short, |
385 newboot_limit, cur_newboot, | 448 newboot_limit, cur_newboot, |
386 cur_oneshot, | 449 cur_oneshot, |
387 t.ticks, t.rem, | 450 t.ticks, t.rem, |
388 boot_normal_status); | 451 boot_normal_status, |
452 sd_serial, | |
453 conf_start); | |
389 } | 454 } |
390 | 455 |
391 static void | 456 static void |
392 cmd_set_params(const char *params) | 457 cmd_set_params(const char *params) |
393 { | 458 { |
943 LOCAL_PSTR(newboot); | 1008 LOCAL_PSTR(newboot); |
944 LOCAL_PSTR(oldboot); | 1009 LOCAL_PSTR(oldboot); |
945 LOCAL_PSTR(status); | 1010 LOCAL_PSTR(status); |
946 LOCAL_PSTR(random); | 1011 LOCAL_PSTR(random); |
947 LOCAL_PSTR(prog); | 1012 LOCAL_PSTR(prog); |
1013 LOCAL_PSTR(testsd); | |
948 LOCAL_HELP(set_params, "<long_limit> <short_limit> <newboot_limit>"); | 1014 LOCAL_HELP(set_params, "<long_limit> <short_limit> <newboot_limit>"); |
949 LOCAL_HELP(set_key, "20_byte_hex>"); | 1015 LOCAL_HELP(set_key, "20_byte_hex>"); |
950 LOCAL_HELP(oneshot, "<timeout>"); | 1016 LOCAL_HELP(oneshot, "<timeout>"); |
951 LOCAL_HELP(prog, "<password>"); | 1017 LOCAL_HELP(prog, "<password>"); |
952 LOCAL_HELP(random, "<admux> <nbytes>"); | 1018 LOCAL_HELP(random, "<admux> <nbytes>"); |
953 LOCAL_HELP(hmac, "<key_index> <20_byte_hex_data>"); | 1019 LOCAL_HELP(hmac, "<key_index> <20_byte_hex_data>"); |
954 LOCAL_HELP(decrypt, "<key_index> <20_byte_hmac|16_byte_aes_block>"); | 1020 LOCAL_HELP(decrypt, "<key_index> <20_byte_hmac|16_byte_aes_block>"); |
1021 LOCAL_HELP(testsd, "<filename>"); | |
955 | 1022 |
956 static const struct handler { | 1023 static const struct handler { |
957 PGM_P name; | 1024 PGM_P name; |
958 void(*cmd)(const char *param); | 1025 void(*cmd)(const char *param); |
959 // existence of arg_help indicates if the cmd takes a parameter. | 1026 // existence of arg_help indicates if the cmd takes a parameter. |
971 {set_params_str, cmd_set_params, set_params_help}, | 1038 {set_params_str, cmd_set_params, set_params_help}, |
972 {set_key_str, cmd_set_avr_key, set_key_help}, | 1039 {set_key_str, cmd_set_avr_key, set_key_help}, |
973 {random_str, cmd_random, random_help}, | 1040 {random_str, cmd_random, random_help}, |
974 {vcc_str, cmd_vcc, NULL}, | 1041 {vcc_str, cmd_vcc, NULL}, |
975 {reset_str, cmd_reset, NULL}, | 1042 {reset_str, cmd_reset, NULL}, |
1043 {testsd_str, cmd_testsd, testsd_help}, | |
976 {prog_str, cmd_prog, prog_help}, | 1044 {prog_str, cmd_prog, prog_help}, |
977 }; | 1045 }; |
978 | 1046 |
979 if (readbuf[0] == '\0') | 1047 if (readbuf[0] == '\0') |
980 { | 1048 { |