From patchwork Fri Aug 10 12:54:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 143917 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3320960ljj; Fri, 10 Aug 2018 05:54:42 -0700 (PDT) X-Received: by 2002:a2e:7815:: with SMTP id t21-v6mr4863517ljc.61.1533905682675; Fri, 10 Aug 2018 05:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533905682; cv=none; d=google.com; s=arc-20160816; b=XIocQwA0Ow+wka1EKsi7kgQD5oZTG/m+6uyQEJj/xCu4iq6bCf5Vu/3cmBvys3b3id m3cJDLMr03lReokKhvroEL6UJLEt3ru2Kt5G1JpQ05qrxyLwHNuyYsI4MQxJW4epCloF HJj52EuAl6flEabRcOX0YridKgAvVp6h+HZgjPUCFGHk3YE7gJKkWISiLHBr6XFLMkh3 MDeOzbS7uJ7VKs8xxQBtn/m1ExTWgb/l1ruZNLb6bfP00NzP/eeZu8qB66QgBQ7Dttp6 WMrJ1TW7LCAatCRrmRDn45ZO1s7CeroCaHKaQPthHVL/y5gxohH3pzm3FDwrlWhB0oh3 /XNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=/AQX6NrEhAw1DMugwgFqidqugiyEqYYJjecffR6I1No=; b=P1VUYZE2uRjjDmI/LX59wgzKpd/28EDYmdTqdD8EGBPP53ld8Bjb1KQZNbwKKsnyAp I7eY4q2DDJ65xAWUgF6XmHVjskUyRFLxQaYUyqcj5LLidFnNw9Mugt5civpvHC3Vh0it N1kYShuN/+C3bH0Km0OnhKAY5kFLCwMM4o0seK9EmZGQFJ5rUdJ1AI4Qncr5HIT+jLHp KjBKlHiFungPkmUhuUomx91buHQwB9zWl0YbNHaopv59SEO2ndeD/02IO+NT69OaRtRG lGTTtV6TTbQbd2Ys870LoSpLja/zAqet+K8/Hmw4wbJE/8hfHTKCOLqsqvUCNJXTnFwq 9wmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AlVf1LJx; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f67-v6sor1210955lfk.179.2018.08.10.05.54.42 for (Google Transport Security); Fri, 10 Aug 2018 05:54:42 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AlVf1LJx; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/AQX6NrEhAw1DMugwgFqidqugiyEqYYJjecffR6I1No=; b=AlVf1LJxBh4KROGfjcdX5kFHWOdO2yayxQFhgiZSDQobtIpXED6agyZYOEUg1GG4Nk POjIy3lKkTZOGf5uXx9+ayvYbuO/XnUO0eF3WBZ6ee81qi9Hn70NjU754rQo4D9G8570 rJTUIyrF4LrdczwVGwLo7XTacQoNo6k/Ly/AE= 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=/AQX6NrEhAw1DMugwgFqidqugiyEqYYJjecffR6I1No=; b=VQ5IqLSJjmYFxO7GkHSePIJraDTNjeGnyKqVEosjHrcboeApZfWQJH/2mOroSMvsOx 92HNdkQ2WHPKolKZXBel6qjHjtypv5Hr83xRfKqxpw7iCAi51Acw3dHNVf5puBW+/Irf 1R234w/BXReovy8KCGcTVgIckZijcN9m3ed6mkvsaGvfoe6zmWdQv19+Z0Sh23hBxtRG E9Wlx/0B2LNjUsg7CMH9G9oKDMFOw0bn2t0SoE2ETcmk2H2l9DmdcVCQM9cK3OKL6eFz UY7nn+lWTD3y+6zWDUeirWEIiuMflTviL2FhD1cvCAHVS5sl38J2zjP2YWaaV3QHx1i1 70zw== X-Gm-Message-State: AOUpUlEcxpxcZrzQBmtIzaiEC8/lig0bWZhVcofPb3NCVfK5vpeaSDe/ LErQq3jfJwTrStOvDB/+Hqkl0oRP X-Google-Smtp-Source: AA+uWPzhZ9wo8pB8zxOh0pln6lYUrLwv+GiwS6GF6eZnmaupKfunXGNSAqN9Kw8eZH4WZRpr6hdSsA== X-Received: by 2002:a19:4c57:: with SMTP id z84-v6mr4356519lfa.67.1533905682496; Fri, 10 Aug 2018 05:54:42 -0700 (PDT) Return-Path: Received: from jax.urgonet (h-84-105.A175.priv.bahnhof.se. [79.136.84.105]) by smtp.gmail.com with ESMTPSA id v10-v6sm1574518ljg.12.2018.08.10.05.54.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 05:54:41 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Jens Wiklander Subject: [PATCH 2/2] fdt: fdtdec_setup_memory_banksize() use livetree Date: Fri, 10 Aug 2018 14:54:10 +0200 Message-Id: <20180810125410.19393-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180810125410.19393-1-jens.wiklander@linaro.org> References: <20180810125410.19393-1-jens.wiklander@linaro.org> Converts fdtdec_setup_memory_banksize() to use ofnode functions instead. Signed-off-by: Jens Wiklander --- lib/fdtdec.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/lib/fdtdec.c b/lib/fdtdec.c index a208589c48ae..fef2f88f9d10 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -16,6 +16,7 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -1182,43 +1183,34 @@ int fdtdec_setup_mem_size_base(void) #if defined(CONFIG_NR_DRAM_BANKS) -static int get_next_memory_node(const void *blob, int startoffset) +static ofnode get_next_memory_node(ofnode mem) { - int mem = -1; - do { - mem = fdt_node_offset_by_prop_value(gd->fdt_blob, mem, - "device_type", "memory", 7); - } while (!fdtdec_get_is_enabled(blob, mem)); + mem = ofnode_by_prop_value(mem, "device_type", "memory", 7); + } while (ofnode_valid(mem) && !ofnode_is_available(mem)); return mem; } int fdtdec_setup_memory_banksize(void) { - int bank, ret, mem, reg = 0; - struct fdt_resource res; + int bank, reg = 0; + struct resource res; + ofnode mem; - mem = get_next_memory_node(gd->fdt_blob, -1); - if (mem < 0) { - debug("%s: Missing /memory node\n", __func__); - return -EINVAL; - } + mem = get_next_memory_node(ofnode_null()); + if (!ofnode_valid(mem)) + goto missing_node; for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); - if (ret == -FDT_ERR_NOTFOUND) { + while (ofnode_read_resource(mem, reg++, &res)) { reg = 0; - mem = get_next_memory_node(gd->fdt_blob, mem); - if (mem == -FDT_ERR_NOTFOUND) - break; - - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); - if (ret == -FDT_ERR_NOTFOUND) - break; - } - if (ret != 0) { - return -EINVAL; + mem = get_next_memory_node(mem); + if (!ofnode_valid(mem)) { + if (bank) + return 0; + goto missing_node; + } } gd->bd->bi_dram[bank].start = (phys_addr_t)res.start; @@ -1232,6 +1224,10 @@ int fdtdec_setup_memory_banksize(void) } return 0; + +missing_node: + debug("%s: Missing /memory node\n", __func__); + return -EINVAL; } #endif