From patchwork Mon Aug 20 09:09:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 144552 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3722013ljj; Mon, 20 Aug 2018 02:10:13 -0700 (PDT) X-Received: by 2002:a19:d105:: with SMTP id i5-v6mr8132220lfg.31.1534756213338; Mon, 20 Aug 2018 02:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534756213; cv=none; d=google.com; s=arc-20160816; b=fDVhFki809aH7CUtjejOgfrZwtfeuLDCPDp1bidIOH5aunpKhHn8qyzA1XI0rPDcgD AI1zhNj2CHIXqSJJN6lqIMsr+ImWJcGEolwYdObfewNOWZZGmFw1KYXDmKiGBKZN8eb4 ELxpSt6YTI5cAnUGv7DEBELif+0BZiyzQfT3kIrCVojRlg3fNEilm2WnAYPIydCzQQYc UwuKBoEBI/22uCRZaJcrIZNP0IFxuhlHff9PsvzvrP9mcMMvaY3FkEFd+4+uQu9vHqC0 l0Zm/4yUeTAUVlkBDEu9xC5aoc+yerkyyOFU9YhlDaoIVXzKNSM0teaFdbRDuZ60yPV5 tGig== 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=2bzMZmfsRh7F6NXhmL1mEgS9uNys0knxo3Bgi/cT4+g=; b=EBGLpatcxbGHYrIhbI2wLsPR2VmhoN/13ZN9gHiRnjmICcbQIzBibiFCwIqnxw3ahK ggldOeyjpVs6GFtlm9rzpOcrVeoJxYN8l9mIgYwe4PdItXMqiESVPP48dfoYGLnajKbC Q74tbnHwJXessn9e4t997CEDNcJGBAenfV03cnNc8WhjfuV2poKg1nL/UaiaUBq+8+UH LRURkg9CU91V48O0E14Nu4bhPxi+AloI5QYoC+kz9AwIZi2M1VFsHu+HV0TRE7D46Tv8 Qhj9aGv5cAz9d0+HOOPKAR7dr3liOrcv7+AECCF2+qvttDBfb3fqhMAEY+Vjk33OuVNr dnmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cgqGAA1x; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id m77-v6sor1545130lje.107.2018.08.20.02.10.13 for (Google Transport Security); Mon, 20 Aug 2018 02:10:13 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cgqGAA1x; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 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=2bzMZmfsRh7F6NXhmL1mEgS9uNys0knxo3Bgi/cT4+g=; b=cgqGAA1xWt4pNKueXh8sgnyqG6K6a+ux/dHoSEklH2a8OcHuOpXLsAw+v6APcLaiec Q4R3Qi+mjOVTZkYZaLq7jMdoFtuK9T8Sj28rbHm2msz2kjmbLTJWTxreYFywSnFIgBjR 7DFunuXUzCWbOuUlcfSJwJglZsME+dKazkTYs= 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=2bzMZmfsRh7F6NXhmL1mEgS9uNys0knxo3Bgi/cT4+g=; b=SDhRAPc4+0GqWh0g1DdjLNq+IUJFz/twxEXekTo6AnOBQtAMIaFHbrKFQc6+DwHQOX fN2bg6Izaeh3fXb0hgYXOPFX6dY6DajIyU2h1o6Qw6zlXAHdrXibpMC+K6uF8DczUsjr jbasTj9ZXhXv6EB/Zoc1bWpZ6wbHsAvWI/WG1l3zqE02AxaojxFA1rbNz8psyMU/hYIy 9RpfQvSNHryk3J+T1E39X5tT9sup2hkVsJgUEdQIa6NkNPjqAwCciKTavj1n0K4s0bBg tUtI+UMsJxV/47srJDAQ1kUUQ7i6zkn74lLEiVNNUMVIPuVfdUlhu31NEyqb/BZi0ct9 449Q== X-Gm-Message-State: AOUpUlErd0sSuFAgn16S1o9lM3PQYFRGW7MG30m6sEJjvqNPsFL/qmFI 6cNMafl1JX8Av5NtQKqvJj5tUu/gBBX8xw== X-Google-Smtp-Source: AA+uWPxX534TmAc1BmcK4Qzss276Cr4GdHxK+63vxc954e0XHkWnj10TLNbvRuVIZwAH8sRShRYpqw== X-Received: by 2002:a2e:4d9d:: with SMTP id c29-v6mr29504467ljd.132.1534756213155; Mon, 20 Aug 2018 02:10:13 -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 i2-v6sm1041025lfa.78.2018.08.20.02.10.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 02:10:12 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Jens Wiklander Subject: [PATCH v2 2/3] fdt: fdtdec_setup_memory_banksize() use livetree Date: Mon, 20 Aug 2018 11:09:59 +0200 Message-Id: <20180820091000.3241-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180820091000.3241-1-jens.wiklander@linaro.org> References: <20180820091000.3241-1-jens.wiklander@linaro.org> Converts fdtdec_setup_memory_banksize() to use ofnode functions instead. Reviewed-by: Simon Glass Signed-off-by: Jens Wiklander --- lib/fdtdec.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) -- 2.17.1 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