Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2406081yba; Sun, 7 Apr 2019 18:06:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqygZpXn6TTEZ5nO0PoiyfC7gp3BrBfDOVmmtWafH7va05B/RcaNR0suNVXD34lPNLLczv5G X-Received: by 2002:a63:5e43:: with SMTP id s64mr24589506pgb.15.1554685572399; Sun, 07 Apr 2019 18:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554685572; cv=none; d=google.com; s=arc-20160816; b=TpqcnU4dW5NAF4mzbkItokMt7fa4DLX/Bd0QgAzZBhMGrRjYqcZyc6Zs9KIzInRcB/ JNFwwAEeyC1TQe1zvWhhm83m559WuhRP4WE+xRy1GwkrG2WAmbnmXummke8qp9Y94pg8 msfw3D6RgB3DLT5zQi70Tu7cCyTCsvgwqTrlCarVgNGh/Tsu++va6+AJ8ECP+UyBT5dE FJU/9g+vLRGHxGA/MpZsMjUTUTJg+1nMcmB3uSx7HO2N4Be60AiVqgfCwowESwj+mjZ3 t+nP1GXaQAJw2o/dq2PsCwcyLR6hxqM58Y/jUv/phzWSRyPsOsB0W2J71DgTeRCtjwyK t2Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=PRZuwdqNrDmLOSIG1Aix46gTawZmZ1+exJPbBgpW89g=; b=upln98ymv+OyYF+tWUDy8b6VSpvLzMNhK0LuXBGKcculQiy3HcdBCXGsJH+G4tLwKx 7g3tTrIkMzi4mFgRNUos+MnMtBFJ69Er+r1kl26wZExqiuDkddQQGRUF5ZwDB56hFjdZ oHYXTxSn1/dTU4/b74mz2cuu4mDTO1HTRP7tSzdnGf3JAYUJ1VVK6QfRZjS+EEuBOmkZ 9nqmEaNK3gSVh3Sz6relTWs2ghBppMSvNpHJv/vHkfjzEmHxD6EVfelV8bIXPxZTpm24 8pn3sZBgwmmiE9UQSufpIj0aznAJCeKjDc0Sdx2vz3h1cD2+sFTmy6Cgyqup0blccg9D WXfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GI6xxjSD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cv9si26477263plb.371.2019.04.07.18.05.55; Sun, 07 Apr 2019 18:06:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GI6xxjSD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726464AbfDHBFS (ORCPT + 99 others); Sun, 7 Apr 2019 21:05:18 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:38544 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726431AbfDHBFS (ORCPT ); Sun, 7 Apr 2019 21:05:18 -0400 Received: by mail-pl1-f196.google.com with SMTP id f36so1823738plb.5; Sun, 07 Apr 2019 18:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=PRZuwdqNrDmLOSIG1Aix46gTawZmZ1+exJPbBgpW89g=; b=GI6xxjSDP/CHore2xT0PGImeHE5sBpc0peysmIsRdbm374fACFuXN/ER+jLMbyVAmF SbLYLV/rSQ1yUpaONR/DOT2DufiHXg9d4mFplnOgui9EUmi3bo4vOlre4az03610DQcc OTL70QbDqvI4EHMn6hSpYO21aJ/1kR2IW+WVDtDTO6+/rJ4kegdSQ0H2GMFcmCE4y2tf 8U5szm7i6wpR0Pimp7qTaVgQCNgNE9ismCOgtGI24yVTPb+n2aC7oiuXKWZoZfT752I/ KoQPzD6OWzTYX/LIdPY/W1lHURIhbHhY00zmqxUwsPB36M2MS0Fg06hdWnmJM4C6Pk6g CD1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PRZuwdqNrDmLOSIG1Aix46gTawZmZ1+exJPbBgpW89g=; b=tvMDMmS0AV7TV4LL++Njf85dMMkeBQCaUrqJyDOskCqm0ZKBFyHEGAAGHZi4ELRUs7 HX8TCTmf2cb/utQ8x88HtvPcJ/fvkWxlAF7LYKUfFBYwsGHqgkseX5O+lucVt5EaUvuC yYzioZThuJhRSKML4rkGA66m1M1gdO/QjUUaoLhn53f+KXBIi8RkQIQkzrzKAKp10oTV TORzWHMlXKXEC9VP36JBd9WSh7PVgAXte+tKRmMytThRy1VoxNKf8V8QahQl/zQrZ7lL 9EAtbFUL+SDhmaDRl2+azZ152NWJAxNkB1rWCH+evnObjTPfMVMLMAt5pPXholGAhJG6 PseA== X-Gm-Message-State: APjAAAUFNPVbUulw1qZRYCgzpZRoneU9pSUQxpAG4Q44cQKTeThFO2RO lqWZtgB13Vy8eTOp+6VnA4Y= X-Received: by 2002:a17:902:d70f:: with SMTP id w15mr27404577ply.134.1554685517683; Sun, 07 Apr 2019 18:05:17 -0700 (PDT) Received: from [192.168.1.70] (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id z14sm42105223pfn.161.2019.04.07.18.05.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Apr 2019 18:05:16 -0700 (PDT) Subject: Re: Using device tree overlays in Linux To: Chris Packham , "pantelis.antoniou@konsulko.com" , "robh+dt@kernel.org" Cc: "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Hamish Martin References: <71fb0ff289e84c55bd92ecd96bc9aa76@svr-chch-ex1.atlnz.lc> From: Frank Rowand Message-ID: <61185ee9-4bee-eec3-f0d0-6d6760595845@gmail.com> Date: Sun, 7 Apr 2019 18:05:15 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <71fb0ff289e84c55bd92ecd96bc9aa76@svr-chch-ex1.atlnz.lc> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chris, On 4/3/19 6:50 PM, Chris Packham wrote: > Hi, > > I'm implementing support for some modular Linux based systems using > device tree overlays. The code is working but it seems a little more > fiddly that than it should be so I'm wondering if I'm doing it right. Let me start by saying that I strongly discourage using device tree overlays in the Linux kernel until the support is more baked. For some info on how unbaked overlays are, see: https://elinux.org/Frank%27s_Evolving_Overlay_Thoughts You should consider applying overlays in the Linux kernel to be fragile at best. If you can not figure out how to solve your needs without using overlays, then having the boot loader apply the overlay instead of the kernel applying the overlay avoids most of the issues. > An example of what I'm doing is > > > arch/arm/boot/dts/Makefile: > DTC_FLAGS_myboard += -@ > > drivers/foo/Makefile: > obj-y += myplugin.dtb.o > obj-y += mydriver.o > > drivers/foo/myplugin.dts: > /dts-v1/; > /plugin/; > /{ > fragment@0 { > target = <&i2c0>; > __overlay__ { > gpio@74 { > compatible = "nxp,pca9539"; > reg = <0x74> > }; > }; > }; > }; The fragment and __overlay__ nodes are implementation, subject to change, and should not be hand coded. The dtc compiler has added features to allow a more generic source code. The above should be: // SPDX-License-Identifier: GPL-2.0 /dts-v1/; /plugin/; &i2c0 { gpio@74 { compatible = "nxp,pca9539"; reg = <0x74>; }; }; (Not compiled, not tested.) The rcar overlay sources were merged before dtc was updated to handle this new syntax, so they are not a good example for how to write an overlay. > drivers/foo/mydriver.c: > extern uint8_t __dtb_myplugin_begin[]; > extern uint8_t __dtb_myplugin_end[]; > > int mydriver_probe(struct platform_device *pdev) > { > u32 size = __dtb_myplugin_end - __dtb_myplugin_begin; > int overlay_id; > int ret; > > ret = of_overlay_fdt_apply(__dtb_myplugin_begin, > size, &overlay_id); > return ret; > } I'm guessing that you have simplified your use case to make it easier to describe (thank you for that). But that also makes it harder to understand the use case, and whether this is a good solution. Can you describe your use case in some more detail? > The first issue is that I need to add -@ to the DTC_FLAGS for my board > dtb. I kind of understand that I only need -@ if my overlay targets > something symbolic so I might not need it but I was surprised that there > wasn't a Kconfig option that makes this happen automatically. > > externing things in C files makes checkpatch.pl complain. I see the > of/unittests.c and rcar_du_of.c hide this with a macro. I was again > surprised that there wasn't a common macro to declare these. unittests.c should not be used as a model of how to code for devicetree. There are some hacks that are needed to be able to test, but should not be used by normal drivers. The rcar use of overlays is a temporary hack to provide backward compatibility. The intent is to drop this code once the backward compatibility window ends. The long-term intent (once enough of the overlay code is in place) is to provide an overlay loader than can apply an overlay .dtb from a file. -Frank