Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Destroy memory

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Memen

Bascom Member



Joined: 06 May 2016
Posts: 13

blank.gif
PostPosted: Sat Aug 10, 2019 9:03 pm    Post subject: Destroy memory Reply with quote

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
View user's profile AIM Address
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Aug 10, 2019 10:50 pm    Post subject: Re: Destroy memory Reply with quote

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
View user's profile
Memen

Bascom Member



Joined: 06 May 2016
Posts: 13

blank.gif
PostPosted: Sun Aug 11, 2019 7:05 am    Post subject: Reply with quote

Clone defense
Back to top
View user's profile AIM Address
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sun Aug 11, 2019 7:14 am    Post subject: Reply with quote

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
View user's profile
Memen

Bascom Member



Joined: 06 May 2016
Posts: 13

blank.gif
PostPosted: Sun Aug 11, 2019 7:49 am    Post subject: Reply with quote

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
View user's profile AIM Address
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Aug 11, 2019 9:52 am    Post subject: Reply with quote

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
View user's profile
Memen

Bascom Member



Joined: 06 May 2016
Posts: 13

blank.gif
PostPosted: Sun Aug 11, 2019 10:17 am    Post subject: Reply with quote

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
View user's profile AIM Address
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Aug 11, 2019 10:41 am    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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