On fredag 10 juni 2016 kl. 16:21:52 CEST Linus Nordberg wrote:
...
> I just pushed some code to user/ln5/tamper. From commit message:

Thanks for writing this code. I've tested it thoroughly now, and gotten it to 
work with a couple of changes:

0) Had to change -mmcu to attiny828 in the Makefile to get the code to run on 
the ATtiny.

1) Sleep mode seemed not to work - it seemed like the AVR was reset on wakeup 
so if I released the panic button while it was flashing it's LED in the start 
of main() the MKM would not get erased. We need to debug that, but I think 
we'll need to go with busy-waiting for the moment (since it is just a couple 
of days before Berlin). Maybe you and I can read the datasheet together in 
Berlin.

2) The chip needed CS_N to go high to mark the end of the sequential read mode 
select command.

3) Initialization should release control of the MKM to the FPGA.

My work-in progress patch is attached. How do you want to incorporate it? 
Should I just commit and push to your user/ln5/tamper repository?

/Fredrik
diff --git a/Makefile b/Makefile
index ec919f8..0bed033 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 CC = avr-gcc
-CFLAGS = -std=gnu99 -Wpedantic -Wall -Werror -mmcu=avr25 -D__AVR_ATtiny828__
+CFLAGS = -std=gnu99 -Wpedantic -Wall -Werror -mmcu=attiny828 -D__AVR_ATtiny828__
 OBJCOPY = avr-objcopy
 
 all: tamper.hex
diff --git a/tamper.c b/tamper.c
index d1d5c04..477198e 100644
--- a/tamper.c
+++ b/tamper.c
@@ -213,18 +213,29 @@ mkm_wipe()
 
   spi_setup(1);
   mkm_grab();
+
   mkm_chip_select(1);
   spi_set_operation(SPI_OPERATION_SEQUENCE);
+  mkm_chip_select(0);
+
+  mkm_chip_select(1);
   spi_write(SPI_WRITE);
   spi_write(0);                    /* Address, high byte. */
   spi_write(0);                    /* Address, low byte. */
   for (int i = 0; i < 0x1fff; i++) /* 8192 bytes (64Kbit). */
     spi_write(0);
   mkm_chip_select(0);
+
   mkm_release();
   spi_setup(0);
 
   AVR_LED_PORT &= ~_BV(AVR_LED_RED_BIT);
+
+  /* Flash blue LED three times to indicate wipe is done */
+  for (int x = 0; x < 6; x++) {
+    AVR_LED_PORT ^= _BV(AVR_LED_BLUE_BIT);
+    for (int i = 0; i < 3200; i++);
+  }
 }
 
 static inline void
@@ -250,13 +261,19 @@ main()
   for (int i = 0; i < 16000; i++);
   AVR_LED_PORT &= ~0x0f;
 
+  mkm_release();
+
   while (1)
     {
       if (panic_p())
         mkm_wipe();
 
-      if (!panic_p())
-        sleep();
+      /* Sleep is not working right at the moment (the AVR seems to be reset
+	 when brought out of sleep mode by a press on the panic button).
+
+	 if (!panic_p())
+	   sleep();
+      */
     }
 
   return 0;
_______________________________________________
Tech mailing list
[email protected]
https://lists.cryptech.is/listinfo/tech

Reply via email to