From patchwork Wed May 11 21:06:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard W.M. Jones" X-Patchwork-Id: 9074661 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3FFC19F1C1 for ; Wed, 11 May 2016 21:08:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 90BE320155 for ; Wed, 11 May 2016 21:08:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA5C62014A for ; Wed, 11 May 2016 21:08:52 +0000 (UTC) Received: from localhost ([::1]:54113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0bND-0000Bm-VU for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 17:08:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0bLR-0004zV-LY for qemu-devel@nongnu.org; Wed, 11 May 2016 17:07:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0bLK-0004Mx-W2 for qemu-devel@nongnu.org; Wed, 11 May 2016 17:07:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37930) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0bLK-0004Lz-Qh for qemu-devel@nongnu.org; Wed, 11 May 2016 17:06:54 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D238C03BD5F; Wed, 11 May 2016 21:06:54 +0000 (UTC) Received: from moo.home.annexia.org (ovpn-204-25.brq.redhat.com [10.40.204.25]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4BL6me1023009; Wed, 11 May 2016 17:06:52 -0400 From: "Richard W.M. Jones" To: qemu-devel@nongnu.org Date: Wed, 11 May 2016 22:06:45 +0100 Message-Id: <1463000807-18015-2-git-send-email-rjones@redhat.com> In-Reply-To: <1463000807-18015-1-git-send-email-rjones@redhat.com> References: <1463000807-18015-1-git-send-email-rjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 11 May 2016 21:06:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 1/3] scripts/signrom.py: Allow option ROM checksum script to write the size header. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marc.mari.barcelo@gmail.com, ehabkost@redhat.com, mst@redhat.com, stefanha@gmail.com, kraxel@redhat.com, pbonzini@redhat.com, lersek@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,FSL_HELO_HOME, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Modify the signrom.py script so that if the size byte in the header is 0 (ie. not set) then the script will set the size. If the size byte is non-zero then we do the same as before, so this doesn't require changes to any existing ROM sourcecode. Signed-off-by: Richard W.M. Jones --- scripts/signrom.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/signrom.py b/scripts/signrom.py index f9c35cc..6c8b9bf 100644 --- a/scripts/signrom.py +++ b/scripts/signrom.py @@ -18,10 +18,29 @@ fin = open(sys.argv[1], 'rb') fout = open(sys.argv[2], 'wb') fin.seek(2) -size = ord(fin.read(1)) * 512 - 1 - +size_byte = ord(fin.read(1)) fin.seek(0) -data = fin.read(size) + +if size_byte == 0: + # If the caller left the size field blank then we will fill it in, + # also rounding the whole input to a multiple of 512 bytes. + data = fin.read() + # +1 because we need a byte to store the checksum. + size = len(data) + 1 + # Round up to next multiple of 512. + size += 511 + size -= size % 512 + if size >= 65536: + sys.exit("%s: option ROM size too large" % sys.argv[1]) + # size-1 because a final byte is added below to store the checksum. + data = data.ljust(size-1, '\0') + data = data[:2] + chr(size/512) + data[3:] +else: + # Otherwise the input file specifies the size so use it. + # -1 because we overwrite the last byte of the file with the checksum. + size = size_byte * 512 - 1 + data = fin.read(size) + fout.write(data) checksum = 0