Hi,
I am trying to switch from the firmware in block(0,1) to another firmware in block(2,3).
My switching function always trigger an illegal access exception and i don't know why :-(
I am posting my function below, could anyone tell me whats wrong with my code? Thanks.
---------------------------------------------------------------------------------------------------------------------------------
My function to switch from block (0,1) to block(2,3):
extern void switch_entry(void);
void boot_switch_to_block_2(void){
// Set block 2,3 size to 0
DecRegs.MFBALR18.bit.BLOCK_SIZE = 0;
DecRegs.MFBALR19.bit.BLOCK_SIZE = 0;
// Move block 0,1 to backup address
DecRegs.MFBALR1.bit.ADDRESS = 0x10000 >> 10;
DecRegs.MFBALR17.bit.ADDRESS = 0x18000 >> 10;
// Move block 2,3 to boot address
DecRegs.MFBALR18.bit.ADDRESS = 0;
DecRegs.MFBALR19.bit.ADDRESS = 0x8000 >> 10;
// Set block 2,3 size back to 32K
DecRegs.MFBALR18.bit.BLOCK_SIZE = 6;
DecRegs.MFBALR19.bit.BLOCK_SIZE = 6;
// Software reset
switch_entry();
}
where switch_entry is a global label in load_UCD3138128.asm
Case handler in SWI:
case 16:
if(arg1 == TRUE){
// Copy function to RAM
memcpy((void*)program_area,(void*)boot_switch_to_block_0_start,sizeof(program_area));
// call function
boot_switch_to_block_0();
}
else{
// Copy function to RAM
memcpy((void*)program_area,(void*)boot_switch_to_block_2_start,sizeof(program_area));
// call function
boot_switch_to_block_2();
}
break;
Modified load_UCD3138128.asm:
.global _switch_entry
rom_main .equ 0xffffa4dc
.sect ".vectors"
.state32
B c_int00
B _undefined_instruction_exception
B _software_interrupt
B _abort_prefetch_exception
B _abort_data_fetch_exception
B _abort_prefetch_exception
B _standard_interrupt
B _fast_interrupt
_switch_entry
B switch_image_stack_fix
.align 4
.sect ".text"
.state32
switch_image_stack_fix
LDR r13, c_sup_stack_top
MRS r1,spsr
BIC r1,r1,#0x20
MRS r0,cpsr
BIC r0,r0,#0x1F
ORR r0,r0,#0x1F
MSR cpsr_cf,r0
ldr r13,c_user_stack_top
MSR cpsr_cf,r1
B _c_int00