Last change
on this file since 00c31a2 was 27c8d40, checked in by Thomas Lopatic <thomas@…>, 8 years ago |
Fixed header script.
|
-
Property mode
set to
100755
|
File size:
1.6 KB
|
Rev | Line | |
---|
[87361de] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | if [ -z "${1}" -o -z "${2}" ]; then
|
---|
| 4 | echo "usage: mkhd.sh cross-nm elf-file"
|
---|
| 5 | exit 1
|
---|
| 6 | fi
|
---|
| 7 |
|
---|
| 8 | CROSS_NM=${1}
|
---|
| 9 | ELF_FILE=${2}
|
---|
| 10 |
|
---|
| 11 | ${CROSS_NM} --help >/dev/null 2>&1
|
---|
| 12 |
|
---|
| 13 | if [ ${?} -ne 0 ]; then
|
---|
| 14 | echo "error while executing ${CROSS_NM}"
|
---|
| 15 | exit 1
|
---|
| 16 | fi
|
---|
| 17 |
|
---|
| 18 | if [ ! -e ${ELF_FILE} ]; then
|
---|
| 19 | echo "${ELF_FILE} does not exist"
|
---|
| 20 | exit 1
|
---|
| 21 | fi
|
---|
| 22 |
|
---|
| 23 | getsym() {
|
---|
| 24 | NAME=${1}
|
---|
| 25 | HEX=$(${CROSS_NM} ${ELF_FILE} | grep ' '${NAME}'$' | cut -c -8)
|
---|
| 26 | RET=$(printf '%d' 0x${HEX})
|
---|
| 27 | printf ' %7s %10s %6s\n' ${NAME} 0x${HEX} ${RET} >&2
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | echo "creating header for ${ELF_FILE}'s sections:" >&2
|
---|
| 31 | echo >&2
|
---|
| 32 |
|
---|
[27c8d40] | 33 | getsym stext; SYM_STEXT=${RET}
|
---|
| 34 | getsym etext; SYM_ETEXT=${RET}
|
---|
| 35 | getsym sdata; SYM_SDATA=${RET}
|
---|
| 36 | getsym edata; SYM_EDATA=${RET}
|
---|
| 37 | getsym sbss; SYM_SBSS=${RET}
|
---|
| 38 | getsym ebss; SYM_EBSS=${RET}
|
---|
[87361de] | 39 |
|
---|
| 40 | echo >&2
|
---|
| 41 |
|
---|
[0acb7d0] | 42 | LEN_TEXT=$((${SYM_SDATA} - ${SYM_STEXT}))
|
---|
| 43 | LEN_DATA=$((${SYM_EDATA} - ${SYM_SDATA}))
|
---|
| 44 | LEN_IMAG=$((${LEN_TEXT} + ${LEN_DATA}))
|
---|
| 45 | LEN_BSS=$((${SYM_EBSS} - ${SYM_SBSS}))
|
---|
| 46 |
|
---|
| 47 | printf ' sz_text 0x%08x %6s\n' ${LEN_TEXT} ${LEN_TEXT} >&2
|
---|
| 48 | printf ' sz_data 0x%08x %6s\n' ${LEN_DATA} ${LEN_DATA} >&2
|
---|
| 49 | printf ' sz_imag 0x%08x %6s\n' ${LEN_IMAG} ${LEN_IMAG} >&2
|
---|
| 50 | printf ' sz_bss 0x%08x %6s\n' ${LEN_BSS} ${LEN_BSS} >&2
|
---|
| 51 |
|
---|
| 52 | echo >&2
|
---|
[87361de] | 53 |
|
---|
| 54 | out8() {
|
---|
| 55 | VAL8=${1}
|
---|
| 56 | HEX8=$(printf '%x' ${VAL8})
|
---|
| 57 | printf "\x${HEX8}"
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | out16() {
|
---|
| 61 | VAL16=${1}
|
---|
| 62 | HI16=$((VAL16 / 256))
|
---|
| 63 | LO16=$((VAL16 % 256))
|
---|
| 64 | out8 ${HI16}
|
---|
| 65 | out8 ${LO16}
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | out32() {
|
---|
| 69 | VAL32=${1}
|
---|
| 70 | HI32=$((VAL32 / 65536))
|
---|
| 71 | LO32=$((VAL32 % 65536))
|
---|
| 72 | out16 ${HI32}
|
---|
| 73 | out16 ${LO32}
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[0acb7d0] | 76 | out16 24603
|
---|
[87361de] | 77 | out32 ${LEN_TEXT}
|
---|
| 78 | out32 ${LEN_DATA}
|
---|
| 79 | out32 ${LEN_BSS}
|
---|
| 80 | out32 0
|
---|
| 81 | out32 0
|
---|
[0acb7d0] | 82 | out32 ${SYM_STEXT}
|
---|
[87361de] | 83 | out16 65535
|
---|
[0acb7d0] | 84 | out32 ${SYM_SDATA}
|
---|
| 85 | out32 ${SYM_SBSS}
|
---|
Note:
See
TracBrowser
for help on using the repository browser.