source: buchla-68k/misc/mkhd.sh@ 3577fe1

Last change on this file since 3577fe1 was 27c8d40, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Fixed header script.

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