summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_bootable.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/ptxd_make_bootable.sh')
-rw-r--r--scripts/lib/ptxd_make_bootable.sh42
1 files changed, 41 insertions, 1 deletions
diff --git a/scripts/lib/ptxd_make_bootable.sh b/scripts/lib/ptxd_make_bootable.sh
index b32b4e3ee..ed9bc31fd 100644
--- a/scripts/lib/ptxd_make_bootable.sh
+++ b/scripts/lib/ptxd_make_bootable.sh
@@ -19,7 +19,7 @@
# $3 first part of the bootloader for the code area of the MBR
# $4 second part of the bootloader for sector 2..n
#
-ptxd_make_bootable() {
+ptxd_make_dd_bootloader() {
local image="$1"
local bytes="$[$2 * 512]"
local stage1="$3"
@@ -49,5 +49,45 @@ ptxd_make_bootable() {
dd if="${stage1}" of="${image}" ${opt} bs=446 count=1 2>/dev/null &&
dd if="${stage2}" of="${image}" ${opt} ${opt2} bs=512 2>/dev/null
}
+export -f ptxd_make_dd_bootloader
+
+
+#
+# Make a disk image bootable. What exactly happens depends on the selected
+# platform options.
+# This function will fail if the specified free space is not enough to
+# install the bootloader.
+#
+# $1 the image to modify
+# $2 number of free sectors at the start of the image
+#
+ptxd_make_bootable() {
+ local image="${1}"
+ local sectors="${2}"
+ local stage1 stage2
+
+ if ptxd_get_ptxconf PTXCONF_GRUB > /dev/null; then
+ echo
+ echo "-----------------------------------"
+ echo "Making the image bootable with grub"
+ echo "-----------------------------------"
+ ptxd_get_path ${PTXDIST_SYSROOT_TARGET}/usr/lib/grub/*/stage1 || return
+ stage1="${ptxd_reply}"
+ ptxd_get_path ${PTXDIST_SYSROOT_TARGET}/usr/lib/grub/*/stage2 || return
+ stage2="${ptxd_reply}"
+ fi
+ if ptxd_get_ptxconf PTXCONF_BAREBOX > /dev/null; then
+ echo
+ echo "--------------------------------------"
+ echo "Making the image bootable with barebox"
+ echo "--------------------------------------"
+ stage1="${ptx_image_dir}/barebox-image"
+ if ptxd_get_ptxconf PTXCONF_ARCH_X86 > /dev/null; then
+ setupmbr -s 32 -m "${stage1}" -d "${image}"
+ return
+ fi
+ fi
+ ptxd_make_dd_bootloader "${image}" "${sectors}" "${stage1}" "${stage2}"
+}
export -f ptxd_make_bootable