Skip to content

Commit f8a5a64

Browse files
committed
add sanity check script for kernel ELF validation
1 parent 90c325e commit f8a5a64

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

check-kernel.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
# This file contain multiple sanity check for testing purpose of the
3+
# vectors table alginement and such.
4+
# run chmod +x ./check-kernel.sh before hand
5+
set -e
6+
7+
ELF=build/kernel.elf
8+
9+
echo "=== Running sanity checks on $ELF ==="
10+
11+
# Check .vectors at 0x0
12+
if arm-none-eabi-objdump -h "$ELF" | grep -q '\.vectors.*00000000'; then
13+
echo "[PASS] .vectors section is mapped at VMA 0x00000000"
14+
else
15+
echo "[FAIL] .vectors not at 0x0!"
16+
fi
17+
18+
# Check entry point is _start
19+
ENTRY=$(arm-none-eabi-readelf -h "$ELF" | grep 'Entry point' | awk '{print $4}' | sed 's/^0x//')
20+
START_ADDR=$(arm-none-eabi-nm -n "$ELF" | grep " T _start" | awk '{print $1}')
21+
if [ $((16#$ENTRY)) -eq $((16#$START_ADDR)) ]; then
22+
echo "[PASS] Entry point matches _start (0x$ENTRY)"
23+
else
24+
echo "[FAIL] Entry point mismatch: entry=0x$ENTRY, _start=0x$START_ADDR"
25+
fi
26+
27+
# Check vector table branches correctly
28+
DISASM=$(arm-none-eabi-objdump -d -j .vectors "$ELF")
29+
30+
if echo "$DISASM" | grep -q "b.*<_start>"; then
31+
echo "[PASS] Reset vector branches to _start"
32+
else
33+
echo "[FAIL] Reset vector does not branch to _start!"
34+
fi
35+
36+
if echo "$DISASM" | grep -q "b.*<irq_entry>"; then
37+
echo "[PASS] IRQ vector branches to irq_entry"
38+
else
39+
echo "[FAIL] IRQ vector does not branch to irq_entry!"
40+
fi
41+
42+
# Check that irq_entry symbol exists
43+
if arm-none-eabi-nm -n "$ELF" | grep -q " T irq_entry"; then
44+
echo "[PASS] irq_entry symbol is defined"
45+
else
46+
echo "[FAIL] irq_entry missing!"
47+
fi
48+
49+
# Check BSS symbols exist
50+
if arm-none-eabi-nm -n "$ELF" | grep -q "__bss_start" && \
51+
arm-none-eabi-nm -n "$ELF" | grep -q "__bss_end"; then
52+
echo "[PASS] __bss_start and __bss_end are defined"
53+
else
54+
echo "[FAIL] Missing __bss_start/__bss_end!"
55+
fi
56+
57+
echo "=== Checks complete ==="

0 commit comments

Comments
 (0)