summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2018-05-06 21:13:02 -0700
committerKeith Packard <keithp@keithp.com>2018-05-07 09:21:56 -0700
commitbea42e45952df85d61428662caefbb100465a585 (patch)
tree34ec1af35c03183e42d4a7ae96b862640d83f330 /src
parent4451f7b6bade66775a197b93c6e70ba15f1826ce (diff)
altos/chaoskey-v1.0: Add endpoint for reading flash contents
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>
Diffstat (limited to 'src')
-rw-r--r--src/chaoskey-v1.0/Makefile4
-rw-r--r--src/chaoskey-v1.0/ao_chaoskey.c2
-rw-r--r--src/chaoskey-v1.0/ao_pins.h4
-rw-r--r--src/kernel/ao_flash_readout.c50
-rw-r--r--src/kernel/ao_flash_readout.h20
5 files changed, 79 insertions, 1 deletions
diff --git a/src/chaoskey-v1.0/Makefile b/src/chaoskey-v1.0/Makefile
index dea5b483..c6cf45bd 100644
--- a/src/chaoskey-v1.0/Makefile
+++ b/src/chaoskey-v1.0/Makefile
@@ -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
diff --git a/src/chaoskey-v1.0/ao_chaoskey.c b/src/chaoskey-v1.0/ao_chaoskey.c
index c3acd441..1165e454 100644
--- a/src/chaoskey-v1.0/ao_chaoskey.c
+++ b/src/chaoskey-v1.0/ao_chaoskey.c
@@ -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();
diff --git a/src/chaoskey-v1.0/ao_pins.h b/src/chaoskey-v1.0/ao_pins.h
index f2c46d8b..22861d9d 100644
--- a/src/chaoskey-v1.0/ao_pins.h
+++ b/src/chaoskey-v1.0/ao_pins.h
@@ -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
index 00000000..46b5ba7a
--- /dev/null
+++ b/src/kernel/ao_flash_readout.c
@@ -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
index 00000000..5eee53cc
--- /dev/null
+++ b/src/kernel/ao_flash_readout.h
@@ -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_ */