summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2011-03-17 11:58:14 +0100
committerMichael Olbrich <m.olbrich@pengutronix.de>2011-03-28 11:11:41 +0200
commit4accb167e80929356d0b200c1ca8db955dec38cd (patch)
tree18a011459768e37699fcf219271e822de088b321
parentae9dae08c70a05554d280db90e648190769f3380 (diff)
downloadptxdist-4accb167e80929356d0b200c1ca8db955dec38cd.tar.gz
ptxdist-4accb167e80929356d0b200c1ca8db955dec38cd.tar.xz
image_hd: move bootloader selection into a function
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--rules/post/image_hd.make20
-rw-r--r--scripts/lib/ptxd_make_bootable.sh42
2 files changed, 43 insertions, 19 deletions
diff --git a/rules/post/image_hd.make b/rules/post/image_hd.make
index 0b3841fbf..4e4ab2104 100644
--- a/rules/post/image_hd.make
+++ b/rules/post/image_hd.make
@@ -31,24 +31,8 @@ $(IMAGEDIR)/hd.img:
@echo "Creating hdimg from root.ext2"; \
PATH=$(PTXCONF_SYSROOT_HOST)/bin:$$PATH $(PTXDIST_TOPDIR)/scripts/genhdimg \
-o $@ $(GENHDIMARGS)
-ifdef PTXCONF_GRUB
- @echo
- @echo "-----------------------------------"
- @echo "Making the image bootable with grub"
- @echo "-----------------------------------"
- @ptxd_make_bootable $@ $(PTXCONF_IMAGE_HD_PART1_START) $(GRUB_DIR)/stage1/stage1 $(GRUB_DIR)/stage2/stage2
-endif
-ifdef PTXCONF_BAREBOX
- @echo
- @echo "--------------------------------------"
- @echo "Making the image bootable with barebox"
- @echo "--------------------------------------"
-ifdef PTXCONF_ARCH_X86
- @$(BAREBOX_DIR)/scripts/setupmbr/setupmbr -s 32 -m $(IMAGEDIR)/barebox-image -d $@
-else
- @ptxd_make_bootable $@ $(PTXCONF_IMAGE_HD_PART1_START) $(IMAGEDIR)/barebox-image
-endif
-endif
+ @$(call ptx/env) \
+ ptxd_make_bootable $@ $(PTXCONF_IMAGE_HD_PART1_START)
@echo "done."
# vim: syntax=make
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