From patchwork Mon May 23 15:09:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9132045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D9B0E607D5 for ; Mon, 23 May 2016 15:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D068A2822F for ; Mon, 23 May 2016 15:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C54E228239; Mon, 23 May 2016 15:23:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 763BF2822F for ; Mon, 23 May 2016 15:23:42 +0000 (UTC) Received: from localhost ([::1]:48863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rhl-0005Is-Jn for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 May 2016 11:23:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUr-0002ER-F4 for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4rUp-00047G-9A for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:20 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUp-000475-39 for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:19 -0400 Received: by mail-wm0-x241.google.com with SMTP id n129so16052725wmn.1 for ; Mon, 23 May 2016 08:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q7xUIXzqttYidxdAQBHnQi3ypLYmPyHELbHZ7U2g3Xw=; b=BT/PeWRxAMoR40TUgcwT97GJdWlgjIV0YMclR/GY8Jn7MlhGgzCw0Oy3WSkJNM6Vjm 7U6dBWP6t+mDH7KN6ZoIi3zAgVkytrZXKX+tRbF0C1UNKCZIIxgo9naWx1x3s+LpZS3e FzUGKjt4DR8kKYLnRkFpQCM3+h7OzkZ13r0uNdzDtWVNgcSX2ixbNNDw4DSHEmNml77x OFoyFbPaBWhzjNRZfTa18FPe0q5GtcTUCvbQpKfbnKlNs/Y3T/++8H9Yv9npJb8SVdJh YPklfH9/t1igECKAS8byEzk0wim7j84ggw+VkJmzACbrbP768xR1S2wDZP8OW061xQhE ziow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Q7xUIXzqttYidxdAQBHnQi3ypLYmPyHELbHZ7U2g3Xw=; b=Gkh6ZT2qqDXiuKStMJfzFgLAJJGg3dV6D5TcvbfY7/BuH8upz+cs0kta7w7osK+0Sz skJYr2PS2XlVADGMzGImbK5ThgkKExNL9m1Hgvw5Zk+4ByjvhCuZ45YgQUOQfRr0U8iL vn79mLOAjvfXm5lwm6nRcsHRcj+JFp3j6My95UxxiJGNYQAR+XtMTWrP34AtvmXRkBQH bwNz7WVjQ3z/IlUjkFImwhsQsRN/7gqRTfrZiCb/ULWcc83vsa+/m6KTpkLGWBFVGoCp i1Wy9PqShI5Qx1mSXY+dc1VJtj6DTIowT0rWooJNAYlxdd7qNcS1g0ZDBFj+3oK13Jys tuwQ== X-Gm-Message-State: AOPr4FVtzwOUFUJonU2PFATrUMRsN1ZLJ7006B2cBm7sKXuBlTS+8SliWqGdiTMUf4cnZw== X-Received: by 10.28.229.203 with SMTP id c194mr16912886wmh.18.1464016218568; Mon, 23 May 2016 08:10:18 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-252-58.clienti.tiscali.it. [78.12.252.58]) by smtp.gmail.com with ESMTPSA id ac2sm19250359wjc.35.2016.05.23.08.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2016 08:10:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 23 May 2016 17:09:51 +0200 Message-Id: <1464016199-43768-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> References: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 16/24] 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: "Richard W.M. Jones" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Richard W.M. Jones" 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 Message-Id: <1463000807-18015-2-git-send-email-rjones@redhat.com> --- 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