View previous topic :: View next topic |
Author |
Message |
Memen
Joined: 06 May 2016 Posts: 13
|
Posted: Sat Aug 10, 2019 9:03 pm Post subject: Destroy memory |
|
|
Hello All!
Sorry for my translation.
There is a code: http://cxem.net/mc/book65.php
$regfile = "m328pbdef.dat"
:
.
rjmp flush_mem ;запускаем отчистку FLASH-памяти
.
; Код для очистки FLASH-памяти программ
.org FLASHEND - 12
flush_mem:
ldi ZH,high(-2*PAGESIZE) ;инициализируем указателю Z
ldi ZL,low(-2*PAGESIZE)
fm1: in R16,SPMCR ;ожидаем пока не закончится действие
sbrc R16,SPMEN ;предыдущая инструкции spm
rjmp fr1
fm2: sbic EECR,EEWE ;ожидаем пока не закончится
rjmp fr2 ;запись в EEPROM-память
subi ZL,low(-2*PAGESIZE) ;увеличиваем текущий адрес
sbci ZH,high(-2*PAGESIZE) ;на величину PAGESIZE слов
ldi R16,(1<< PGERS)|(1<< SPMEN)
out SPMCR,R16 ;заносим регистр SPMCR команду стирания
spm ;в течении 4-х циклов выполняем команду spm
rjmp fr1 ;переходим к очистки очередной страницы
The code is located at the end of the memory, and destroys the entire flash.
Help adapt for Bascom.
(BASCOM-AVR version : 2.0.8.2 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Aug 10, 2019 10:50 pm Post subject: Re: Destroy memory |
|
|
Memen wrote: | The code is located at the end of the memory, and destroys the entire flash. |
Why would one do that? |
|
Back to top |
|
|
Memen
Joined: 06 May 2016 Posts: 13
|
Posted: Sun Aug 11, 2019 7:05 am Post subject: |
|
|
Clone defense |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sun Aug 11, 2019 7:14 am Post subject: |
|
|
Hi,
Why not just have a look at the bootloader code, there's an example of writing to Flash.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Memen
Joined: 06 May 2016 Posts: 13
|
Posted: Sun Aug 11, 2019 7:49 am Post subject: |
|
|
I'm trying to put the code at the end of the bootloader.
$asm
.org $3FC0 ' the last page
my_TEST:
.db $55 , $55 , $55 , $55 , $55 , $55 , $55 , $55
$end Asm
I get errors and the size is 101%
Error : 344 Line : 7 Program will overwrite flash memory (or bootloader) [ 564 too long] , in File : C:\MCS\BASCAVR2082\LIB\FP_TRIG.LBX
Error : 80 Line : 161 Code does not fit into target chip , in File : C:\MCS\BASCAVR2082\LIB\MCS.LBX |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Aug 11, 2019 9:52 am Post subject: |
|
|
Memen wrote: | Clone defense |
If fuses don't stop an attacker, your suicide-routine won't do either.
Problem would be also to detect and differentiate an intrusion from normal use, as otherwise legal users will become really unhappy.
Do you believe you are able to write hundred percent reliable detector code, while you are already struggling with this simple cleanup code?
For the actual issue: It's kind of an hen/egg problem.
This cleanup code must reside in loader section, while it actually has no loader functionality, and thus it can not load application code into flash, after it was loaded via ISP.
The solution is to compile the cleanup code with option $loader, manually combine app.hex and cleanup.hex and upload via ISP.
Second option would be to extend a working boot loader with this cleanup code, flash it via ISP and load app.hex with the help of the boot loader. |
|
Back to top |
|
|
Memen
Joined: 06 May 2016 Posts: 13
|
Posted: Sun Aug 11, 2019 10:17 am Post subject: |
|
|
The code needs to be placed at the end of the atmega328pb memory, in the boot sector, after the existing bootloader. Problem in implementation (
Code:
$asm
.org $3E48
.db $55 , $55 , $55 , $55 , $55 , $55 , $55 , $55
$end Asm
Where does the extra code come from?
Last edited by Memen on Sun Aug 11, 2019 10:46 am; edited 1 time in total |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Aug 11, 2019 10:41 am Post subject: |
|
|
Memen wrote: | The code needs to be placed at the end of the atmega328pb memory, in the boot sector, after the existing bootloader. Problem in implementation ( |
Either you did not fully read my reply, or its translation makes it impossible to understand.
If you use a boot loader where you have the sources, add your code there, if no sources are available, then use a Bascom-loader and add it. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|