From patchwork Mon Jan 4 14:33:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 1422097 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=HE4KcUPh; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D8dRZ3yx1z9sVv for ; Tue, 5 Jan 2021 01:34:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7474282647; Mon, 4 Jan 2021 15:33:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com 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=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="HE4KcUPh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 313FD82462; Mon, 4 Jan 2021 15:33:55 +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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (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 1D0F682462 for ; Mon, 4 Jan 2021 15:33:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=narmstrong@baylibre.com Received: by mail-ej1-x62d.google.com with SMTP id d17so36978614ejy.9 for ; Mon, 04 Jan 2021 06:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=53LcLUPj9sgSrTm1nA7VE9Bin+ZvOn7XU9HMfMk/JOU=; b=HE4KcUPhQ73hZeNb35Y2oIRWzWEVh+WScTl5ZiSPq6rFxD4e5wJK1v0KfQBHpPIqW2 I/ej9shaM/xt4dSlVYrdYTbKUBhOu+9mmDWFCjF+3w4MB/C2kz1fEfTzQFawzw8pQdot GN7M+PZkPgCOo1uWEKTwgKNrkmgP/+ngeo8rOF512SqpJyiygnN9HTBHLd7p0/besxfR nBV8wMwS7HKqISRj3v267koluJnd4ABp5kwL+rUJezrlGSBpIRkI4HwT9YzUU3vmLfqR y9DM9eFOLsuRFF+8UJL6Qzq83Dz8bhVCPDRZKqrttw/2JnglZ+3kO8JsL98/5J21AjfS IISQ== 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:mime-version :content-transfer-encoding; bh=53LcLUPj9sgSrTm1nA7VE9Bin+ZvOn7XU9HMfMk/JOU=; b=EeZpF9PI9kx2lx0VoWmWfZ7CmUQFm0vxOOMFxRweeGesmINKGBsG0tv3h417fauYSX wDJY18NbVcwUFBpoxjyEGaslH6nh6mK1OFPGDHvU7BIuZFUTdXh3tRZSZB32pbWck/Gj 4uSD6sIo2j1s6wGjiUx6/HL/egZL5N17L5KjIiysh/pWElzWhhrcP62KL/TGYcftG+HP reH456ZhjKXsrfvlAkO0VDLEWM/30b0SCxaX2mj8BZmkiBWdObcGSpEhRsgtcE8QBWeN +oP3quGRoztjJwBQY9OOKOjzylYrmwfj8kS2U0jlWL4vq5R29dJc4bqm5R8rjQor8t7k j88A== X-Gm-Message-State: AOAM531YKIYzpP3UNwDY1EiLyERBql1gkylxJYr9uK7DGbtnQVfTICzu UgX1icLETFdgCxvL1N+Zv/hyQgIGuZeHHwqw X-Google-Smtp-Source: ABdhPJxj0utMvulVTN8KznW02yf0ahnC9ruxddzNvMp5WSvprSdqCDxiGLdJyhmZcuIoU9mbhQG5pQ== X-Received: by 2002:a17:907:20a4:: with SMTP id pw4mr66020050ejb.499.1609770831235; Mon, 04 Jan 2021 06:33:51 -0800 (PST) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:17a:9662:5ead:50af]) by smtp.gmail.com with ESMTPSA id a23sm16256853ejg.7.2021.01.04.06.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 06:33:50 -0800 (PST) From: Neil Armstrong To: u-boot@lists.denx.de, trini@konsulko.com Cc: Neil Armstrong , Andre Heider , =?utf-8?q?Jernej_=C5=A0krabec?= , Jonas Karlman Subject: [PATCH v2] cmd: pxe: add support for FDT overlays Date: Mon, 4 Jan 2021 15:33:43 +0100 Message-Id: <20210104143343.16037-1-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This adds support for specifying FDT overlays in an extlinux/pxelinux configuration file. Without this, there is no simple way to apply overlays when the kernel and fdt is loaded by the pxe command. This change adds the 'fdtoverlays' keyword for a label, supporting multiple overlay files to be applied on top of the fdt specified in the 'fdt' or 'devicetree' keyword. Example: label linux kernel /Image devicetree /soc-board.dtb fdtoverlays /soc-board-function.dtbo append console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait This code makes usage of a new variable called fdtoverlay_addr_r used to load the overlay files without overwritting anything important. Cc: Tom Rini Cc: Andre Heider Cc: Jernej Škrabec Cc: Jonas Karlman Signed-off-by: Neil Armstrong Tested-by: Jernej Skrabec Reviewed-by: Jernej Skrabec --- Hi Tom, This is repost of my last year's attempt. It fills a hole to allow loading FDT overlays using PXE/Extlinux without using FIT. V2 adds documentation. Neil cmd/pxe_utils.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ cmd/pxe_utils.h | 1 + doc/README.pxe | 9 +++++ 3 files changed, 113 insertions(+) diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c index 8716e782f6..25367190a7 100644 --- a/cmd/pxe_utils.c +++ b/cmd/pxe_utils.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include #include @@ -284,6 +286,9 @@ static void label_destroy(struct pxe_label *label) if (label->fdtdir) free(label->fdtdir); + if (label->fdtoverlays) + free(label->fdtoverlays); + free(label); } @@ -331,6 +336,92 @@ static int label_localboot(struct pxe_label *label) return run_command_list(localcmd, strlen(localcmd), 0); } +/* + * Loads fdt overlays specified in 'fdtoverlays'. + */ +#ifdef CONFIG_OF_LIBFDT_OVERLAY +static void label_boot_fdtoverlay(struct cmd_tbl *cmdtp, struct pxe_label *label) +{ + char *fdtoverlay = label->fdtoverlays; + struct fdt_header *working_fdt; + char *fdtoverlay_addr_env; + ulong fdtoverlay_addr; + ulong fdt_addr; + int err; + + /* Get the main fdt and map it */ + fdt_addr = simple_strtoul(env_get("fdt_addr_r"), NULL, 16); + working_fdt = map_sysmem(fdt_addr, 0); + err = fdt_check_header(working_fdt); + if (err) + return; + + /* Get the specific overlay loading address */ + fdtoverlay_addr_env = env_get("fdtoverlay_addr_r"); + if (!fdtoverlay_addr_env) { + printf("Invalid fdtoverlay_addr_r for loading overlays\n"); + return; + } + + fdtoverlay_addr = simple_strtoul(fdtoverlay_addr_env, NULL, 16); + + /* Cycle over the overlay files and apply them in order */ + do { + struct fdt_header *blob; + char *overlayfile; + char *end; + int len; + + /* Drop leading spaces */ + while (*fdtoverlay == ' ') + ++fdtoverlay; + + /* Copy a single filename if multiple provided */ + end = strstr(fdtoverlay, " "); + if (end) { + len = (int)(end - fdtoverlay); + overlayfile = malloc(len + 1); + strncpy(overlayfile, fdtoverlay, len); + overlayfile[len] = '\0'; + } else + overlayfile = fdtoverlay; + + if (!strlen(overlayfile)) + goto skip_overlay; + + /* Load overlay file */ + err = get_relfile_envaddr(cmdtp, overlayfile, + "fdtoverlay_addr_r"); + if (err < 0) { + printf("Failed loading overlay %s\n", overlayfile); + goto skip_overlay; + } + + /* Resize main fdt */ + fdt_shrink_to_minimum(working_fdt, 8192); + + blob = map_sysmem(fdtoverlay_addr, 0); + err = fdt_check_header(blob); + if (err) { + printf("Invalid overlay %s, skipping\n", + overlayfile); + goto skip_overlay; + } + + err = fdt_overlay_apply_verbose(working_fdt, blob); + if (err) { + printf("Failed to apply overlay %s, skipping\n", + overlayfile); + goto skip_overlay; + } + +skip_overlay: + if (end) + free(overlayfile); + } while ((fdtoverlay = strstr(fdtoverlay, " "))); +} +#endif + /* * Boot according to the contents of a pxe_label. * @@ -525,6 +616,11 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label) label->name); goto cleanup; } + +#ifdef CONFIG_OF_LIBFDT_OVERLAY + if (label->fdtoverlays) + label_boot_fdtoverlay(cmdtp, label); +#endif } else { bootm_argv[3] = NULL; } @@ -582,6 +678,7 @@ enum token_type { T_INCLUDE, T_FDT, T_FDTDIR, + T_FDTOVERLAYS, T_ONTIMEOUT, T_IPAPPEND, T_BACKGROUND, @@ -616,6 +713,7 @@ static const struct token keywords[] = { {"fdt", T_FDT}, {"devicetreedir", T_FDTDIR}, {"fdtdir", T_FDTDIR}, + {"fdtoverlays", T_FDTOVERLAYS}, {"ontimeout", T_ONTIMEOUT,}, {"ipappend", T_IPAPPEND,}, {"background", T_BACKGROUND,}, @@ -1048,6 +1146,11 @@ static int parse_label(char **c, struct pxe_menu *cfg) err = parse_sliteral(c, &label->fdtdir); break; + case T_FDTOVERLAYS: + if (!label->fdtoverlays) + err = parse_sliteral(c, &label->fdtoverlays); + break; + case T_LOCALBOOT: label->localboot = 1; err = parse_integer(c, &label->localboot_val); diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h index 77d2588875..6af9523734 100644 --- a/cmd/pxe_utils.h +++ b/cmd/pxe_utils.h @@ -43,6 +43,7 @@ struct pxe_label { char *initrd; char *fdt; char *fdtdir; + char *fdtoverlays; int ipappend; int attempted; int localboot; diff --git a/doc/README.pxe b/doc/README.pxe index 42f913c61f..352415b581 100644 --- a/doc/README.pxe +++ b/doc/README.pxe @@ -89,6 +89,9 @@ pxe boot fdt_addr - the location of a fdt blob. 'fdt_addr' will be passed to bootm command if it is set and 'fdt_addr_r' is not passed to bootm command. + fdtoverlay_addr_r - location in RAM at which 'pxe boot' will temporarily store + fdt overlay(s) before applying them to the fdt blob stored at 'fdt_addr_r'. + pxe file format =============== The pxe file format is nearly a subset of the PXELINUX file format; see @@ -148,6 +151,12 @@ kernel - if this label is chosen, use tftp to retrieve the kernel It useful for overlay selection in pxe file (see: doc/uImage.FIT/overlay-fdt-boot.txt) +fdtoverlays [...] - if this label is chosen, use tftp to retrieve the DT + overlay(s) at . it will temporarily stored at the + address indicated in the fdtoverlay_addr_r environment variable, + and then applied in the load order to the fdt blob stored at the + address indicated in the fdt_addr_r environment variable. + append - use as the kernel command line when booting this label.