From patchwork Sat Aug 15 20:37:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 507811 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C4CC1140134 for ; Mon, 17 Aug 2015 17:10:26 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=ERm6+JqL; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7A0FD4B845; Mon, 17 Aug 2015 09:07:57 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C19ipGM64HtJ; Mon, 17 Aug 2015 09:07:57 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9AEAD4B834; Mon, 17 Aug 2015 09:06:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8973E4B61F for ; Sat, 15 Aug 2015 22:38:31 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 10zdEixpnzCu for ; Sat, 15 Aug 2015 22:38:31 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-io0-f182.google.com (mail-io0-f182.google.com [209.85.223.182]) by theia.denx.de (Postfix) with ESMTPS id 2D21E4B61D for ; Sat, 15 Aug 2015 22:38:26 +0200 (CEST) Received: by iodb91 with SMTP id b91so115392242iod.1 for ; Sat, 15 Aug 2015 13:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=QiWyw+1yK6cl/w0GIUyfV5TQkg2Z1bCxfRJzPO1ipV4=; b=ERm6+JqLj83JKs9W+WrYQVcHtD5gZb9fDabMF9D5sDx+9FPO8WZHpR0PxWeqMWJ7tg 06+eQg782ZgcuMIeGAR34MvA7dS20px+h+aSDoxU1UQQf7Q3pim/ntU5636v8H3ugJYJ mFTdWeVWi9hWhxZ/wAvwG8NXwWFbu7vJLK01qmRjIlfstgO1Cw9PbIwn1KMoJL38I+2V dqNVO33e9SG0Omwv2j2t1qOv6f0tCvSuA1fbkZpGeehiX+wceDsnj2el/YxalDU5j5Tv k9rQ55Fc2u6ljU/l1e3ssJah6UEziyn32WoKyy7xXUqOD2AC9VES6l4nSUea+OJ0WtGq qFWw== 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=QiWyw+1yK6cl/w0GIUyfV5TQkg2Z1bCxfRJzPO1ipV4=; b=U5G7xf+DBgpjCpcNSH11FUDwmrIr+cWHwOPzThnVFVGUwTV7zZSxSdFTu2LfZDm4w8 +vJ+/yrgaVLdN+1csALJAE1dMiPMA7Tz+nQ5f0C8SeaSWjn1lLRaaYAJVW/qpBMb6oQV nU4tIol6AvYVrbq6q28QbEVjj3Y4cb2cJFw/TCp4Eudb+GvS4d6kYJU2OQYs7PoJAaf4 DFn5uhD2T3fyHw8eUygSj+56E2RP9QaPoz43s3uG4TEGtlKHl+06bpxhXU3zw9GAv7ZX Np4MFEgTjTN5QkthqIMY5+o/cXBhACz33PfLpKSTJ3RCJidl84/7xCkvZqCB6gGUO1NZ DU6g== X-Gm-Message-State: ALoCoQmRRkbsvkfD2WRQaZ3hciExA1EMpmudQ9qtI6Zp1Nl/AGYjQ3pmijaEdkk25eonlh+x/bSw X-Received: by 10.107.128.152 with SMTP id k24mr48414691ioi.74.1439671105898; Sat, 15 Aug 2015 13:38:25 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by smtp.gmail.com with ESMTPSA id 91sm8579683ioi.44.2015.08.15.13.38.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Aug 2015 13:38:25 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 2D2DE2215F6; Sat, 15 Aug 2015 14:38:22 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 15 Aug 2015 14:37:54 -0600 Message-Id: <1439671074-6683-8-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.5.0.276.gf5e568e In-Reply-To: <1439671074-6683-1-git-send-email-sjg@chromium.org> References: <1439671074-6683-1-git-send-email-sjg@chromium.org> Cc: Graeme Russ Subject: [U-Boot] [PATCH v2 7/7] x86: ifdtool: Drop microcode from the device tree when collating X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When ifdtool collates the microcode into one place it effectively creates a copy of the 'data' properties in the device tree microcode nodes. This is wasteful since we now have two copies of the microcode in the ROM. To avoid this, remove the microcode data from the device tree and shrink it down. This means that there is only one copy and the overall ROM space used by the microcode does not increase. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- Changes in v2: - Enhance ifdtool rather that changing the microcode format tools/ifdtool.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/tools/ifdtool.c b/tools/ifdtool.c index d966c56..1f95203 100644 --- a/tools/ifdtool.c +++ b/tools/ifdtool.c @@ -783,6 +783,47 @@ static int scan_ucode(const void *blob, char *ucode_base, int *countp, return ucode - ucode_base; } +static int remove_ucode(char *blob) +{ + int node, count; + int ret; + + /* Keep going until we find no more microcode to remove */ + do { + for (node = 0, count = 0; node >= 0;) { + int ret; + + node = fdt_node_offset_by_compatible(blob, node, + "intel,microcode"); + if (node < 0) + break; + + ret = fdt_delprop(blob, node, "data"); + + /* + * -FDT_ERR_NOTFOUND means we already removed the + * data for this one, so we just continue. + * 0 means we did remove it, so offsets may have + * changed and we need to restart our scan. + * Anything else indicates an error we should report. + */ + if (ret == -FDT_ERR_NOTFOUND) + continue; + else if (!ret) + node = 0; + else + return ret; + } + } while (count); + + /* Pack down to remove excees space */ + ret = fdt_pack(blob); + if (ret) + return ret; + + return fdt_totalsize(blob); +} + static int write_ucode(char *image, int size, struct input_file *fdt, int fdt_size, unsigned int ucode_ptr, int collate_ucode) @@ -818,8 +859,8 @@ static int write_ucode(char *image, int size, struct input_file *fdt, } /* - * Collect the microcode into a buffer and place it immediately above - * the device tree. + * Collect the microcode into a buffer, remove it from the device + * tree and place it immediately above the (now smaller) device tree. */ if (collate_ucode && count > 1) { ucode_buf = malloc(ucode_size); @@ -833,7 +874,17 @@ static int write_ucode(char *image, int size, struct input_file *fdt, if (ret < 0) return ret; + /* Remove the microcode from the device tree */ + ret = remove_ucode((char *)blob); + if (ret < 0) { + debug("Could not remove FDT microcode: %s\n", + fdt_strerror(ret)); + return -EINVAL; + } debug("Collated %d microcode block(s)\n", count); + debug("Device tree reduced from %x to %x bytes\n", + fdt_size, ret); + fdt_size = ret; /* * Place microcode area immediately above the FDT, aligned