
Em fevereiro de 2020, um artigo emocionante apareceu em Habré sobre a conversão do programador ST-Link v2 em uma chave de criptografia de hardware. Mesmo assim, nos comentários, houve reclamações de que o resultado não poderia ser repetido, mas permaneceram sem resposta.
Nos últimos tempos, algumas encomendas do Aliexpress chegaram até mim e agora, tendo percorrido todo o caminho de forma independente, tentarei enviar uma instrução mais ou menos completa com comentários que ajudarão um leigo a atualizar o microprocessador no clone chinês ST-Link v2 . Tentarei não repetir o que já é conhecido. Consulte o artigo de origem sobre contatos de solda e uso do GPG com uma chave de hardware.
Hardware
, , — Aliexpress. , - STM32***, . , , , .
— - . , USB USB , , , , .
ST-Link v2 STMicroelectronics STM32F103 , 128 -.
STM32F103 — CKS32F103C8*. . CS32F CKS32F. - , , 64 K -. , CKS32F103CB* 128 K , .
STM32GC102CB. , , , 64 K - (, , USB).
, 64 . ST-Link v2 .
- Linux, Debian. antiX Linux Debian 9 Stretch.
make git , :
sudo apt install gcc-arm-none-eabi
sudo apt install libnewlib-arm-none-eabi
sudo apt install openocd
, .
- c Arm Embedded Toolchain CentOS. .
Windows :
, .
, , . .
, . , , , , . , , . .
, OpenOCD.
- , ( ).
1: ST32F1** ( STM32GC102CB)
$ openocd -f interface/stlink-v2.cfg -f target/st32f1x.cfg -c 'init; reset halt; stm32f1x unlock 0; reset halt;exit'
...
Info : device id = 0x20036410
Info : flash size = 64kbytes
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
2: CKS32F1**
$ openocd -f interface/stlink-v2.cfg -f target/st32f1x.cfg -c 'init; reset halt; stm32f1x unlock 0; reset halt;exit'
...
Info : STLINK v2 JTAG v29 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.174295
Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477
interface/stlink-v2.cfg target/st32f1x.cfg — OpenOCD, . ID 0x2ba01477, STM321F1*** 0x1ba01477. , OpenOCD ID, , STM321F1**, ID set _CPUTAPID 0x1ba01477.
mkdir ~/.openocd/{target}
cp /usr/share/openocd/scripts/target/stm32f1x.cfg ~/.openocd/target/cks32f1x.cfg
sed -i 's/0x1ba01477/0x2ba01477/' /.openocd/target/cks32f1x.cfg
, CKS32F1** -f target/cks32f1x.cfg.
. , , 128 -. OpenOCD :
Error: checksum mismatch - attempting binary compare
diff 0 address 0x08010000. Was 0x00 instead of 0x7d
diff 1 address 0x08010001. Was 0x50 instead of 0x40
:
$ openocd -f interface/stlink-v2.cfg -f target/cks32f1x.cfg -c 'init; reset halt; stm32f1x unlock 1; reset halt;exit'
...
Error: flash bank 1 does not exist
...
— , .
GNUK
- , GNUK, .
, 2003 g10code, GnuPG, , OpenPGP, , ISO/IEC 7816. — ZeitControl , , Card OS ( -). FLOSS-Shop OpenPGP Smart Card 17,90 €. , -, .
Free Software Initiative of Japan — FSF. GNUK STM32*, - OpenPGP Smart Card.
GNUK — 1.0 1.2, . , STABLE-BRANCH-1-0 STABLE-BRANCH-1-2 .
PolarSSL, 1.0 ChibiOS_2.0.8, 1.2 chopstx.
, 1.0 62 , 1.2 — 112 .
, 128 , 1.2
git clone https://salsa.debian.org/gnuk-team/gnuk/gnuk.git
cd gnuk
git checkout STABLE-BRANCH-1-2
# 'chopstx'
git submodule update --init
cd src
# --target , USB
# --target - FST_01 - ST-LINK v2
# --vidpid="234b:0000" USB -
# --enable-factory-reset - PIN
./configure --target=ST_DONGLE --vidpid="234b:0000" --enable-factory-reset
make
64 , 1.0
git clone https://salsa.debian.org/gnuk-team/gnuk/gnuk.git
cd gnuk
git checkout STABLE-BRANCH-1-0
cd src
# , - OLIMEX_STM32_H103 - ST-LINK v2
# --enable-keygen -
./configure --vidpid="234b:0000" --enable-keygen
make
, :
usb_lld.o: In function `usb_lld_set_data_to_recv':
usb_lld.c:(.text.usb_lld_set_data_to_recv+0x0): multiple definition of `usb_lld_set_data_to_recv'
main.o:/mnt/f/DocSasha/devzone/gnuk/src/usb_lld.h:136: first defined here
...
, inline usb_lld.h usb_lld_set_data_to_recv , .
inline- #define make. patch, , , , .
--- a/src/usb_lld.h
+++ b/src/usb_lld.h
@@ -131,10 +131,7 @@ extern void usb_lld_set_feature (uint8_t feature);
extern void usb_lld_set_data_to_send (const void *p, size_t len);
-extern inline void usb_lld_set_data_to_recv (void *p, size_t len)
-{
- usb_lld_set_data_to_send ((const void *)p, len);
-}
+#define usb_lld_set_data_to_recv(p, len) usb_lld_set_data_to_send ((const void *)p, len)
extern void usb_lld_prepare_shutdown (void);
extern void usb_lld_shutdown (void);
. cfg , 1.2 src/build/gnuk.elf, 1.0 src/gnuk.elf
#
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c 'program build/gnuk.elf verify reset exit'
#
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "stm32f1x lock 0" -c reset -c exit
Como tenho todos os processadores com 64 Kbytes de memória flash, não pude verificar se o comando stm32f1x lock 1 deve ser usado para bloquear o acesso ao segundo banco de memória.
Conclusão
Então é só isso. Eu consegui. Espero que você tenha sucesso.
Outros links