blob: 1b1873e591dfc44e366b09314c9199c01a766c50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#! /bin/bash
set -u
set -e
. build_helpers/progressif.ly.io.sh
INPATH="$1"
INBASEPATH="${INPATH%.*}"
# mangle such that no two names conflict (a/b/c and a/b.c conflicting would be no fun)
#OUTNAME="$(echo "$INBASEPATH" | sed 's/\./../g' | sed 's/\//._/g')"
OUTNAME="src._kernel._main"
# $INPATH
track building_src "Building sources to 'tmp/$OUTNAME'... "
gcc -T linker.ld -m32 -Wl,--build-id=none -nostartfiles -nostdlib -ffreestanding $INPATH -o "tmp/$OUTNAME".o
trackend building_src t
track find_start "Detecting start address... "
BIN_START=$(objdump tmp/src._kernel._main.o -f | grep start | cut -b 15-)
tracknote find_start "Start address is: $BIN_START"
trackend find_start t
# this actually writes three extra nulls, not sure why...
echo "$BIN_START" | xxd -r - | od -t x --endian=little | head | xxd -r - > "bin/$OUTNAME".bin
track strip_sections "Stripping unnecessary sections... "
objcopy -R .note.gnu.build-id -R .comment -O binary "tmp/$OUTNAME".o "tmp/converted_$OUTNAME".bin
trackend strip_sections t
track relocate_kernel "Joining kernel and start address... "
# adjust for the three extra nulls above
dd if="tmp/converted_$OUTNAME".bin of="bin/$OUTNAME".bin seek=4 oflag=seek_bytes conv=notrunc 2>/dev/null
trackend relocate_kernel t
#rm "tmp/$OUTNAME".o
|