From patchwork Wed Dec 19 19:00:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1016269 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IPopb+Yh"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43Kknk2hYBz9rxp for ; Thu, 20 Dec 2018 06:03:54 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 20B62C21E3E; Wed, 19 Dec 2018 19:01:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BC23DC220AF; Wed, 19 Dec 2018 19:00:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 278C5C2202C; Wed, 19 Dec 2018 19:00:29 +0000 (UTC) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by lists.denx.de (Postfix) with ESMTPS id 47363C21F91 for ; Wed, 19 Dec 2018 19:00:21 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id v13so20607494wrw.5 for ; Wed, 19 Dec 2018 11:00:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=//AcW7YSnc1zUVb1NY1i9EGvmhzZmdO8s6PK8KEi5MA=; b=IPopb+YhlTAp9Zcw3ohWzoj+SNdsDNznsO0LsnthZdgO7Su+YVyj3cwKvMdeE3H5MI kfUKAXtDiLn4vXQarGgNJuiDbLw8WU0oNsEG0dm8/t8MMjL/f49+urm5sBwPv5CFxPaF fu2XdIkV/mZDHvGDJC7IX5pOPZN6FAiSL4G8qaGwD9HHzN9h3vfTZkbSocFNRKz2015G tEjj9K8g0SBYoJ7+GbI9ALWoCcbbEu9T82EJhaOyGiSNLgRdeHcidVRfm8G9lxZoq4bb 7REAz1i8Jxv0k3GsvXZ6id16QzLuWhHGqo4CQSQ6qJRInP4onOTU5zEk8h36HRlUEUlP q3sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=//AcW7YSnc1zUVb1NY1i9EGvmhzZmdO8s6PK8KEi5MA=; b=Gn0qphDTTDnNINSnh/x+C1IXLzqQXkhfs65Tr+0LkEkG9MdyGKMBVUlHFmlXA5IX1A xtN1TWs2JmaM4uZ+1RW31faXjOdx40jussgaZz0oiDoZ3cTotn2DYVuIKjPxO0EAnITK tsRM3MS+qDU/SmboOuYN8kyAaW/5Jw8xvgDLSQ/ToywYkv0jEN2MvPwCLlOHlgXED89H Y1CLG9EH2o9TCL4gd5gyQKkOXrU9piFRp7FHHrR9twiPM8ibk74/785527Sk78H/Urb4 HRY77PUKfPHKaXjZGvOY0aRRbd7apk+Pm/5No11Z8DEMI6mUZRvLkJ9jFClnOUgZy4qj +2PA== X-Gm-Message-State: AA+aEWaHPTNZQaIykx/bWn+Ab+2CXL5PQ0LMyL+90mKGMJZ3jr5ZZTXz M41TeuaJtBDFcQ49tWmiAbk= X-Google-Smtp-Source: AFSGD/VAW01qIo9A5immeL29zzGFrfO9ey2jjs6pz7KwYqPNdpS2HgNjDsP7i/AK9bYHb5k0rJN1sQ== X-Received: by 2002:a5d:40c1:: with SMTP id b1mr20846045wrq.133.1545246020952; Wed, 19 Dec 2018 11:00:20 -0800 (PST) Received: from ubuntu.home ([2a02:8071:6a3:700:80b1:ba3d:111a:23c5]) by smtp.gmail.com with ESMTPSA id q3sm10334744wrn.84.2018.12.19.11.00.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 11:00:20 -0800 (PST) From: Simon Goldschmidt To: Tom Rini , u-boot@lists.denx.de, Joe Hershberger Date: Wed, 19 Dec 2018 20:00:03 +0100 Message-Id: <20181219190009.23265-5-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181219190009.23265-1-simon.k.r.goldschmidt@gmail.com> References: <20181219190009.23265-1-simon.k.r.goldschmidt@gmail.com> Cc: Alexey Brodkin , Heinrich Schuchardt , Alexander Graf , Miquel Raynal , Andrea Barisani Subject: [U-Boot] [PATCH v9 04/10] fdt: parse "reserved-memory" for memory reservation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" boot_fdt_add_mem_rsv_regions() adds reserved memory sections to an lmb struct. Currently, it only parses regions described by /memreserve/ entries. Extend this to the more commonly used scheme of the "reserved-memory" node. Signed-off-by: Simon Goldschmidt --- Changes in v9: None Changes in v8: None Changes in v7: - fix compiling without CONFIG_FIT Changes in v6: - fix compiling without OF_CONTROL Changes in v5: None Changes in v4: - fixed invalid 'if' statement without braces in boot_fdt_reserve_region Changes in v2: - this patch is new in v2 common/image-fdt.c | 53 +++++++++++++++++++++++++++++++++++++++------- lib/Makefile | 1 + 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/common/image-fdt.c b/common/image-fdt.c index 95748f0ae1..5c0d6db3fe 100644 --- a/common/image-fdt.c +++ b/common/image-fdt.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -67,30 +68,66 @@ static const image_header_t *image_get_fdt(ulong fdt_addr) } #endif +static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr, + uint64_t size) +{ + int ret; + + ret = lmb_reserve(lmb, addr, size); + if (!ret) { + debug(" reserving fdt memory region: addr=%llx size=%llx\n", + (unsigned long long)addr, (unsigned long long)size); + } else { + puts("ERROR: reserving fdt memory region failed "); + printf("(addr=%llx size=%llx)\n", + (unsigned long long)addr, (unsigned long long)size); + } +} + /** - * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable + * boot_fdt_add_mem_rsv_regions - Mark the memreserve and reserved-memory + * sections as unusable * @lmb: pointer to lmb handle, will be used for memory mgmt * @fdt_blob: pointer to fdt blob base address * - * Adds the memreserve regions in the dtb to the lmb block. Adding the - * memreserve regions prevents u-boot from using them to store the initrd - * or the fdt blob. + * Adds the and reserved-memorymemreserve regions in the dtb to the lmb block. + * Adding the memreserve regions prevents u-boot from using them to store the + * initrd or the fdt blob. */ void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob) { uint64_t addr, size; - int i, total; + int i, total, ret; + int nodeoffset, subnode; + struct fdt_resource res; if (fdt_check_header(fdt_blob) != 0) return; + /* process memreserve sections */ total = fdt_num_mem_rsv(fdt_blob); for (i = 0; i < total; i++) { if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0) continue; - printf(" reserving fdt memory region: addr=%llx size=%llx\n", - (unsigned long long)addr, (unsigned long long)size); - lmb_reserve(lmb, addr, size); + boot_fdt_reserve_region(lmb, addr, size); + } + + /* process reserved-memory */ + nodeoffset = fdt_subnode_offset(fdt_blob, 0, "reserved-memory"); + if (nodeoffset >= 0) { + subnode = fdt_first_subnode(fdt_blob, nodeoffset); + while (subnode >= 0) { + /* check if this subnode has a reg property */ + ret = fdt_get_resource(fdt_blob, subnode, "reg", 0, + &res); + if (!ret) { + addr = res.start; + size = res.end - res.start + 1; + boot_fdt_reserve_region(lmb, addr, size); + } + + subnode = fdt_next_subnode(fdt_blob, subnode); + } } } diff --git a/lib/Makefile b/lib/Makefile index a6dd928a92..358789ff12 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -30,6 +30,7 @@ obj-y += crc7.o obj-y += crc8.o obj-y += crc16.o obj-$(CONFIG_ERRNO_STR) += errno_str.o +obj-$(CONFIG_OF_LIBFDT) += fdtdec.o obj-$(CONFIG_FIT) += fdtdec_common.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o