Search This Blog

Feb 16, 2011

Generate project files list from ELF

1. Generate u-boot project files list.

1.1 Extract u-boot package.

$ ./ltib -m prep -p u-boot
$ cd rpm/BUILD/u-boot-2009.08

1.2 Add dwarf information in u-boot elf file

$ gedit config.mk in u-boot directory. Add dwarf flag
-DBGFLAGS= -g # -DDEBUG
+DBGFLAGS= -g -gdwarf-2# -DDEBUG
$ make
We will get ELF format file u-boot after building done.

1.3 Use dwarfdump to parse project files path information.

$ dwarfdump -a u-boot | grep DW_AT_decl_file > project-file.txt
We will get file contents below.
DW_AT_decl_file             8 /root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/arch/mx53.h
DW_AT_decl_file             3 /root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/types.h
DW_AT_decl_file             3 /root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/types.h
DW_AT_decl_file             4 /root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/posix_types.h
DW_AT_decl_file             5 /root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/linux/types.h

1.4 Get final project files list.

Use IDE replace function with "wildcards", replace string "*/root" to "/root", and then we get final project files list.
/root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/arch/mx53.h
/root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/types.h
/root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/types.h
/root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/asm/posix_types.h
/root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/include/linux/types.h
Some lines need removed manually.
<   57> DW_AT_decl_file             DW_FORM_data1
      <   90> DW_AT_decl_file             DW_FORM_data1
      <  112> DW_AT_decl_file             DW_FORM_data1
      <  132> DW_AT_decl_file             DW_FORM_data1
And we have two .S files need added in manually.
/root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/board/freescale/mx53_smd/flash_header.S
/root/work/imx53-1101/ltib/rpm/BUILD/u-boot-2009.08/board/freescale/mx53_smd/lowlevel_init.S

1.5 IDE import project files list.

a)Open your IDE, create project and import your project-file.txt.
b)And we will see all the compiled files are import into IDE project management.

2. Generate Linux kernel project files list

2.1 Extract Linux kernel package.

$ ./ltib -m prep -p kernel
$ cd rpm/BUILD/linux-2.6.35.3

2.2 Add dwarf flag in Makefile

$ gedit Makefile
#ifdef CONFIG_DEBUG_INFO
KBUILD_CFLAGS += -g
KBUILD_AFLAGS += -gdwarf-2
#endif
$ Make uImage
We will get vmlinux when building complete.

2.3 Use readelf to parse project files path information

$ readelf -wL vmlinux | grep : > project-file.txt
Now we have contents like this:
include/linux/rcutree.h:
include/linux/thread_info.h:
include/asm-generic/bitops/non-atomic.h:
include/linux/rcutree.h:
init/main.c:
CU: include/asm-generic/int-ll64.h:
CU: init/do_mounts.c:
/root/work/ltib/rpm/BUILD/linux-2.6.35.3/arch/arm/include/asm/current.h:
init/do_mounts.c:
init/do_mounts.h:
We replace three symbols with blank.
"/root/work/ltib/rpm/BUILD/linux-2.6.35.3/", "CU: " and ":" and then we get contents below:
include/linux/rcutree.h
include/linux/thread_info.h
include/asm-generic/bitops/non-atomic.h
include/linux/rcutree.h
init/main.c
include/asm-generic/int-ll64.h
init/do_mounts.c
arch/arm/include/asm/current.h
init/do_mounts.c
init/do_mounts.h

2.4 IDE import project files list.

a)Open your IDE, create project and import your project-file.txt.
b)And we will see all the compiled files are import into IDE project management.

No comments: