@@ -8,6 +8,7 @@ source "fs/initramfs/Config.in"
source "fs/iso9660/Config.in"
source "fs/jffs2/Config.in"
source "fs/romfs/Config.in"
+source "fs/rawimg/Config.in"
source "fs/squashfs/Config.in"
source "fs/tar/Config.in"
source "fs/ubifs/Config.in"
new file mode 100644
@@ -0,0 +1,17 @@
+config BR2_TARGET_ROOTFS_RAWIMG
+ bool "raw disk image"
+ depends on (BR2_i386 || BR2_x86_64)
+ depends on BR2_LINUX_KERNEL
+ select BR2_LINUX_KERNEL_INSTALL_TARGET
+ select BR2_TARGET_ROOTFS_EXT2
+ select BR2_TARGET_GRUB
+ select BR2_TARGET_GRUB_FS_EXT2
+ select BR2_PACKAGE_HOST_UTIL_LINUX
+ select BR2_PACKAGE_HOST_UTIL_LINUX_FDISK
+ help
+ Build a bootable raw disk image, that can be booted in a VM (e.g. QEMU),
+ or directly written to disk. Creates a valid partition table with MBR.
+
+comment "raw disk image needs a Linux kernel to be built"
+ depends on BR2_i386 || BR2_x86_64
+ depends on !BR2_LINUX_KERNEL
new file mode 100755
@@ -0,0 +1,35 @@
+#!/bin/sh
+set -e
+
+BINARIES_DIR="$1"
+OUTPUT_IMG="$2"
+# Size of generated ext2 fs
+EXT2SIZE=`ls -l $BINARIES_DIR/rootfs.ext2 | cut -d' ' -f5`
+# Size of image with MBR and partition table (512 block size with fdisk image file)
+# Add 2048 blocks to beginning & end of file
+IMGCOUNT=$(($EXT2SIZE/512+2048+2048))
+
+# Create an empty file, final size
+dd if=/dev/zero of=$OUTPUT_IMG bs=512 count=$IMGCOUNT 2>/dev/null
+
+# Create a partition table - call our own fdisk in $PATH from host-util-linux
+fdisk $OUTPUT_IMG >/dev/null 2>/dev/null <<EOB
+n
+p
+1
+
+
+w
+EOB
+
+# Write the ext2 rootfs to the 1st partition
+dd if=$BINARIES_DIR/rootfs.ext2 of=$OUTPUT_IMG conv=notrunc bs=512 iflag=fullblock seek=2048 skip=0 2>/dev/null
+
+# Write MBR, grub is also called from $PATH
+grub --no-floppy --batch >/dev/null 2>/dev/null <<EOB
+device (hd0) $OUTPUT_IMG
+geometry (hd0)
+root (hd0,0)
+setup (hd0)
+quit
+EOB
new file mode 100644
@@ -0,0 +1,13 @@
+################################################################################
+#
+# Build the raw disk image
+#
+################################################################################
+
+ROOTFS_RAWIMG_DEPENDENCIES = rootfs-ext2
+
+define ROOTFS_RAWIMG_CMD
+ PATH=$(BR_PATH) fs/rawimg/genrawimg.sh $(BINARIES_DIR) $@
+endef
+
+$(eval $(call ROOTFS_TARGET,rawimg))
Creates a bootable raw disk image as a new rootfs image. Boots in QEMU or on bare metal after written (dd) to disk. Signed-off-by: Karoly Kasza <kaszak@gmail.com> --- fs/Config.in | 1 + fs/rawimg/Config.in | 17 +++++++++++++++++ fs/rawimg/genrawimg.sh | 35 +++++++++++++++++++++++++++++++++++ fs/rawimg/rawimg.mk | 13 +++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 fs/rawimg/Config.in create mode 100755 fs/rawimg/genrawimg.sh create mode 100644 fs/rawimg/rawimg.mk