From patchwork Wed Jan 20 08:54:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 1429091 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) 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=GxFvzyMM; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DLK985v0Bz9sVS for ; Wed, 20 Jan 2021 19:55:08 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 22C428280E; Wed, 20 Jan 2021 09:55:03 +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="GxFvzyMM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ED05B82813; Wed, 20 Jan 2021 09:55:00 +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-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 C97B9827D6 for ; Wed, 20 Jan 2021 09:54:57 +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-wm1-x330.google.com with SMTP id u14so2077827wmq.4 for ; Wed, 20 Jan 2021 00:54:57 -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=NuarbUnZfWqhnnXW3lpmfEHdF3L1ghlY+MoeabbmIec=; b=GxFvzyMMigGbPEfEKzs/A/mqpJLQG7qTkZspgIapOuCovJK1oberyKy3UcJkrf0yLG HvN3kun6pMuqzxm/LueXi9/eV4ECUIWFhB+xjXxpxEVqrCHouiLM3RGexcuPdlwU1gSu YyrDmcydSapsPISWbKdBtnB82D+lfJezoLxcajhTBFbEtks0754hLdz0vMV8J8h9rjQS K3IckWfAB9Lv6vl9kvQjnAUYDsJmS572MXJ0kGt0V89vr2hInjYThFowjrzALK5g9md5 +qpDBcHnwde5yS10wv4UyvX319/zij5HPh/XCVdKVDYpo5jtpVrmgSut64r1MIhrF2pp AofQ== 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=NuarbUnZfWqhnnXW3lpmfEHdF3L1ghlY+MoeabbmIec=; b=J3ow5QnvHLSsKm3pR0g4Tnrxyt1l+bADKdcQ86TcPWU5qYNDrqZt1FVW8i7fry0WUA 0sRay7ctzkoS39i4lEk1dcOmg5KXlbaDjMZKZVUAWAlHKeZpF5l63fMnFaXESwgSORhs 2sw+18r31O0XTLq3UhUB+VrSdChQizb194XX93HxN/i/9EUdX+2kRMsMcUUYFIsKUwU8 T+j+b0cWn7vUirE0frCmlh38qBJ1EnF5N5ixNT3wzlAbzbdxBKaHrfHWWA8fpv51JYKo cqbGbMAYcLCoqHiSWt0YDc3PKutiq2D9+uIjP0jcCtc5wfczKCDMq3HSB2ZOFNIMpuP0 kH+w== X-Gm-Message-State: AOAM531p8yIHNhJegeUJi4lki7jiAzY50nfwMkiwEHqQaHrPbAmCFGb5 12hma/gEhnU3VImT3JlOpOdHVMLA8De17ZWv X-Google-Smtp-Source: ABdhPJzdLWdHAp/X008FuEi+Rk7sB8TyB9y4Xab/AxPDSDLs55txLY5Ps4QAWYNeCasb+aoyfoeMeg== X-Received: by 2002:a05:600c:4ed3:: with SMTP id g19mr3196034wmq.95.1611132896913; Wed, 20 Jan 2021 00:54:56 -0800 (PST) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:c425:fafb:abed:a263]) by smtp.gmail.com with ESMTPSA id p18sm2529768wmc.31.2021.01.20.00.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:54:56 -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 v3] cmd: pxe: add support for FDT overlays Date: Wed, 20 Jan 2021 09:54:53 +0100 Message-Id: <20210120085453.2783678-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 fdt /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 Tested-by: Jernej Škrabec Reviewed-by: Jernej Škrabec Signed-off-by: Neil Armstrong --- Changes since v2: - fixed typo in commit log - fixed in README.pxe - added review & test tags from Jernej 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 b9d9a5786c..3526a651d7 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); } @@ -332,6 +337,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. * @@ -534,6 +625,11 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label) goto cleanup; } } + +#ifdef CONFIG_OF_LIBFDT_OVERLAY + if (label->fdtoverlays) + label_boot_fdtoverlay(cmdtp, label); +#endif } else { bootm_argv[3] = NULL; } @@ -591,6 +687,7 @@ enum token_type { T_INCLUDE, T_FDT, T_FDTDIR, + T_FDTOVERLAYS, T_ONTIMEOUT, T_IPAPPEND, T_BACKGROUND, @@ -625,6 +722,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,}, @@ -1057,6 +1155,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..b67151ca51 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 be 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.