2025-03-29 03:52:35 -04:00

50 lines
1.6 KiB
Bash
Executable File

#!/bin/bash -e
# Tiny Linux Bootloader
# (c) 2014- Dr Gareth Owen (www.ghowen.me). All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
export SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "${SCRIPT_DIR}"
INPUT="bflop.asm"
KERN="${1:-bzImage}"
OUTPUT="${2:-boot-disk.img}"
PAD_TO_FLOPPY="${PAD_TO_FLOPPY:-y}"
#size of kern + ramdisk
K_SZ="$(stat -c %s "${KERN}")"
#padding to make it up to a sector
K_PAD="$((512 - "${K_SZ}" % 512))"
nasm -o "${OUTPUT}" "${INPUT}"
cat "${KERN}" >> "${OUTPUT}"
if [[ "${K_PAD}" -lt 512 ]]; then
dd if=/dev/zero bs=1 count="${K_PAD}" >> "${OUTPUT}"
fi
TOTAL="$(stat -c %s "${OUTPUT}")"
if [[ "${TOTAL}" -gt 1474560 ]]; then
echo "Warning: Image exceeds floppy size by $(( TOTAL - 1474560 )) bytes"
exit 1
else
echo "Free bytes on floppy image: $(( 1474560 - TOTAL ))"
fi
if [ "$PAD_TO_FLOPPY" = y ]; then
dd if=/dev/zero bs=1 count="$((1474560 - TOTAL))" >> "${OUTPUT}" 2>/dev/null
fi