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.

Feb 10, 2011

Get Linux BSP compiled files list for IDE

   We are working on Linux BSP. There are tons of source files. We only want to add those files which been compiled into our IDE, like SlickEdit 15.06. We need the dump the file path information from ELF file and generate list file for SlickEdit.


 1. Add CONFIG_DEBUG_INFO in Linux config file.

 $ cd ~/ltib/rpm/BUILD/linux-2.6.35.3/
 $ make menuconfig
 When menu appear enter  "Kernel hacking", select two items
  [*] Kernel debugging
  [*] Compile the kernel with debug info
 Exit and save
 $ make uImage -j4
 And then we get vmlinux with debug information.

2.  Use readelf to dump the files path from vmlinux
 $ 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

"
Now we get compiled files list, some of the file are duplicate, however, SlickEdit will handle it, don't worry about it.

3. Open SlickEdit, create new project in " ~/ltib/rpm/BUILD/linux-2.6.35.3/".
  And select "Project->project properties" from menu item, you will see "import" button on right-bottom of the window, click it and select "project-file.txt" as import file. Click OK button and done.
  1500 files were added into SlickEdit project, without this files list, to add all files in Linux BSP, 28000 files need added into SlickEdit project. It will deeply impact parsing speed in IDE.