New: src/mcu-stm32f103.c.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka
2017-04-28 15:49:38 +09:00
parent 9e52789203
commit 86eaa26d32
6 changed files with 60 additions and 23 deletions

View File

@@ -1,5 +1,8 @@
2017-04-28 NIIBE Yutaka <gniibe@fsij.org>
* src/usb_ctrl.c (download_check_crc32): Use check_crc32.
* src/mcu-stm32f103.c: New.
* src/openpgp-do.c (gpg_write_digital_signature_counter): Fix
writing lower 10-bit.

View File

@@ -8,8 +8,8 @@ CHOPSTX = ../chopstx
# Define linker script file here
LDSCRIPT= gnuk.ld
CSRC = main.c usb_desc.c usb_ctrl.c \
call-rsa.c \
CSRC = main.c call-rsa.c mcu-stm32f103.c \
usb_desc.c usb_ctrl.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 \

View File

@@ -459,3 +459,5 @@ int pinpad_getline (int msg_code, uint32_t timeout_usec);
#endif
extern uint8_t _regnual_start, __heap_end__[];
int check_crc32 (const uint32_t *start_p, const uint32_t *end_p);

50
src/mcu-stm32f103.c Normal file
View File

@@ -0,0 +1,50 @@
/*
* mcu-stm32f103.c - STM32F103 specific routines
*
* Copyright (C) 2017
* Free Software Initiative of Japan
* Author: NIIBE Yutaka <gniibe@fsij.org>
*
* This file is a part of Gnuk, a GnuPG USB Token implementation.
*
* Gnuk 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 3 of the License, or
* (at your option) any later version.
*
* Gnuk 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdint.h>
#include "mcu/stm32f103.h"
static uint32_t
rbit (uint32_t v)
{
uint32_t r;
asm ("rbit %0, %1" : "=r" (r) : "r" (v));
return r;
}
int
check_crc32 (const uint32_t *start_p, const uint32_t *end_p)
{
uint32_t crc32 = *end_p;
const uint32_t *p;
RCC->AHBENR |= RCC_AHBENR_CRCEN;
CRC->CR = CRC_CR_RESET;
for (p = start_p; p < end_p; p++)
CRC->DR = rbit (*p);
return (rbit (CRC->DR) ^ crc32) == 0xffffffff;
}

View File

@@ -1549,7 +1549,6 @@ gpg_data_scan (const uint8_t *do_start, const uint8_t *do_end)
int i;
const uint8_t *dsc_h14_p, *dsc_l10_p;
int dsc_h14, dsc_l10;
const uint8_t *p_end;
dsc_h14_p = dsc_l10_p = NULL;
pw1_lifetime_p = NULL;

View File

@@ -38,7 +38,6 @@
#include "usb_lld.h"
#include "usb_conf.h"
#include "gnuk.h"
#include "mcu/stm32f103.h"
#ifdef ENABLE_VIRTUAL_COM_PORT
#include "usb-cdc.h"
@@ -209,27 +208,11 @@ static const uint8_t *const mem_info[] = { &_regnual_start, __heap_end__, };
#define USB_FSIJ_GNUK_EXEC 2
#define USB_FSIJ_GNUK_CARD_CHANGE 3
static uint32_t rbit (uint32_t v)
{
uint32_t r;
asm ("rbit %0, %1" : "=r" (r) : "r" (v));
return r;
}
/* After calling this function, CRC module remain enabled. */
static int download_check_crc32 (struct usb_dev *dev, const uint32_t *end_p)
static int
download_check_crc32 (struct usb_dev *dev, const uint32_t *end_p)
{
uint32_t crc32 = *end_p;
const uint32_t *p;
RCC->AHBENR |= RCC_AHBENR_CRCEN;
CRC->CR = CRC_CR_RESET;
for (p = (const uint32_t *)&_regnual_start; p < end_p; p++)
CRC->DR = rbit (*p);
if ((rbit (CRC->DR) ^ crc32) == 0xffffffff)
if (check_crc32 ((const uint32_t *)&_regnual_start, end_p))
return usb_lld_ctrl_ack (dev);
return -1;