altos/chaoskey-v1.0: Add endpoint for reading flash contents
authorKeith Packard <keithp@keithp.com>
Mon, 7 May 2018 04:13:02 +0000 (21:13 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 7 May 2018 16:21:56 +0000 (09:21 -0700)
This creates another IN endpoint which provides the contents of flash
for validation of the firmware load on the host.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/chaoskey-v1.0/Makefile
src/chaoskey-v1.0/ao_chaoskey.c
src/chaoskey-v1.0/ao_pins.h
src/kernel/ao_flash_readout.c [new file with mode: 0644]
src/kernel/ao_flash_readout.h [new file with mode: 0644]

index dea5b483f5158e719cf63dcf0d49c018f5e67fef..c6cf45bd348e2203dc778cbaec325c5c17879afa 100644 (file)
@@ -14,6 +14,7 @@ INC = \
        ao_task.h \
        ao_adc_fast.h \
        ao_power.h \
+       ao_flash_readout.h \
        ao_crc.h \
        stm32f0.h
 
@@ -34,6 +35,7 @@ ALTOS_SRC = \
        ao_boot_chain.c \
        ao_usb_stm.c \
        ao_trng_send.c \
+       ao_flash_readout.c \
        ao_task.c \
        ao_power.c \
        ao_gpio.c \
@@ -84,7 +86,7 @@ check: $(METAINFO)
 distclean:     clean
 
 clean:
-       rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx
+       rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx *.bin
        rm -f ao_product.h
        rm -f *.cab
 
index c3acd441c637c77f2357f01a24d11e74dc434020..1165e4540fbe5e445a1e7aa32ef54681d76ae262 100644 (file)
@@ -20,6 +20,7 @@
 #include <ao_adc_fast.h>
 #include <ao_crc.h>
 #include <ao_trng_send.h>
+#include <ao_flash_readout.h>
 
 void main(void)
 {
@@ -30,6 +31,7 @@ void main(void)
        ao_dma_init();
        ao_adc_init();
        ao_crc_init();
+       ao_flash_readout_init();
 
        ao_usb_init();
 
index f2c46d8b409193a84156975326f25011f8c98869..22861d9d1e8636e665ba706518532d9c568fb632 100644 (file)
@@ -50,6 +50,7 @@
 #define AO_USB_HAS_OUT                 0
 #define AO_USB_HAS_IN                  1
 #define AO_USB_HAS_IN2                 1
+#define AO_USB_HAS_IN3                 1
 #define AO_USB_HAS_INT                 0
 #define AO_USB_SELF_POWER              0
 #define AO_USB_DEVICE_ID_SERIAL                1
@@ -58,6 +59,9 @@
 
 #define IS_FLASH_LOADER        0
 
+#define AO_FLASH_READOUT               1
+#define ao_flash_readout_putchar(c)    ao_usb_putchar3(c)
+
 /* ADC */
 
 #define AO_ADC_PIN0_PORT       (&stm_gpioa)
diff --git a/src/kernel/ao_flash_readout.c b/src/kernel/ao_flash_readout.c
new file mode 100644 (file)
index 0000000..46b5ba7
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2018 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <ao.h>
+#include <ao_usb.h>
+#include <ao_flash_readout.h>
+
+#ifndef AO_FLASH_READOUT_BASE
+#define AO_FLASH_READOUT_BASE  AO_BOOT_LOADER_BASE
+#define AO_FLASH_READOUT_BOUND AO_BOOT_APPLICATION_BOUND
+#endif
+
+static void
+ao_flash_readout(void)
+{
+       uint8_t *base = (uint8_t *) AO_FLASH_READOUT_BASE;
+       uint8_t *bound = (uint8_t *) AO_FLASH_READOUT_BOUND;
+       uint8_t *p = base;
+
+       for (;;) {
+               ao_arch_block_interrupts();
+               while (!ao_usb_running) {
+                       p = base;
+                       ao_sleep(&ao_usb_running);
+               }
+               ao_arch_release_interrupts();
+               ao_flash_readout_putchar(*p++);
+               if (p == bound)
+                       p = base;
+       }
+}
+
+static struct ao_task  ao_flash_readout_task;
+
+void
+ao_flash_readout_init(void)
+{
+       ao_add_task(&ao_flash_readout_task, ao_flash_readout, "flash_readout");
+}
diff --git a/src/kernel/ao_flash_readout.h b/src/kernel/ao_flash_readout.h
new file mode 100644 (file)
index 0000000..5eee53c
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright © 2018 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef _AO_FLASH_READOUT_H_
+#define _AO_FLASH_READOUT_H_
+
+void   ao_flash_readout_init(void);
+
+#endif /* _AO_FLASH_READOUT_H_ */