protection
This commit is contained in:
@@ -3,10 +3,15 @@
|
||||
* src/main.c (flash_mass_erase_and_exec, good_bye): New.
|
||||
(main): Call good_bye.
|
||||
|
||||
* tool/gnuk_upgrade.py (regnual.protect): New.
|
||||
(main): Call regnual.protect().
|
||||
|
||||
* regnual/regnual.c (regnual_setup): Don't call flash_write here.
|
||||
(regnual_ctrl_write_finish): But call here.
|
||||
(USB_REGNUAL_RESULT): New.
|
||||
|
||||
* regnual/sys.c (flash_protect): New.
|
||||
|
||||
2012-05-22 Niibe Yutaka <gniibe@fsij.org>
|
||||
|
||||
* src/configure (../regnual/sys.h): Create symblic link.
|
||||
|
||||
@@ -33,7 +33,7 @@ extern void *memset (void *s, int c, size_t n);
|
||||
extern void set_led (int);
|
||||
extern uint8_t _flash_start, _flash_end;
|
||||
extern int flash_write (uint32_t dst_addr, const uint8_t *src, size_t len);
|
||||
extern int flash_protect (uint16_t protection);
|
||||
extern int flash_protect (void);
|
||||
extern void nvic_system_reset (void);
|
||||
|
||||
|
||||
@@ -154,8 +154,8 @@ static void regnual_ctrl_write_finish (uint8_t req, uint8_t req_no,
|
||||
|
||||
result = flash_write (dst_addr, mem, 256);
|
||||
}
|
||||
else if (req_no == USB_REGNUAL_PROTECT && index == 0)
|
||||
result = flash_protect (value);
|
||||
else if (req_no == USB_REGNUAL_PROTECT && value == 0 && index == 0)
|
||||
result = flash_protect ();
|
||||
else if (req_no == USB_REGNUAL_FINISH && value == 0 && index == 0)
|
||||
nvic_system_reset ();
|
||||
}
|
||||
@@ -202,11 +202,9 @@ regnual_setup (uint8_t req, uint8_t req_no,
|
||||
if (dst_addr + 256 <= (uint32_t)&_flash_end)
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
else if (req_no == USB_REGNUAL_PROTECT && len == 0 && index == 0)
|
||||
{
|
||||
if (value == 0)
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
else if (req_no == USB_REGNUAL_PROTECT && len == 0
|
||||
&& value == 0 && index == 0)
|
||||
return USB_SUCCESS;
|
||||
else if (req_no == USB_REGNUAL_FINISH && len == 0
|
||||
&& value == 0 && index == 0)
|
||||
return USB_SUCCESS;
|
||||
|
||||
@@ -430,11 +430,39 @@ flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define FLASH_OPTION_BYTE_RDP 0x1ffff800
|
||||
|
||||
int
|
||||
flash_protect (uint16_t protection)
|
||||
flash_protect (void)
|
||||
{
|
||||
/* Not yet implemented */
|
||||
return 1;
|
||||
int status;
|
||||
uint16_t rdp;
|
||||
|
||||
status = flash_wait_for_last_operation (FLASH_PROGRAM_TIMEOUT);
|
||||
|
||||
intr_disable ();
|
||||
if (status == FLASH_COMPLETE)
|
||||
{
|
||||
FLASH->OPTKEYR = FLASH_KEY1;
|
||||
FLASH->OPTKEYR = FLASH_KEY2;
|
||||
|
||||
FLASH->CR |= FLASH_CR_OPTER;
|
||||
FLASH->CR |= FLASH_CR_STRT;
|
||||
|
||||
status = flash_wait_for_last_operation (FLASH_PROGRAM_TIMEOUT);
|
||||
if (status != FLASH_TIMEOUT)
|
||||
FLASH->CR &= ~FLASH_CR_OPTER;
|
||||
}
|
||||
intr_enable ();
|
||||
|
||||
if (status != FLASH_COMPLETE)
|
||||
return 0;
|
||||
|
||||
rdp = *(volatile uint16_t *)FLASH_OPTION_BYTE_RDP;
|
||||
if (rdp == 0x00ff)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct SCB
|
||||
|
||||
@@ -105,6 +105,17 @@ class regnual:
|
||||
if r_value == 0:
|
||||
print "failure"
|
||||
|
||||
def protect(self):
|
||||
self.__devhandle.controlMsg(requestType = 0x40, request = 4,
|
||||
value = 0, index = 0, buffer = None,
|
||||
timeout = 10000)
|
||||
res = self.__devhandle.controlMsg(requestType = 0xc0, request = 2,
|
||||
value = 0, index = 0, buffer = 4,
|
||||
timeout = 10000)
|
||||
r_value = ((res[3]*256 + res[2])*256 + res[1])*256 + res[0]
|
||||
if r_value == 0:
|
||||
print "protect failure"
|
||||
|
||||
def finish(self):
|
||||
self.__devhandle.controlMsg(requestType = 0x40, request = 5,
|
||||
value = 0, index = 0, buffer = None,
|
||||
@@ -379,6 +390,7 @@ def main(passwd, data_regnual, data_upgrade):
|
||||
print "%08x:%08x" % mem_info
|
||||
print "Downloading the program"
|
||||
reg.download(mem_info[0], data_upgrade)
|
||||
reg.protect()
|
||||
reg.finish()
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user