s3c2440开发板支持两种启动方式,一种是 nandflash 启动,此时 nandflash 中的前 4K 内容会由硬件自动拷贝至片内 SRAM 4K 内存中,这片内 4K 内存会被 map 到 nGCS0 也就是 bank0 ,起始地址为0 。如果是 Nor 启动,norflash 也是被接在 nGCS0 ban0 上的,Norflash 可以直接被读取,因此 cpu 从 Norflash 的 0 地址开始运行。一直被人忽略的一点,nor启动时,片内 sram 4K 内存的起始地址为 0x4000 0000 .
使用 Jlink 可以将文件下载到 sram ,那么,我们就可以在 sram 执行一个初始化 sdram 的程序,初始化更大的可用内存空间。然后,就可以使用 Jlink 向 sdram 中下载程序。如果说,我们想烧写文件到 nandflash 或者 norflash ,可以自己来写 nandflash norflash 的烧写函数,或者直接利用 Uboot 来烧写。
一、烧写 nandflash
将跳线开关拨到 nand 启动那一侧!需要的文件:
1、init.bin 用来初始化 sdram
2、uboot_no_initsdram ,去掉初始化 sdram 部分的 uboot
3、要烧写的文件
1、init.bin
@******************************************************************************
@ File:init.S
@ 功能:初始化sdram
@******************************************************************************
.text
.global _start
_start:
// 关看门狗
ldr r0,=0x53000000
mov r1,#0
str r1,[r0]
// 屏蔽中断
mov r1, #0xffffffff
ldr r0, =0x4A000008
str r1, [r0]
ldr r1, =0x3ff
ldr r0, =0x4A00001C
str r1, [r0]
// 初始化内存
MOV R0,#0x48000000
ADRL R1,mem_cfg_val
@STR [R1],[R0],#4
MOV R4,#0
1:
LDR R3,[R1],#4
STR R3,[R0],#4
ADD R4,R4,#1
CMP R4,#13
BNE 1b
loop:
b loop
.align 4
mem_cfg_val:
@ 存储控制器13个寄存器的设置值
.long 0x22011110 @ BWSCON
.long 0x00000700 @ BANKCON0
.long 0x00000700 @ BANKCON1
.long 0x00000700 @ BANKCON2
.long 0x00000700 @ BANKCON3
.long 0x00000700 @ BANKCON4
.long 0x00000700 @ BANKCON5
.long 0x00018005 @ BANKCON6
.long 0x00018005 @ BANKCON7
.long 0x008C07A3 @ REFRESH
.long 0x000000B1 @ BANKSIZE
.long 0x00000030 @ MRSRB6
.long 0x00000030 @ MRSRB7
makefile
init_sdram.bin : init_sdram_elf
arm-linux-objcopy -O binary -S init_sdram_elf init_sdram.bin
arm-linux-objdump -D -m arm init_sdram_elf > init_sdram.dis
init_sdram_elf : init.o
arm-linux-ld -Ttext 0x00000000 -g init.o -o init_sdram_elf
init.o : init.S
arm-linux-gcc -g -c -o init.o init.S
clean:
rm -f init_sdram.dis init_sdram.bin init_sdram_elf *.o
注意这里的连接地址是 0 地址,因为 nand 启动时,片内 sram 的起始地址为 0
2、uboot_no_initsdram ,去掉初始化 sdram 部分的 uboot
这里我是用的是 u-boot-1.1.6.tar.bz2 源码,以及韦东山老师提供的补丁文件 u-boot-1.1.6_jz2440.patch (适用于绝大多数2440开发板),将两个文件放于同一目录下
tar jxvf u-boot-1.1.6.tar.bz2 解压缩
cd u-boot-1.1.6
patch -p < ../u-boot-1.1.6_jz2440.patch
make 100ask24x0_config
修改 cpu/arm920t/start.S 注释掉 bllowlevel_init
make
3、jink连接好开发板,上电,打开 j-link commonder ,输入 usb 检查连接状况
如图所示,能够识别出 id 以及ARM,Architecure 4T 表示正常
speed 12000
loadbin xxx_init.bin 0 将初始化 sdram 的文件通过Jink拷贝到片内sram
setpc 0
g
h//暂停cpu
loadbin u-boot_no_init_sdram.bin 33f80000 //33f80000为uboot的连接地址,不能更改
setpc 33f80000
g
此时,不出意外,串口上可以看到 Uboot 的打印信息了
此时你可以借助于 tftp nfs 来将文件下载到内存,也可以继续使用 jlink ,文件较小的话直接使用jlink比较方便
h
loadbin uboot.bin 30000000
g
nand erase 0x60000 0x500000//0x500000 5M 对于uboot来说应该够大了
nand write 0x30000000 0x60000 0x500000 //至此,通过jink 烧写 uboot 完成
二、jink 烧写 norflash
如果 Uboot 支持烧写 norflash 的话,我们同样可以采取上述方法,只不过要把跳线拨到nor启动那一侧,初始化 sram 程序的连接地址改为 0x40000000 ,将它 拷贝到 0x40000000 处去。
但是韦老大的uboot貌似不支持,我们直接借助于 jink 来烧写更直接,打开jink-arm
新建一个 project , option->projectsetting
General 以及 Target interface 保持默认
cpu 选项卡,core 选择 arm9 ,勾选 use target ram addr 40000000 4K
40000000 是nor启动时片内sram的地址,4K为大小 ,delet 下边那个框里的 reset 如图
flash 选项卡,首先去掉 auto xxx 选项的钩,然后 select flash device ,根据自己的norflash型号选择,睁大眼看看自己板子上的norflash型号
在烧写之前呢,我们最好想前边烧写nandflash一样,先把初始化程序拷贝到sram,初始化一下sdram,关看门狗,屏蔽中断,否则在烧写较大文件的过程中必然失败。
注意,此时初始化程序的连接地址为 0x40000000
@******************************************************************************
@ File:init.S
@ 功能:初始化sdram
@******************************************************************************
.text
.global _start
_start:
// 关看门狗
ldr r0,=0x53000000
mov r1,#0
str r1,[r0]
// 屏蔽中断
mov r1, #0xffffffff
ldr r0, =0x4A000008
str r1, [r0]
ldr r1, =0x3ff
ldr r0, =0x4A00001C
str r1, [r0]
// 初始化内存
MOV R0,#0x48000000
ADRL R1,mem_cfg_val
@STR [R1],[R0],#4
MOV R4,#0
1:
LDR R3,[R1],#4
STR R3,[R0],#4
ADD R4,R4,#1
CMP R4,#13
BNE 1b
loop:
b loop
.align 4
mem_cfg_val:
@ 存储控制器13个寄存器的设置值
.long 0x22011110 @ BWSCON
.long 0x00000700 @ BANKCON0
.long 0x00000700 @ BANKCON1
.long 0x00000700 @ BANKCON2
.long 0x00000700 @ BANKCON3
.long 0x00000700 @ BANKCON4
.long 0x00000700 @ BANKCON5
.long 0x00018005 @ BANKCON6
.long 0x00018005 @ BANKCON7
.long 0x008C07A3 @ REFRESH
.long 0x000000B1 @ BANKSIZE
.long 0x00000030 @ MRSRB6
.long 0x00000030 @ MRSRB7
init_sdram.bin : init_sdram_elf
arm-linux-objcopy -O binary -S init_sdram_elf init_sdram.bin
arm-linux-objdump -D -m arm init_sdram_elf > init_sdram.dis
init_sdram_elf : init.o
arm-linux-ld -Ttext 0x40000000 -g init.o -o init_sdram_elf
init.o : init.S
arm-linux-gcc -g -c -o init.o init.S
clean:
rm -f init_sdram.dis init_sdram.bin init_sdram_elf *.o
speed 12000
loadbin init.bin 0x40000000
setpc 40000000
g
h
此时,初始化工作已经完毕,开始烧写
open 要烧写到 nor flash的文件,指定烧写地址一般为0,点击 Target connect ,然后 program OK
其实,初始化的工作可以在 projectsetting 下边那个框框里来做,我比较懒,直接用前边的初始化程序来自己初始化,都是一样的。
jlink 的功能不局限于此,用它来进行裸机调试也是十分方便的,openjtag 需要借助于 openocd ,jlink 只需要一个jlink commonder ,这个后边调试的时候再细写吧。
以下转载自:http://blog.csdn.net/liushaowei2008/article/details/7721511
JLINK v8命令集
Available commands are:
有效的命令如下:
(本人简单翻译了一下如有错误还请指出,谢谢各位网友)
----------------------
f Firmware info(显示固件信息)
h halt(暂停CPU)
g go(运行)
Sleep Waits the given time (in milliseconds). Syntax: Sleep (睡眠多少毫秒)
s Single step the target chip(单步调试目标芯片)
st Show hardware status(显示硬件状态)
hwinfo Show hardware info(显示硬件信息)
mem Read memory. Syntax: mem , (hex)(读内存)
mem8 Read 8-bit items. Syntax: mem8 , (hex)(读内存8字节)
mem16 Read 16-bit items. Syntax: mem16 , (hex)mem32 Read 32-bit items. Syntax: mem32 , (hex)
w1 Write 8-bit items. Syntax: w1 , (hex)(写内存8字节)
w2 Write 16-bit items. Syntax: w2 , (hex)(读内存16字节)
w4 Write 32-bit items. Syntax: w4 , (hex)(读内存32字节)
wm Write test words. Syntax: wm
is Identify length of scan chain select register
ms Measure length of scan chain. Syntax: ms
mr Measure RTCK react time. Syntax: mr
q Quit(推出)
qc Close JLink connection and quit(关闭jlink连接,并退出)
r Reset target (RESET)(重启目标)
rx Reset target (RESET). Syntax: rx (延时重启)
RSetType Set the current reset type. Syntax: RSetType
Regs Display contents of registers(显示寄存器信息)
wreg Write register. Syntax: wreg , (写继承器)
SetBP Set breakpoint. Syntax: SetBP [A/T] [S/H](设置断点)
SetWP Set Watchpoint. Syntax: [R/W] [ [] [A-Mask]](设置监视点)
ClrBP Clear breakpoint. Syntax: ClrBP (清除断点)
ClrWP Clear watchpoint. Syntax: ClrWP (清楚监视点)
VCatch Write vector catch. Syntax: VCatch
loadbin Load binary file into target memory.(下载bin文件到目标内存)
Syntax: loadbin ,
savebin Saves target memory into binary file.(保存BIN文件)
Syntax: savebin , ,
SetPC Set the PC to specified value. Syntax: SetPC (设置PC(r15)寄存器)
le Change to little endian mode(设置成小端模式)
be Change to big endian mode(设置成大端模式)
log Enables log to file. Syntax: log
unlock Unlocks a device. Syntax: unlock
Type unlock without to get a list
of supported device names.
nRESET has to be connected
---- CP15 ------------
rce Read CP15. Syntax: rce , , , (读CP15)
wce Write CP15. Syntax: wce , , , , (写CP15)
---- ICE -------------
Ice Show state of the embedded ice macrocell (ICE breaker)
ri Read Ice reg. Syntax: ri (hex)
wi Write Ice reg. Syntax: wi , (hex)
---- ETM -------------
etm Show ETM status
re Read ETM reg. Syntax: re
we Write ETM reg. Syntax: we , (hex)
es Start trace
---- ETB -------------
etb Show ETB status
rb Read ETB register. Syntax: rb
wb Write ETB register. Syntax: wb , (hex)
---- TRACE -----------
TAddBranch TRACE - Add branch instruction to trace buffer. Paras:,
TAddInst TRACE - Add (non-branch) instruction to trace buffer. Syntax:
TClear TRACE - Clear buffer
TSetSize TRACE - Set Size of trace buffer
TSetFormat TRACE - SetFormat
TSR TRACE - Show Regions (and analyze trace buffer)
TStart TRACE - Start
TStop TRACE - Stop
---- SWO -------------
SWOSpeed SWO - Show supported speeds
SWOStart SWO - Start
SWOStop SWO - Stop
SWOStat SWO - Display SWO status
SWORead SWO - Read and display SWO data
SWOShow SWO - Read and analyze SWO data
SWOFlush SWO - Flush data
---- File I/O --------
fwrite Write file to emulator
fread Read file from emulator
fshow Read and display file from emulator
fdelete Delete file on emulator
fsize Display size of file on emulator
---- Test ------------
thg Run go/halt 1000 times
ts Run step 1000 times
testwspeed Test download speed. Syntax: testwspeed [ []]
testrspeed Test upload speed. Syntax: testrspeed [ [] [ s>]]
testcspeed Test CPU speed. Syntax: testcspeed []
---- JTAG ------------
Config Set number of IR/DR bits before ARM device.
Syntax: Config ,
speed Set JTAG speed. Syntax: speed |auto|adaptive, e.g. speed 2000,
speed a
i Read JTAG Id (Host CPU)
wjc Write JTAG command (IR). Syntax: wjc (hex)
wjd Write JTAG data (DR). Syntax: wjd (hex), (dec)
RTAP Reset TAP Controller using state machine (111110)
wjraw Write Raw JTAG data. Syntax: wjraw , ,
rt Reset TAP Controller (nTRST)
---- JTAG-Hardware ---
c00 Create clock with TDI = TMS = 0
c Clock
0 Clear TDI
1 Set TDI
t0 Clear TMS
t1 Set TMS
trst0 Clear TRST
trst1 Set TRST
r0 Clear RESET
r1 Set RESET
---- Connection ------
usb Connect to J-Link via USB. Syntax: usb , where port is 0..3
ip Connect to J-Link ARM Pro or J-Link TCP/IP Server via TCP/IP.
Syntax: ip
---- Configuration ---
si Select target interface. Syntax: si ,
where 0=JTAG and 1=SWD.
power Switch power supply for target. Syntax: power [perm],
where State is either On or Off. Example: power on perm
wconf Write configuration byte. Syntax: wconf ,
rconf Read configuration bytes. Syntax: rconf
usbaddr Assign usb address to the connected J-Link: Syntax: usbaddr =
ipaddr Show/Assign IP address and subnetmask of/to the connected J-Link.
gwaddr Show/Assign network gateway address of/to the connected J-Link.
dnsaddr Show/Assign network DNS server address of/to the connected J-Link.
conf Show configuration of the connected J-Link.
ecp Enable the J-Link control panel.
calibrate Calibrate the target current measurement.
selemu Select a emulator to communicate with,
from a list of all emulators which are connected to the host
The interfaces to search on, can be specified
Syntax: selemu [ ...]
ShowEmuList Shows a list of all emulators which are connected to the host.
The interfaces to search on, can be specified.
Syntax: ShowEmuList [ ...]
----------------------
NOTE: Specifying a filename in command line
will start J-Link Commander in script mode.
几个常用命令:
usb--------连接目标板
r----------重启目标板
halt-------停止cpu运行的程序
loadbin----加载可执行的二进制文件
g----------跳到代码段地址执行
s----------单步执行(调试用)
setpc-----设置pc寄存器的值(调试用)
setbp-----设置断点
Regs-------读寄存器组织
wreg-------写寄存器
mem--------读内存
w4---------写内存
power off mmu---关闭mmu,这个对于裸板调试很重要
w4 cpsr,0x0000001f------切换到系统模式
speed------设置jtag的传输速率
rce 0,c0,c0,0-----设置cp15寄存器的第1个寄存器为0