📄 at91sam9260_demo_linux_dataflash.tcl
字号:
# ----------------------------------------------------------------------------
# ATMEL Microcontroller Software Support - ROUSSET -
# ----------------------------------------------------------------------------
# Copyright (c) 2006, Atmel Corporation
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the disclaiimer below.
#
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the disclaimer below in the documentation and/or
# other materials provided with the distribution.
#
# Atmel's name may not be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
# DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------------
################################################################################
# proc uboot_env: Convert u-boot variables in a string ready to be flashed
# in the region reserved for environment variables
################################################################################
proc set_uboot_env {nameOfLstOfVar} {
upvar $nameOfLstOfVar lstOfVar
# sector size is the size defined in u-boot CFG_ENV_SIZE
set sectorSize [expr 0x4000 - 4]
set strEnv [join $lstOfVar "\0"]
while {[string length $strEnv] < $sectorSize} {
append strEnv "\0"
}
set strCrc [binary format i [::vfs::crc $strEnv]]
return "$strCrc$strEnv"
}
################################################################################
# Sanity Checks:
# Checks the mapping regarding the kernel and the disk size
################################################################################
proc is_mapping_correct {} {
variable df_mapping
variable bootstrapSize
variable ubootSize
variable kernelSize
variable diskSize
# ### Check the offset in DataFlash ###
# Check if there is enough space for the bootstrap before uboot environment variables
if {[expr ($df_mapping(bootstrapOff) + $bootstrapSize)] > $df_mapping(ubootEnvOff)} {
error "-F- The area for the bootstrap in DataFlash is not large enough $df_mapping(bootstrapSize)"
}
# Check if there is enough space for the uboot before Linux Kernel
if {[expr ($df_mapping(ubootOff) + $ubootSize)] > $df_mapping(kernelOff)} {
error "-F- The area for the uboot in DataFlash is not large enough $ubootSize"
}
# Check if there is enough space for the kernel before the ramdisk
if {[expr ($df_mapping(kernelOff) + $kernelSize)] > $df_mapping(diskOff)} {
error "-F- The area for the kernel in DataFlash is not large enough $df_mapping(kernelSize)"
}
# ### Check the position in sdram ###
if {[expr ($df_mapping(diskSdram) + $diskSize)] > $df_mapping(kernelSdram)} {
error "-F- The area for the disk in SDRAM is not large enough $df_mapping(diskSize)"
}
}
################################################################################
# Main script: Load the linux demo in DataFlash,
# Update the environment variables
################################################################################
array set df_mapping {
bootstrapFileName "dataflash_at91sam9260ek.bin"
kernelFileName "linux-2.6.18-rc4-sam9260.img"
diskFileName "armv5l-uclibc-sam9260"
ubootEnvFileName "tmp.bin"
baseAddr 0xD0000000
bootstrapOff 0x00000000
ubootOff 0x00008000
ubootEnvOff 0x00004000
kernelOff 0x00030000
diskOff 0x00300000
kernelSdram 0x21500000
diskSdram 0x21100000
}
set binPath [lindex $::argv 3]
set ubootFileName [lindex $::argv 4]
puts "u-boot file: $ubootFileName"
set bootstrapFile [file join $binPath $df_mapping(bootstrapFileName)]
set ubootFile [file join $binPath $ubootFileName]
set kernelFile [file join $binPath $df_mapping(kernelFileName)]
set diskFile [file join $binPath $df_mapping(diskFileName)]
set bootstrapSize [format "0x%08X" [file size $df_mapping(bootstrapFileName)]]
set ubootSize [format "0x%08X" [file size $ubootFileName]]
set kernelSize [format "0x%08X" [file size $df_mapping(kernelFileName)]]
set diskSize [format "0x%08X" [file size $df_mapping(diskFileName)]]
puts "diskSize: $diskSize"
set kernelAddr [format "0x%08X" [expr $df_mapping(baseAddr) + $df_mapping(kernelOff)]]
set diskAddr [format "0x%08X" [expr $df_mapping(baseAddr) + $df_mapping(diskOff)]]
puts "-I- === Performs sanity checks==="
if { [catch {is_mapping_correct} eid] } {
puts "$eid"
exit 1
}
catch {is_mapping_correct}
lappend u_boot_variables \
"bootdelay=3" \
"baudrate=115200" \
"stdin=serial" \
"stdout=serial" \
"stderr=serial" \
"bootcmd=\
cp.b $kernelAddr $df_mapping(kernelSdram) $kernelSize;\
cp.b $diskAddr $df_mapping(diskSdram) $diskSize;\
bootm $df_mapping(kernelSdram)"
puts "-I- === Initialize the DataFlash access ==="
DATAFLASH::SelectDataflash AT91C_SPI0_CS1
puts "-I- === Erase all the DataFlash blocs and test the erasing ==="
DATAFLASH::EraseAllDataFlash
puts "-I- === Load the bootstrap: dataflash_at91sam9260ek in the first sector ==="
DATAFLASH::SendBootFile $bootstrapFile
puts "-I- === Load the u-boot in the next sectors ==="
send_file {DataFlash AT45DB/DCB} "$ubootFile" $df_mapping(ubootOff) 0
puts "-I- === Load the u-boot environment variables ==="
set fh [open "$df_mapping(ubootEnvFileName)" w]
fconfigure $fh -translation binary
puts -nonewline $fh [set_uboot_env u_boot_variables]
close $fh
send_file {DataFlash AT45DB/DCB} "$df_mapping(ubootEnvFileName)" $df_mapping(ubootEnvOff) 0
puts "-I- === Load the Kernel image ==="
send_file {DataFlash AT45DB/DCB} "$df_mapping(kernelFileName)" $df_mapping(kernelOff) 0
puts "-I- === Load the linux file system ==="
send_file {DataFlash AT45DB/DCB} "$df_mapping(diskFileName)" $df_mapping(diskOff) 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -