From ab51c5421da96b55052a384ad9b7f9fd6ae41f9c Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 31 May 2012 08:58:08 +0900 Subject: [PATCH] revice system service, version string --- ChangeLog | 10 ++++++++++ src/gnuk.ld.in | 2 ++ src/sys.c | 17 +++++++---------- src/sys.h | 29 ++++++++++++++++------------- src/usb_conf.h | 2 +- src/usb_desc.c | 2 ++ 6 files changed, 38 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b05e18..c4115d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-05-31 Niibe Yutaka + + Version string of system service is now USB string. + * src/sys.h (unique_device_id): Define here, not as system + service. + * src/sys.c (sys_version): Version string for system service. + * src/usb_desc.c (String_Descriptors): Add sys_version. + * src/usb_conf.h (NUM_STRING_DESC): 7 (was: 6). + * src/gnuk.ld.in (.sys.version): New section. + 2012-05-30 Niibe Yutaka * src/openpgp.c (CHALLENGE_LEN): New. diff --git a/src/gnuk.ld.in b/src/gnuk.ld.in index bd57af7..e87bf1e 100644 --- a/src/gnuk.ld.in +++ b/src/gnuk.ld.in @@ -54,6 +54,8 @@ SECTIONS { _sys = .; KEEP(*(.vectors)) + . = ALIGN(16); + *(.sys.version) sys.o(.text) sys.o(.text.*) sys.o(.rodata) diff --git a/src/sys.c b/src/sys.c index 2c71b99..0c1cc00 100644 --- a/src/sys.c +++ b/src/sys.c @@ -30,15 +30,6 @@ extern uint8_t __flash_start__, __flash_end__; -static const uint8_t * -unique_device_id (void) -{ - /* STM32F103 has 96-bit unique device identifier */ - const uint8_t *addr = (const uint8_t *)0x1ffff7e8; - - return addr; -} - static void usb_cable_config (int enable) { @@ -295,7 +286,6 @@ extern uint8_t __ram_end__; handler vector[] __attribute__ ((section(".vectors"))) = { (handler)&__ram_end__, reset, - (handler)unique_device_id, (handler)set_led, flash_unlock, (handler)flash_program_halfword, @@ -308,3 +298,10 @@ handler vector[] __attribute__ ((section(".vectors"))) = { usb_lld_sys_shutdown, nvic_system_reset, }; + +const uint8_t sys_version[8] __attribute__((section(".sys.version"))) = { + 3*2+2, /* bLength */ + 0x03, /* bDescriptorType = USB_STRING_DESCRIPTOR_TYPE*/ + /* sys version: "1.0" */ + '1', 0, '.', 0, '0', 0, +}; diff --git a/src/sys.h b/src/sys.h index 4a3d89b..3884c95 100644 --- a/src/sys.h +++ b/src/sys.h @@ -1,18 +1,21 @@ +extern const uint8_t sys_version[8]; + typedef void (*handler)(void); extern handler vector[14]; static inline const uint8_t * unique_device_id (void) { - const uint8_t * (*func) (void) = (const uint8_t * (*)(void))vector[2]; + /* STM32F103 has 96-bit unique device identifier */ + const uint8_t *addr = (const uint8_t *)0x1ffff7e8; - return (*func) (); + return addr; } static inline void set_led (int on) { - void (*func) (int) = (void (*)(int))vector[3]; + void (*func) (int) = (void (*)(int))vector[2]; return (*func) (on); } @@ -20,13 +23,13 @@ set_led (int on) static inline void flash_unlock (void) { - (*vector[4]) (); + (*vector[3]) (); } static inline int flash_program_halfword (uint32_t addr, uint16_t data) { - int (*func) (uint32_t, uint16_t) = (int (*)(uint32_t, uint16_t))vector[5]; + int (*func) (uint32_t, uint16_t) = (int (*)(uint32_t, uint16_t))vector[4]; return (*func) (addr, data); } @@ -34,7 +37,7 @@ flash_program_halfword (uint32_t addr, uint16_t data) static inline int flash_erase_page (uint32_t addr) { - int (*func) (uint32_t) = (int (*)(uint32_t))vector[6]; + int (*func) (uint32_t) = (int (*)(uint32_t))vector[5]; return (*func) (addr); } @@ -42,7 +45,7 @@ flash_erase_page (uint32_t addr) static inline int flash_check_blank (const uint8_t *p_start, size_t size) { - int (*func) (const uint8_t *, int) = (int (*)(const uint8_t *, int))vector[7]; + int (*func) (const uint8_t *, int) = (int (*)(const uint8_t *, int))vector[6]; return (*func) (p_start, size); } @@ -51,7 +54,7 @@ static inline int flash_write (uint32_t dst_addr, const uint8_t *src, size_t len) { int (*func) (uint32_t, const uint8_t *, size_t) - = (int (*)(uint32_t, const uint8_t *, size_t))vector[8]; + = (int (*)(uint32_t, const uint8_t *, size_t))vector[7]; return (*func) (dst_addr, src, len); } @@ -59,7 +62,7 @@ flash_write (uint32_t dst_addr, const uint8_t *src, size_t len) static inline int flash_protect (void) { - int (*func) (void) = (int (*)(void))vector[9]; + int (*func) (void) = (int (*)(void))vector[8]; return (*func) (); } @@ -67,7 +70,7 @@ flash_protect (void) static inline void __attribute__((noreturn)) flash_erase_all_and_exec (void (*entry)(void)) { - void (*func) (void (*)(void)) = (void (*)(void (*)(void)))vector[10]; + void (*func) (void (*)(void)) = (void (*)(void (*)(void)))vector[9]; (*func) (entry); for (;;); @@ -76,17 +79,17 @@ flash_erase_all_and_exec (void (*entry)(void)) static inline void usb_lld_sys_init (void) { - (*vector[11]) (); + (*vector[10]) (); } static inline void usb_lld_sys_shutdown (void) { - (*vector[12]) (); + (*vector[11]) (); } static inline void nvic_system_reset (void) { - (*vector[13]) (); + (*vector[12]) (); } diff --git a/src/usb_conf.h b/src/usb_conf.h index ac49ec1..75241e3 100644 --- a/src/usb_conf.h +++ b/src/usb_conf.h @@ -3,7 +3,7 @@ #ifndef __USB_CONF_H #define __USB_CONF_H -#define NUM_STRING_DESC 6 +#define NUM_STRING_DESC 7 /* Control pipe */ /* EP0 */ diff --git a/src/usb_desc.c b/src/usb_desc.c index 13a45c7..681d41f 100644 --- a/src/usb_desc.c +++ b/src/usb_desc.c @@ -4,6 +4,7 @@ #include "config.h" #include "ch.h" +#include "sys.h" #include "usb_lld.h" #include "usb_conf.h" #include "usb-cdc.h" @@ -283,4 +284,5 @@ const struct Descriptor String_Descriptors[NUM_STRING_DESC] = { {gnukStringSerial, sizeof (gnukStringSerial)}, {gnuk_revision_detail, sizeof (gnuk_revision_detail)}, {gnuk_config_options, sizeof (gnuk_config_options)}, + {sys_version, sizeof (sys_version)}, };