MC9S12XEP 的bootloader 归纳总结 两个要点:
1.ROM不要重叠,bootloader的代码与用户应用代码不要重叠。各自设置各自的ROM区域;
2.bootloader有一部分代码是在RAM里运行的,所以RAM也不能重叠,RAM可以分为如下三种:
a.) 堆栈区域;
b.)bootloader代码变量区域;
c.)bootloader 中断地址;
上述三种RAM类型,不可重叠。
先说bootloader部分,需要处理的步骤如下:
a). 为 bootloader 划出ROM,(.prm文件修改)
b). 为bootloader ROM里再划出一块区域,程序运行时,这个区域里的CODE会被复制到RAM里执行;(.prm文件修改)
c).中断向量映射。地址保存在RAM里,所以,这个RAM与上面存放代码的RAM以及程序运行时的RAM都不要重叠;(.c文件,程序里定义)
d).需要在RAM运行的代码,拷贝到RAM里; (.c文件,程序里操作)
下面是一个project.prm 文件,(这里的地址值用的是 逻辑地址)
INIT _BootStart
NAMES END
SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
/*
Area 0x3800-0x38FF is reserved for stack. Stack pointer is initialized in StartS12X.s file
to initail value 0x3900.
Area 0x3900-0x3CFF is used for standard purposes.
Area 0x3D00-0x3EFF is used for functions that must be executed from RAM memory. These functions
are stored in flash memory in RAM_CODE_SEG (see below) and are copied to RAM memory after startup.
Area 0x3F00-0x3FFF is used for interrupt vector table.
*/
RAM = READ_WRITE 0x3000 TO 0x36FF;
RAM_CODE_SEG = READ_ONLY 0xFA00 TO 0xFEFF RELOCATE_TO 0x3700;
ROM_F000 = READ_ONLY 0xE000 TO 0xF9FF;
END
PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
ROM_VAR,
STRINGS,
DEFAULT_ROM,
NON_BANKED INTO ROM_F000;
DEFAULT_RAM INTO RAM;
RAM_CODE INTO RAM_CODE_SEG;
END
ENTRIES
flash_array
END
STACKSIZE 0x100
//handle all reset vectors
VECTOR 0 _BootStart
VECTOR 1 _BootStart
VECTOR 2 _BootStart
文件里有这样的字样
RAM = READ_WRITE 0x3000 TO 0x36FF;
RAM_CODE_SEG = READ_ONLY 0xFA00 TO 0xFEFF RELOCATE_TO 0x3700;
ROM_F000 = READ_ONLY 0xE000 TO 0xF9FF;
RAM = READ_WRITE 0X3000 TO 0X36FF 表示代码运行时,可以自由支配使用的RAM区域;
其中,0X3000 需要与 .S文件里的 堆栈 设置 相匹配。在.S文件里,如下
;********************************************************************************
;* Freescale Semiconductor Inc.
;* (c) Copyright 2004-2005 Freescale Semiconductor, Inc.
;* ALL RIGHTS RESERVED.
;********************************************************************************
;Services performed by FREESCALE in this matter are performed AS IS and without
;any warranty. CUSTOMER retains the final decision relative to the total design
;and functionality of the end product. FREESCALE neither guarantees nor will be
;held liable by CUSTOMER for the success of this project.
;FREESCALE DISCLAIMS ALL WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY INCLUDING,
;BUT NOT LIMITED TO, IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
;A PARTICULAR PURPOSE ON ANY HARDWARE, SOFTWARE OR ADVISE SUPPLIED TO THE PROJECT
;BY FREESCALE, AND OR NAY PRODUCT RESULTING FROM FREESCALE SERVICES. IN NO EVENT
;SHALL FREESCALE BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF
;THIS AGREEMENT.
;
;CUSTOMER agrees to hold FREESCALE harmless against any and all claims demands or
;actions by anyone on account of any damage, or injury, whether commercial,
;contractual, or tortuous, rising directly or indirectly as a result of an advise
;or assistance supplied CUSTOMER in connection with product, services or goods
;supplied under this Agreement.
;********************************************************************************
;* File StartS12X.s
;* Owner b01802
;* Version 1.0
;* Date Dec-02-2010
;* Classification General Business Information
;* Brief Startup file
;********************************************************************************
;* Detailed Description:
;*
;* Tested on: DEMO9S12XSFAME, EVB9S12XEP100
;*
;* The bootloder handles all reset vectors. This startup file makes a decision
;* whether the bootloader or user application is executed.
;********************************************************************************
;Revision History:
;Version Date Author Description of Changes
;1.0 Dec-02-2010 b01802 Initial version
;********************************************************************************
;
xref main
;
xdef _BootStart
;
AppResetVect: equ $effe ; here is stored reset vector of user application
StackTop: equ $3000
_BootStart:
; -----------------------------------------------------------------------------
movb #$01, $025C ; enable pull up resistor on PP0 (or we can use external one)
nop ;wait a few cycles for stabilization of the signal
nop
nop
nop
nop
brclr $0259, $01, GoBoot ; if PP0 == 0 then start the bootloader
; if PP0 == 1 then start the application
movb #$00, $025C ; disable pull up resistor on pin PP0 - restore default state
; -----------------------------------------------------------------------------
ldd AppResetVect
cpd #$ffff
beq GoBoot ; if the application reset vector is not available
; then start the bootloader
ldx AppResetVect
jmp 0,x ; jump to the application
GoBoot:
lds #StackTop
jmp main
;********************************************************************************
.S文件里的 “ StackTop: equ $3000 ” 表示堆栈值是 0X3000 与上述的.prm文件里的 RAM = READ_WRITE 0X3000 TO 0X36FF 相对应,因为.prm文件里定义了堆栈层数是是0X100("STACKSIZE 0x100"),所以 堆栈的地址区域是 0X2F00 ~ 0X3000 ,显然这个区域是专用的.