Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / build / utility / sh / make_ld.sh
1 #!/bin/sh
2
3 # This script is intended for use with separately linked ROM and RAM.
4 # It creates EITHER a linker script that satisfies references made by RAM
5 # applications to ROM symbols OR a linker script that forces symbols to
6 # be included in a ROM image.
7 #
8 # The option "--addrs" causes the RAM linkage script to be generated
9 # and the option "--externs" causes the ROM linkage script to be generated.
10 #
11 # Example usage:
12 #     make_ld.sh --addrs athos.rom.out athos.rom.symbols > rom.addrs.ld
13 #     make_ld.sh --externs athos.rom.symbols > rom.externs.ld
14
15 eval XTNM=xt-nm
16
17 Usage() {
18     echo Usage:
19     echo $progname '{--addrs ROM_ELF_Image | --externs} symbol_file'
20 }
21
22 Provide() {
23     addr0=`echo $1 | sed 's/\r$//'`
24         addr=0x`nm $image_file | grep -w $addr0 | cut -d ' ' -f 1`
25     if [ "$addr" != "0x" ]
26     then
27         echo PROVIDE \( $addr0 = $addr \)\;
28     fi
29 }
30
31 Extern() {
32     echo EXTERN \( $1 \)\;
33 }
34
35 progname=$0
36 script_choice=$1
37
38 if [ "$script_choice"=="--addrs" ]
39 then
40     action=Provide
41     image_file=$2
42
43     if [ ! -r "$image_file" ]
44     then
45         echo "Cannot read ELF image: $image_file"
46         Usage
47     fi
48     symbol_file=$3
49 elif [ "$script_choice"=="--externs" ]
50 then
51     action=Extern
52     symbol_file=$2
53
54         if [ ! -r "$symbol_file" ]
55         then
56             echo "Cannot read symbol list from: $symbol_file"
57             Usage
58         fi
59 else
60     Usage
61 fi
62
63 for i in `cat $symbol_file`
64 do
65     $action $i
66 done