From patchwork Tue Dec 9 16:03:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karoly Kasza X-Patchwork-Id: 419161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 5C8281400D2 for ; Wed, 10 Dec 2014 03:03:55 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8A48E91A2F; Tue, 9 Dec 2014 16:03:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JfoUocjbKCAe; Tue, 9 Dec 2014 16:03:50 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 90E9B91C66; Tue, 9 Dec 2014 16:03:48 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 0F37B1CE932 for ; Tue, 9 Dec 2014 16:03:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 09A3492225 for ; Tue, 9 Dec 2014 16:03:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fwuRXgQK5y3k for ; Tue, 9 Dec 2014 16:03:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by whitealder.osuosl.org (Postfix) with ESMTPS id 34BE09222D for ; Tue, 9 Dec 2014 16:03:39 +0000 (UTC) Received: by mail-wi0-f171.google.com with SMTP id bs8so8370275wib.4 for ; Tue, 09 Dec 2014 08:03:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gYOOhQ47xDTZ09ng0GBp3YB4Wr4s00Xho7OWVKDVLGo=; b=zamrSA7MqDVHgVoRXXVkPwSiCZVaZ8/dgZ4N8/j0Qz/RC+Zn6YEfuPs+V92kg7bI+4 tK5EWoiOMHN1xKm4+jd01WZkdZWU8migEVfOyGaXDc57y6CX3YeJ549Yb9O5ki9TueWB PelWJ/IES4lCM93At5EJRpg6Sqn+Y4G0qUoyd1GvaYTyl6YJXve/YaoDOH4aBJKjvdQS Brk48Z/Yuj6MlieCNHYHHtlRn0/SXgV2u/WMvI6Q2YEZoTMR5M+lJM/ooThv5LRpc8j6 yhs7C3ENIrTLRCI83yoCqASdQUgd1VpXyyq7877zAKwCOpQp13awCLbEF8dGvXC9gDZt omlg== X-Received: by 10.194.59.166 with SMTP id a6mr6147769wjr.49.1418141017632; Tue, 09 Dec 2014 08:03:37 -0800 (PST) Received: from localhost.localdomain (mllnC3E4ABB5.fixip.t-online.hu. [195.228.171.181]) by mx.google.com with ESMTPSA id hz9sm2287800wjb.17.2014.12.09.08.03.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Dec 2014 08:03:37 -0800 (PST) From: Karoly Kasza To: buildroot@buildroot.org Date: Tue, 9 Dec 2014 17:03:26 +0100 Message-Id: <1418141008-18739-3-git-send-email-kaszak@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1418141008-18739-1-git-send-email-kaszak@gmail.com> References: <1418141008-18739-1-git-send-email-kaszak@gmail.com> Subject: [Buildroot] [PATCH v2 2/3] package/mkrawimg: new package X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" mkrawimg is a helper script like mke2img. It a host package, useful to build a complete raw disk image, with grub in the MBR and one ext* partition. 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 --- Changes v1 -> v2: - Created a new package from the script in v1. - Fdisk now specifies head and sector. - Sector size of ext* image is calculated properly. package/Config.in.host | 1 + package/mkrawimg/Config.in.host | 13 +++++++++++++ package/mkrawimg/mkrawimg | 38 ++++++++++++++++++++++++++++++++++++++ package/mkrawimg/mkrawimg.mk | 14 ++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 package/mkrawimg/Config.in.host create mode 100755 package/mkrawimg/mkrawimg create mode 100644 package/mkrawimg/mkrawimg.mk diff --git a/package/Config.in.host b/package/Config.in.host index 0b7bc36..4fa58f8 100644 --- a/package/Config.in.host +++ b/package/Config.in.host @@ -11,6 +11,7 @@ menu "Host utilities" source "package/genpart/Config.in.host" source "package/lpc3250loader/Config.in.host" source "package/mke2img/Config.in.host" + source "package/mkrawimg/Config.in.host" source "package/mtd/Config.in.host" source "package/mtools/Config.in.host" source "package/omap-u-boot-utils/Config.in.host" diff --git a/package/mkrawimg/Config.in.host b/package/mkrawimg/Config.in.host new file mode 100644 index 0000000..f5083b4 --- /dev/null +++ b/package/mkrawimg/Config.in.host @@ -0,0 +1,12 @@ +config BR2_PACKAGE_HOST_MKRAWIMG + bool "host mkrawimg" + select BR2_TARGET_GRUB + select BR2_TARGET_GRUB_FS_EXT2 + select BR2_PACKAGE_HOST_UTIL_LINUX + select BR2_PACKAGE_HOST_UTIL_LINUX_FDISK + help + Easily create raw disk images. + + This tool is bundled by, and specific to Buildroot. + It does not make much sense, to use it without + the "raw disk image" rootfs target. diff --git a/package/mkrawimg/mkrawimg b/package/mkrawimg/mkrawimg new file mode 100755 index 0000000..dcc5d06 --- /dev/null +++ b/package/mkrawimg/mkrawimg @@ -0,0 +1,38 @@ +#!/bin/bash + +# Buildroot tool to generate bootable raw disk image +# GRUB in MBR, boot first primary partition (ext*) + +set -e + +BINARIES_DIR="$1" +OUTPUT_IMG="$2" +# Size of generated ext* fs in sectors +SECTORS=`fdisk -l $BINARIES_DIR/rootfs.ext2 | grep $BINARIES_DIR/rootfs.ext2 | cut -d" " -f7` +# Size of image with MBR and partition table (512 block size with fdisk image file) +SECTOR_COUNT=$(($SECTORS+2048)) + +# Create an empty file, final size +dd if=/dev/zero of=$OUTPUT_IMG bs=512 count=$SECTOR_COUNT 2>/dev/null + +# Create a partition table - call our own fdisk in $PATH from host-util-linux +fdisk -H 16 -S 63 $OUTPUT_IMG >/dev/null 2>/dev/null </dev/null + +# Write MBR, grub is also called from $PATH +grub --no-floppy --batch >/dev/null 2>/dev/null <