booting to dfu, detaching, fast flash write

This commit is contained in:
Conor Patrick
2018-12-04 20:23:06 -05:00
parent b475c8391a
commit 173b8833ce
6 changed files with 61 additions and 7 deletions

View File

@@ -14,11 +14,20 @@ flash: solo.hex bootloader.hex
STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect
STM32_Programmer_CLI -c port=SWD -halt -d all.hex -rst STM32_Programmer_CLI -c port=SWD -halt -d all.hex -rst
flash_dfu: solo.hex bootloader.hex
python merge_hex.py solo.hex bootloader.hex all.hex
# STM32_Programmer_CLI -c port=usb1 -halt -e all --readunprotect
STM32_Programmer_CLI -c port=usb1 -halt -d all.hex
flashboot: solo.hex bootloader.hex flashboot: solo.hex bootloader.hex
python merge_hex.py solo.hex bootloader.hex all.hex python merge_hex.py solo.hex bootloader.hex all.hex
STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect
STM32_Programmer_CLI -c port=SWD -halt -d bootloader.hex -rst STM32_Programmer_CLI -c port=SWD -halt -d bootloader.hex -rst
# tell ST DFU to enter application
detach:
STM32_Programmer_CLI -c port=usb1 -ob nBOOT0=1
bootloader.hex: bootloader.hex:
echo "You need to build the bootloader first." echo "You need to build the bootloader first."

View File

@@ -70,8 +70,6 @@ all: $(TARGET).elf
clean: clean:
rm -f *.o src/*.o src/*.elf bootloader/*.o $(OBJ) rm -f *.o src/*.o src/*.elf bootloader/*.o $(OBJ)
detach:
STM32_Programmer_CLI -c port=usb1 -ob nBOOT0=1
cbor: cbor:
cd ../../tinycbor/ && make clean cd ../../tinycbor/ && make clean

View File

@@ -63,6 +63,7 @@ int is_authorized_to_boot()
int bootloader_bridge(int klen, uint8_t * keyh) int bootloader_bridge(int klen, uint8_t * keyh)
{ {
static int has_erased = 0; static int has_erased = 0;
int i;
BootloaderReq * req = (BootloaderReq * )keyh; BootloaderReq * req = (BootloaderReq * )keyh;
uint8_t hash[32]; uint8_t hash[32];
uint8_t version = 1; uint8_t version = 1;
@@ -103,6 +104,8 @@ int bootloader_bridge(int klen, uint8_t * keyh)
} }
flash_write((uint32_t)ptr,req->payload, len); flash_write((uint32_t)ptr,req->payload, len);
break; break;
case BootDone: case BootDone:
printf1(TAG_BOOT, "BootDone: "); printf1(TAG_BOOT, "BootDone: ");
@@ -149,7 +152,7 @@ int bootloader_bridge(int klen, uint8_t * keyh)
printf1(TAG_BOOT, "BootReboot.\r\n"); printf1(TAG_BOOT, "BootReboot.\r\n");
device_reboot(); device_reboot();
break; break;
#ifndef SOLO_HACKER #ifdef SOLO_HACKER
case BootBootloader: case BootBootloader:
printf1(TAG_BOOT, "BootBootloader.\r\n"); printf1(TAG_BOOT, "BootBootloader.\r\n");
flash_option_bytes_init(1); flash_option_bytes_init(1);

View File

@@ -139,6 +139,39 @@ void flash_write(uint32_t addr, uint8_t * data, size_t sz)
} }
// NOT YET working
void flash_write_fast(uint32_t addr, uint32_t * data)
{
__disable_irq();
while (FLASH->SR & (1<<16))
;
FLASH->SR = FLASH->SR;
// Select fast program action
FLASH->CR |= (1<<18);
int i;
for(i = 0; i < 64; i++)
{
*(volatile uint32_t*)addr = (*data);
addr+=4;
data++;
}
while (FLASH->SR & (1<<16))
;
if(FLASH->SR & (1<<1))
{
printf2(TAG_ERR,"program NOT successful %lx\r\n", FLASH->SR);
}
FLASH->SR = (1<<0);
FLASH->CR &= ~(1<<18);
__enable_irq();
}
void flash_lock() void flash_lock()
{ {
FLASH->CR |= (1U<<31); FLASH->CR |= (1U<<31);

View File

@@ -4,6 +4,7 @@
void flash_erase_page(uint8_t page); void flash_erase_page(uint8_t page);
void flash_write_dword(uint32_t addr, uint64_t data); void flash_write_dword(uint32_t addr, uint64_t data);
void flash_write(uint32_t addr, uint8_t * data, size_t sz); void flash_write(uint32_t addr, uint8_t * data, size_t sz);
void flash_write_fast(uint32_t addr, uint32_t * data);
void flash_option_bytes_init(int boot_from_dfu); void flash_option_bytes_init(int boot_from_dfu);
#define FLASH_PAGE_SIZE 2048 #define FLASH_PAGE_SIZE 2048

View File

@@ -142,11 +142,21 @@ class Programmer():
this command will tell the token to boot directly to the st DFU this command will tell the token to boot directly to the st DFU
so it can be reprogrammed. Warning, you could brick your device. so it can be reprogrammed. Warning, you could brick your device.
""" """
if self.exchange == self.exchange_hid: soloboot = False
self.send_only_hid(SoloBootloader.HIDCommandEnterSTBoot, '') try:
p.version()
soloboot = True
except CtapError as e:
if e.code == CtapError.ERR.INVALID_COMMAND:
pass
else: else:
raise (e)
if soloboot or self.exchange == self.exchange_u2f:
req = Programmer.format_request(SoloBootloader.st_dfu) req = Programmer.format_request(SoloBootloader.st_dfu)
self.send_only_hid(SoloBootloader.HIDCommandBoot, req) self.send_only_hid(SoloBootloader.HIDCommandBoot, req)
else:
self.send_only_hid(SoloBootloader.HIDCommandEnterSTBoot, '')
def program_file(self,name): def program_file(self,name):
@@ -235,7 +245,7 @@ if __name__ == '__main__':
parser.add_argument("--reset-only", action="store_true", help = 'Don\'t write anything, try to boot without a signature.') parser.add_argument("--reset-only", action="store_true", help = 'Don\'t write anything, try to boot without a signature.')
parser.add_argument("--reboot", action="store_true", help = 'Tell bootloader to reboot.') parser.add_argument("--reboot", action="store_true", help = 'Tell bootloader to reboot.')
parser.add_argument("--enter-bootloader", action="store_true", help = 'Don\'t write anything, try to enter bootloader. Typically only supported by Solo Hacker builds.') parser.add_argument("--enter-bootloader", action="store_true", help = 'Don\'t write anything, try to enter bootloader. Typically only supported by Solo Hacker builds.')
parser.add_argument("--st-dfu", action="store_true", help = 'Don\'t write anything, try to enter ST DFU. Warning, you could brick your Solo if you overwrite everything. Make sure to reprogram the option bytes just to be safe.') parser.add_argument("--st-dfu", action="store_true", help = 'Don\'t write anything, try to enter ST DFU. Warning, you could brick your Solo if you overwrite everything. You should reprogram the option bytes just to be safe (boot to Solo bootloader first, then run this command).')
args = parser.parse_args() args = parser.parse_args()
print() print()