Friday, May 22, 2009

Debugging Linux on CCS

Though Linux cant be debugged using CCS, by doing some changes to the memory, CCS can be used to debug linux untill is MMC is turned ON. This is most required in board bring up projects.

On compiling linux code we get the image vmlinux in elf32 format. In order to lead this image through CCS this needs to be converted to the .out type.
The kernel image vmlinux, has a start address, VMA and LMA set to 0xC0008000. But 0xC0008000 does not map to a valid loadable address in the DaVinci/OMAP system. So, when vmlinux image is tried to download via CCS on the target, CCS complainsthat the memory map of the target does not match the program address. Hence vmlinux cannot be downloaded to the target directly.To circumvent this problem, the LMA of the vmlinux image is changed from 0xC0008000 to 0x80008000 which maps correctly into the target system memory. This conversion of vmlinux can be done by the script conv-elf-to-out.sh.This also helps in direct debugging of the kernel with ICE without necessarily flashing the kernel into the NOR flash.

conv-elf-to-out.sh
#!/bin/sh
# This shell script converts given input file of elf32-littlearm

# format to output file which is also elf32-littlearm format but
# the LMA (load memory addresses) are shifted by 0x40000000 so
# that it can be downlaodable by CCS on the target. This script
# is used to mainly, convert compiled linux image vmlinux to
# downloadable image vmlinux.out whose LMA starts from 0x80008000
usage()

{
echo ""
echo " Incomplete command line .. missing inputs " ;
echo " Usage : sh conv-elf-to-out.sh " ;
echo " Example : sh conv-elf-to-out.sh /home/linux/vmlinux /home/linux/vmlinux.out" ;
echo ""
exit 0;
}
if [ -z "$1" -o -z "$2" ] ;

then usage
fi
if [ ! -f "$1" ] ;

then echo " File not found : $1 "
exit 0;
fi
echo "Converting "$1" to "$2" "
arm-none-linux-gnueabi-objcopy $1 $2
arm-none-linux-gnueabi-objcopy $(arm_v5t_le-objdump -h $2 awk '$1~/^[0-9]/ && $5 {print $2}' while read s; do echo --change-section-lma $s-0x40000000; done) $2
arm-none-linux-gnueabi-objcopy --set-start 0x80008000 $2
echo "Changed the LMA of ""$1"" to 0x80008000 in ""$2"" "

Note: Once the MMU is turned ON, CCS can further not be used to debug, but can be used to trace the code in assembly code. In order to do this disable memory mapping by Options->Memory Map and Disable Memory Map

No comments: