From patchwork Mon Feb 26 17:26:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 775928 Delivered-To: patch@linaro.org Received: by 2002:ab3:621a:0:b0:258:3251:9e33 with SMTP id w26csp1494918lte; Mon, 26 Feb 2024 09:31:02 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUOuXqNq2zBV31bIxPVwpa7o5Iw8PE5RwamCopaZF+wcOnxUiRoIg3U7myN4hOy4v5PZvTgkKeUU4aXebE2Ytqa X-Google-Smtp-Source: AGHT+IGYPehJBGPdWgABitT2erqw18g5REIkotghFDwq2OmW0Buj8MCu8E5q3R+6+X2Cm2mc2U8P X-Received: by 2002:a05:600c:4885:b0:412:981d:2889 with SMTP id j5-20020a05600c488500b00412981d2889mr4880887wmp.40.1708968662108; Mon, 26 Feb 2024 09:31:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708968662; cv=none; d=google.com; s=arc-20160816; b=k4hvIyIho/5C27yzSEE0C3RHPw8i6sjQ8guxqNuF8oanVE2cj+YAAwVZHxaY0Zkvyr obk4Pb7ABrz+kM0xFQeeIh2pHeBfFbmM7HkUzYBZXMlpRPfgrbB9a6Ponzmlopmfs4Co t/jesO/WQVI8xpXUK0dxOaIOEMELDZTd4eQaIEycxVB33e7G5e/qtcT0vFGnG0EbVUqp chK5ipCd+l0WKUUKypD7i7erxYNJ5L8ldnO6Nlp+z67iG5gZkaJGeljdiUVBDEb922nP C35X0z584s1J5pVEMOzs0ZQ1Kto47xMQaD1q6U68gJNwyJTynBxZOJok7W2YleAmI2KB 02XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=4bfGjUSY12UuXoCnxk3IB0+8QrNsn8oVVnRQLxMOJqQ=; fh=O9kXY3x7XLNLWAhzuQi/ll9/zTxQ4T3zqvdf+szIxkk=; b=GZkUtntEOXs6kpSK/a/BmkGUTm6bweGc7R17WL7t2Piwp7UTuMYj+79yNvZKOlMiko n1U7IzHZGfwtA+cYR4+qqSanPFwiD8Qq8zj/nG3hb7Z0LJpCbt4F4q28VcZSV3EP8sQO mb2LXjhYenkBJ+QJuTI51d5sgSx6feq2+pHI0LXZMVvZJ4s0+yBUPCnp60ty145F0/Q3 rPjds9JsZ2svikR7yxf34dQxqpwVScUwT7oIKEZ499qiCGrQyDGxl4pMGRM02KjrvYgh FS+ZC7oGa8FXr5lWKmeBsc/8z0oB205rzFrO+wxnOxGPSLJzcrSIvawFpX9UoIGszCA3 NH5g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GEruE5/5"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a5-20020a056000188500b0033d04d78fcbsi2866286wri.628.2024.02.26.09.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 09:31:02 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GEruE5/5"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 90C248801E; Mon, 26 Feb 2024 18:27:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="GEruE5/5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 014408800B; Mon, 26 Feb 2024 18:26:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 86A4087FB8 for ; Mon, 26 Feb 2024 18:26:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33d8739ddd4so2608574f8f.2 for ; Mon, 26 Feb 2024 09:26:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708968403; x=1709573203; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4bfGjUSY12UuXoCnxk3IB0+8QrNsn8oVVnRQLxMOJqQ=; b=GEruE5/5QCtgsUlVtvCDiju7V143AAz3INbDIqGIT2hmt6QHCS4FICofPTveNaqlvN yVchaZa1UyPHbMAiTZ6S8ILCsdNzYKC2TZQiMhvlSl9gQK3jnd2+XMOctGWqQd+TesX3 2W3wTm5cMt/vq8FKkp8kpNzv2b+GodGjjvS4v6lA37fcVLZP4mYXboTBop7eb8823oe5 bP9NdtHJt1pCzyxJjrq21Om7yqJ9HuWdcv7zOISSHvdimeYO4AEKZDl6Fzv573h2n+zV pgxmdG6kjaOh0a5K/oMYJ32MCd8V6+7Yge51QdIzoyJafcf+YzQ3M4RFbcHYuxJKI0tq YilA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708968403; x=1709573203; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4bfGjUSY12UuXoCnxk3IB0+8QrNsn8oVVnRQLxMOJqQ=; b=dTrDFuWJZlCYYSabhWjMI/htlW2yQs5tnODfZYn52DD7K44JJM8h3R4Gq+4ya/eamY tvu8WTAxx8j58fY+2xxnluY+xn6R3eWCXRbJ43S/tTYNDYFFQ1FfrqeBBhty//hMJiqX 8Wz0a55vgYqIGntDxiDdLsqj0P4HaUNhvDAbXPDV5FudnZEzEx7mESMNf7EBNiccD3x8 kCdAHlB8U07D1964RbgMGLvbb+n9cJmNKB+3tdxkcXpc0ZVclmvKf2e8TZsUfZ4o6eKy uPMbweSBVrwqxqbD4tOF2EiG4FkpE1wrmyTrYLp2nlunxxqnWHBGpnceepv2ekVYw6zs YCGQ== X-Forwarded-Encrypted: i=1; AJvYcCUK3rkTfckT1Drue/jHPc3AJR4SovA64SRHQnKr1Mt2fVERArV73ru/9JUD2vrnmxWoEcMTkPJ8qWIvWWyaDPudyjxFwA== X-Gm-Message-State: AOJu0YxCl+iq3VVAUKXm51CisiD18Z/4UJbv7hbIp7aQmM19sUpMlyLq +nRExErHJ21GXqgDe7BudDmlgVZY1VI7pGPBf8mO3xkQIeX00j9uGkdf0IFlYR0= X-Received: by 2002:a05:6000:1243:b0:33d:b32a:8acb with SMTP id j3-20020a056000124300b0033db32a8acbmr5326517wrx.23.1708968403019; Mon, 26 Feb 2024 09:26:43 -0800 (PST) Received: from lion.localdomain (host-92-17-96-232.as13285.net. [92.17.96.232]) by smtp.gmail.com with ESMTPSA id bt1-20020a056000080100b0033d9c7eb63csm9142256wrb.84.2024.02.26.09.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 09:26:42 -0800 (PST) From: Caleb Connolly Date: Mon, 26 Feb 2024 17:26:26 +0000 Subject: [PATCH v5 22/39] mach-snapdragon: generate fdtfile automatically MIME-Version: 1.0 Message-Id: <20240226-b4-qcom-common-target-v5-22-10c8e078befb@linaro.org> References: <20240226-b4-qcom-common-target-v5-0-10c8e078befb@linaro.org> In-Reply-To: <20240226-b4-qcom-common-target-v5-0-10c8e078befb@linaro.org> To: Neil Armstrong , Sumit Garg , Ramon Fried , Dzmitry Sankouski , Caleb Connolly , Peng Fan , Jaehoon Chung , Rayagonda Kokatanur , Lukasz Majewski , Sean Anderson , Jorge Ramirez-Ortiz , Stephan Gerhold Cc: Marek Vasut , u-boot@lists.denx.de X-Mailer: b4 0.13-dev-4bd13 X-Developer-Signature: v=1; a=openpgp-sha256; l=4668; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=qsVwCcVKBIhHDPA3LlNhly/wSFjfo707sJL8aVKs9H4=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtQ7J3f3rnAXfmfksbXHc8bdtoXbWDRuTjWN+DKxNbv41 jq7eedMO0pZGAQ5GGTFFFnETyyzbFp72V5j+4ILMHNYmUCGMHBxCsBEvn5lZGgUnL32Y9b7eSHT 311aHrvn/JL+qfYX3878IGgQfm0Xn2EdI8OcLP19HNEdit+3lbr01tltfbbIYEvW9hVfFWP3XF6 asPoGAA== X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean With just a few basic rules, we can generate the $fdtfile environment variable to match the format used in Linux. This uses the root compatible property inside u-boot, with specific handling for the Dragonboard845c which is a special case, and for the qrb robotics boards. This is known to work on supported platforms, and lets us avoid having a big lookup table. Reviewed-by: Neil Armstrong Reviewed-by: Sumit Garg Tested-by: Sumit Garg #qcs404 Signed-off-by: Caleb Connolly --- arch/arm/mach-snapdragon/board.c | 101 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index f445bed3af00..5a859aabd5c4 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -159,8 +159,108 @@ int board_init(void) qcom_board_init(); return 0; } +/* Sets up the "board", and "soc" environment variables as well as constructing the devicetree + * path, with a few quirks to handle non-standard dtb filenames. This is not meant to be a + * comprehensive solution to automatically picking the DTB, but aims to be correct for the + * majority case. For most devices it should be possible to make this algorithm work by + * adjusting the root compatible property in the U-Boot DTS. Handling devices with multiple + * variants that are all supported by a single U-Boot image will require implementing device- + * specific detection. + */ +static void configure_env(void) +{ + const char *first_compat, *last_compat; + char *tmp; + char buf[32] = { 0 }; + /* + * Most DTB filenames follow the scheme: qcom/-[vendor]-.dtb + * The vendor is skipped when it's a Qualcomm reference board, or the + * db845c. + */ + char dt_path[64] = { 0 }; + int compat_count, ret; + ofnode root; + + root = ofnode_root(); + /* This is almost always 2, but be explicit that we want the first and last compatibles + * not the first and second. + */ + compat_count = ofnode_read_string_count(root, "compatible"); + if (compat_count < 2) { + log_warning("%s: only one root compatible bailing!\n", __func__); + return; + } + + /* The most specific device compatible (e.g. "thundercomm,db845c") */ + ret = ofnode_read_string_index(root, "compatible", 0, &first_compat); + if (ret < 0) { + log_warning("Can't read first compatible\n"); + return; + } + + /* The last compatible is always the SoC compatible */ + ret = ofnode_read_string_index(root, "compatible", compat_count - 1, &last_compat); + if (ret < 0) { + log_warning("Can't read second compatible\n"); + return; + } + + /* Copy the second compat (e.g. "qcom,sdm845") into buf */ + strlcpy(buf, last_compat, sizeof(buf) - 1); + tmp = buf; + + /* strsep() is destructive, it replaces the comma with a \0 */ + if (!strsep(&tmp, ",")) { + log_warning("second compatible '%s' has no ','\n", buf); + return; + } + + /* tmp now points to just the "sdm845" part of the string */ + env_set("soc", tmp); + + /* Now figure out the "board" part from the first compatible */ + memset(buf, 0, sizeof(buf)); + strlcpy(buf, first_compat, sizeof(buf) - 1); + tmp = buf; + + /* The Qualcomm reference boards (RBx, HDK, etc) */ + if (!strncmp("qcom", buf, strlen("qcom"))) { + /* + * They all have the first compatible as "qcom,-" + * (e.g. "qcom,qrb5165-rb5"). We extract just the part after + * the dash. + */ + if (!strsep(&tmp, "-")) { + log_warning("compatible '%s' has no '-'\n", buf); + return; + } + /* tmp is now "rb5" */ + env_set("board", tmp); + } else { + if (!strsep(&tmp, ",")) { + log_warning("compatible '%s' has no ','\n", buf); + return; + } + /* for thundercomm we just want the bit after the comma (e.g. "db845c"), + * for all other boards we replace the comma with a '-' and take both + * (e.g. "oneplus-enchilada") + */ + if (!strncmp("thundercomm", buf, strlen("thundercomm"))) { + env_set("board", tmp); + } else { + *(tmp - 1) = '-'; + env_set("board", buf); + } + } + + /* Now build the full path name */ + snprintf(dt_path, sizeof(dt_path), "qcom/%s-%s.dtb", + env_get("soc"), env_get("board")); + env_set("fdtfile", dt_path); +} + void __weak qcom_late_init(void) { } @@ -187,8 +287,9 @@ int board_late_init(void) if (status) log_warning("%s: Failed to set run time variables\n", __func__); + configure_env(); qcom_late_init(); return 0; }