From 6fac517d485b8a8d2689710db04690d4da32fda1 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 1 Jul 2012 09:54:45 -0300 Subject: [PATCH] fw/: move secrets to secret.c; rename reset secret to maintenance secret --- fw/Makefile | 2 +- fw/image.c | 8 +------- fw/image.h | 6 ------ fw/param.c | 2 +- fw/reset.c | 7 ++----- fw/secret.c | 29 +++++++++++++++++++++++++++++ fw/secret.h | 27 +++++++++++++++++++++++++++ 7 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 fw/secret.c create mode 100644 fw/secret.h diff --git a/fw/Makefile b/fw/Makefile index 39fa3cf..a78dc4e 100644 --- a/fw/Makefile +++ b/fw/Makefile @@ -31,7 +31,7 @@ OBJCOPY = $(AVR_PREFIX)objcopy SIZE = $(AVR_PREFIX)size OBJS = $(NAME).o accel.o dispatch.o hash.o image.o param.o \ - reset.o sample.o sweep.o \ + reset.o sample.o secret.o sweep.o \ $(COMMON_OBJS) BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS) COMMON_OBJS = rf.o spi.o diff --git a/fw/image.c b/fw/image.c index 6d70dca..f0e8ad9 100644 --- a/fw/image.c +++ b/fw/image.c @@ -15,12 +15,11 @@ #include #include -#include - #include "io.h" #include "hash.h" #include "proto.h" #include "dispatch.h" +#include "secret.h" #include "image.h" @@ -32,11 +31,6 @@ static bool failed; const struct line *image = images[0]; -const uint8_t image_secret[2*PAYLOAD] PROGMEM = { - #include "image-secret.inc" -}; - - #define MAP(port, value, group) ( \ ((value) & 1 ? MASK(port, LED_##group##1) : 0) | \ ((value) & 2 ? MASK(port, LED_##group##2) : 0) | \ diff --git a/fw/image.h b/fw/image.h index 81282b3..8b4feab 100644 --- a/fw/image.h +++ b/fw/image.h @@ -14,13 +14,8 @@ #ifndef IMAGE_H #define IMAGE_H -#include #include -#include - -#include "proto.h" - struct line { uint8_t d; /* port D0-D7 */ @@ -29,6 +24,5 @@ struct line { extern const struct line *image; -extern const uint8_t image_secret[2*PAYLOAD] PROGMEM; #endif /* !IMAGE_H */ diff --git a/fw/param.c b/fw/param.c index c02c24c..12ecd81 100644 --- a/fw/param.c +++ b/fw/param.c @@ -19,7 +19,7 @@ #include "hash.h" #include "sweep.h" -#include "image.h" +#include "secret.h" #include "proto.h" #include "dispatch.h" diff --git a/fw/reset.c b/fw/reset.c index a8b96be..eaa573e 100644 --- a/fw/reset.c +++ b/fw/reset.c @@ -20,6 +20,7 @@ #include "proto.h" #include "dispatch.h" +#include "secret.h" /* @@ -34,14 +35,10 @@ * intercept the secret(s) either way. */ -static const uint8_t reset_secret[PAYLOAD] PROGMEM = { - #include "unlock-secret.inc" -}; - static bool reset_first(uint8_t limit, const uint8_t *payload) { - if (memcmp_P(payload, reset_secret, PAYLOAD)) + if (memcmp_P(payload, maint_secret, PAYLOAD)) return 0; WDTCSR = 1 << WDE; return 1; diff --git a/fw/secret.c b/fw/secret.c new file mode 100644 index 0000000..6dab055 --- /dev/null +++ b/fw/secret.c @@ -0,0 +1,29 @@ +/* + * fw/secret.c - Shared authentication secrets + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * 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. + */ + + +#include + +#include + +#include "proto.h" +#include "secret.h" + + +const uint8_t maint_secret[PAYLOAD] PROGMEM = { + #include "unlock-secret.inc" +}; + + +const uint8_t image_secret[2*PAYLOAD] PROGMEM = { + #include "image-secret.inc" +}; diff --git a/fw/secret.h b/fw/secret.h new file mode 100644 index 0000000..43e0d2b --- /dev/null +++ b/fw/secret.h @@ -0,0 +1,27 @@ +/* + * fw/secret.h - Shared authentication secrets + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * 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. + */ + + +#ifndef SECRET_H +#define SECRET_H + +#include + +#include + +#include "proto.h" + + +extern const uint8_t maint_secret[PAYLOAD] PROGMEM; +extern const uint8_t image_secret[2*PAYLOAD] PROGMEM; + +#endif /* !SECRET_H */