diff --git a/ChangeLog b/ChangeLog index 4f17cf5..904f846 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,10 @@ 2017-04-28 NIIBE Yutaka - * src/usb_ctrl.c (download_check_crc32): Use check_crc32. * src/mcu-stm32f103.c: New. + (check_crc32, sram_address): New. + + * src/usb_ctrl.c (download_check_crc32): Use check_crc32 and + sram_address. * src/openpgp-do.c (gpg_write_digital_signature_counter): Fix writing lower 10-bit. diff --git a/emulation/Makefile b/emulation/Makefile new file mode 100644 index 0000000..bfa6499 --- /dev/null +++ b/emulation/Makefile @@ -0,0 +1,31 @@ +SRCS = usbip-server.c +OBJS = $(SRCS:.c=.o) +TARGET=gnuk_emulation +GNUKDIR=../src + +GNUK_SRCS = main.c call-rsa.c \ + usb-ccid.c openpgp.c ac.c openpgp-do.c flash.c \ + bn.c mod.c \ + modp256r1.c jpc_p256r1.c ec_p256r1.c call-ec_p256r1.c \ + modp256k1.c jpc_p256k1.c ec_p256k1.c call-ec_p256k1.c \ + mod25638.c ecc-edwards.c ecc-mont.c sha512.c \ + random.c neug.c sha256.c +USB_SRCS=usb_desc.c usb_ctrl.c + +GNUK_CSRC = $(addprefix $(GNUKDIR)/, $(GNUK_SRCS)) +GNUK_OBJS = $(notdir $(GNUK_CSRC:.c=.o)) + +USB_CSRC = $(addprefix $(GNUKDIR)/, $(USB_SRCS)) +USB_OBJS = $(notdir $(USB_CSRC:.c=.o)) + +# all: +# echo $(GNUK_OBJS) + +$(TARGET): $(OBJS) $(USB_OBJS) Makefile + $(CC) -o $(TARGET) $(OBJS) $(USB_OBJS) + +$(GNUK_OBJS): %.o : $(GNUKDIR)/%.c Makefile + $(CC) -c $(CFLAGS) -I. -I$(GNUKDIR) -I../chopstx $< -o $@ + +$(USB_OBJS): %.o : $(GNUKDIR)/%.c Makefile + $(CC) -c $(CFLAGS) -I. -I$(GNUKDIR) -I../chopstx $< -o $@ diff --git a/src/gnuk.h b/src/gnuk.h index b5eb15a..55ae8e1 100644 --- a/src/gnuk.h +++ b/src/gnuk.h @@ -461,3 +461,4 @@ int pinpad_getline (int msg_code, uint32_t timeout_usec); extern uint8_t _regnual_start, __heap_end__[]; int check_crc32 (const uint32_t *start_p, const uint32_t *end_p); +uint8_t * sram_address (uint32_t offset); diff --git a/src/mcu-stm32f103.c b/src/mcu-stm32f103.c index 5ccedc6..ce10515 100644 --- a/src/mcu-stm32f103.c +++ b/src/mcu-stm32f103.c @@ -48,3 +48,9 @@ check_crc32 (const uint32_t *start_p, const uint32_t *end_p) return (rbit (CRC->DR) ^ crc32) == 0xffffffff; } + +uint8_t * +sram_address (uint32_t offset) +{ + return ((uint8_t *)0x20000000) + offset; +} diff --git a/src/usb_ctrl.c b/src/usb_ctrl.c index bbb1c6d..3e89c42 100644 --- a/src/usb_ctrl.c +++ b/src/usb_ctrl.c @@ -233,8 +233,7 @@ usb_setup (struct usb_dev *dev) } else /* SETUP_SET */ { - uint8_t *addr = (uint8_t *)(0x20000000 + arg->value * 0x100 - + arg->index); + uint8_t *addr = sram_address ((arg->value * 0x100) + arg->index); if (arg->request == USB_FSIJ_GNUK_DOWNLOAD) { @@ -255,7 +254,7 @@ usb_setup (struct usb_dev *dev) if (*ccid_state_p != CCID_STATE_EXITED) return -1; - if (((uint32_t)addr & 0x03)) + if (((uintptr_t)addr & 0x03)) return -1; return download_check_crc32 (dev, (uint32_t *)addr);