Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C742BC54EBC for ; Sun, 8 Jan 2023 02:51:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1159F85663; Sun, 8 Jan 2023 03:51:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Lafo2YWJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD08785623; Sun, 8 Jan 2023 03:51:09 +0100 (CET) Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) (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 C55D585413 for ; Sun, 8 Jan 2023 03:50:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x132.google.com with SMTP id bp26so3302388ilb.3 for ; Sat, 07 Jan 2023 18:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=O8QpM+zqIVv/5levmZkTl+43KWowgMJaoHbLyLCb6zQ=; b=Lafo2YWJc5cQ7Rz+qQAvywyA01CGaA6Kvwn0MnDgZH2UraxhEySdxa4y9/FW0yS4qz V1Ank0cT+tKa0fD2S26BGOeJANU/wsYgRs/ZdDo/t34a883Vhr4Wc7LcqIdkXF+M7Bxx uBGH+lco5yfmx+b8aRWwH4z/lUEQ9IY4JcuFw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O8QpM+zqIVv/5levmZkTl+43KWowgMJaoHbLyLCb6zQ=; b=Y/LwxLZt1wAqSlbL98wdConJirt8aLDNAWkVF4O7orJ69UmJaSH0RVi32bZVfoxOLs wjdbbmF2Mnmke4+qJg9dA64ziYrz/fO3U5hb0Vi0tTlyMvJyqyMBU9DoJH0My1BpmxRO 89XyukA8F/rviZLHk/3c2L0GMzNBrgkCcrOg8jY5a8MQH6sb7GenKX1oelvg6ecrza2a jx19kOZrbcjGlR0vbYgrsiXynFe1zeIvwCtpcW4y9PM1U5dCW8+X8bNOay0pfvHoO2pZ EN1xVKPY1mq7Bqe57evmC+QuU+9tlaRn5K3ar0HvsbwqByXvs+Q8X9cEchA8vbzGs+FZ jrhg== X-Gm-Message-State: AFqh2kqpOen/LQPpcTqpXnQwQO/X/Wu//x+vWUi1+i62myVHaqbR6azD vCDEtiiMT/ygJEoRzAdoXLWai9soqUKgJ7T6 X-Google-Smtp-Source: AMrXdXvbbwkpJZfa9axeBhUf44z5vYwe9FuNBIbn0nOplQuXwaMdEv59cpU3iJYCvIM8UaenkDg+Vg== X-Received: by 2002:a92:870d:0:b0:307:739a:db47 with SMTP id m13-20020a92870d000000b00307739adb47mr42969538ild.27.1673146251851; Sat, 07 Jan 2023 18:50:51 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id c17-20020a92bd11000000b00302a00aaefasm1622174ile.26.2023.01.07.18.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:50:51 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass , Jaehoon Chung , Jeffy Chen , Joe Hershberger , Kever Yang , Marek Vasut , Pavel Herrmann , Peng Fan , Philipp Tomsich , Rob Herring , huang lin Subject: [PATCH v2 00/71] bootstd: Allow migration from distro_bootcmd scripts Date: Sat, 7 Jan 2023 19:49:36 -0700 Message-Id: <20230108025047.522240-1-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean So far, standard boot does not replicate all the of the functionality of the distro_bootcmd scripts. In particular it lacks some bootdevs and some of the bootmeths are incomplete. Also there is currently no internal mechanism to enumerate buses in order to discover bootdevs, e.g. with USB. This series addresses these shortcomings: - Adds the concept of a 'bootdev hunter' to enumerate buses, etc. in an effort to find bootdevs of a certain priority - Adds bootdevs for SCSI, IDE, NVMe, virtio, SPI flash - Handles PXE and DHCP properly - Supports reading the device tree with EFI and reading scripts from the network It also tidies up label processing, so it is possible to use: bootflow scan mmc2 to scan just one MMC device (with BOOTSTD_FULL). As before this implementation still relies on CONFIG_CMDLINE being enabled, mostly for the network stack. Further work would be required to disentangle that. Quite a few tests are added but there are some gaps: - SPI flash bootdev - EFI FDT loading Note that SATA works via SCSI (CONFIG_SCSI_AHCI) and does not use driver model. Only pogo_v4 seems to be affected. Probably all thats is needed is to call bootdev_setup_sibling_blk() in the Marvell SATA driver. Also, while it would be possible to init MMC in a bootdev hunter, there is no point since U-Boot always inits MMC on startup, if present. With this series it should be possible to migrate boards to standard boot by removing the inclusion of config_distro_bootcmd.h and instead adding a suitable value for boot_targets to the environment, e.g.: boot_targets=mmc1 mmc0 nvme scsi usb pxe dhcp spi Thus it is possible to boot automatically without scripts and boards can use a text-based environment instead of the config.h files. To demonstrate this, rockpro64-rk3399 is migrated to standard boot in this series. Full migration could probably be automated using a script, similar in concept to moveconfig: - obtain the board environment via 'make u-boot-initial-env' - get the value of "boot_targets" - drop config_distro_bootcmd.h from the config.h file - rebuild again to get the environment without distro scripts - write the environment (adding boot_targets) to board.env - remove CONFIG_EXTRA_ENV_SETTINGS from the config.h file This series is based on top of the boot menu series v3 [1]. The tree is available at u-boot-dm/dis-working [1] https://patchwork.ozlabs.org/project/uboot/list/?series=335364 Changes in v2: - Rebase to -next Simon Glass (71): dm: core: Correct ordering of uclasses IDs dm: core: Support sorting devices with dm tree dm: test: Correct assertion in dm_test_part() lib: Add a function to split a string into substrings bootstd: Remove special-case code for boot_targets bootstd: Simplify locating existing bootdevs test: Fix the help for the ut command test: Drop duplicate restore of DM state sandbox: mmc: Start off with a zeroed file vbe: Avoid a build failure when bloblist is not enabled vbe: sandbox: Drop VBE node in chosen dm: part: Update test to use mmc2 dm: test: Correct ordering of DM setup ide: Drop non-DM code for BLK dm: mmc: Use bootdev_setup_sibling_blk() bootstd: Add a default method to get bootflows sandbox: Allow ethernet to be disabled at runtime sandbox: Allow ethernet bootdevs to be disabled for tests sandbox: Enable the Ethernet bootdev lib: Support printing an error string event: Correct duplicate log message in event_notify() efi: Improve logging in efi_disk bootstd: Add the concept of a bootdev hunter bootstd: Support running bootdev hunters dm: usb: Drop some dead code dm: usb: Mark the device name as alloced when binding test: Add a generic function to skip delays bootstd: Add a USB hunter bootstd: Add an MMC hunter net: Add a function to run dhcp bootstd: Add a hunter for ethernet part: Add a function to find the first bootable partition bootstd: Only scan bootable partitions scsi: Correct allocation of block-device name scsi: Remove all children of SCSI devices before rescanning bootstd: Add a SCSI bootdev bootstd: Add an IDE bootdev bootstd: Add an NVMe bootdev virtio: Avoid repeating a long expression virtio: Fix returning -ENODEV virtio: Avoid strange behaviour on removal virtio: Add a block device bootstd: Add a virtio bootdev ata: Don't try to use non-existent ports bootstd: Rename bootdev checkers bootstd: Allow reading an EFI file from the network bootstd: Include the device tree in the bootflow bootstd: Support reading the device tree with EFI bootstd: Set the distro_bootpart env var with scripts bootstd: Update docs on bootmeth_try_file() for sandbox bootstd: Move label parsing into its own function bootstd: Add a new bootmeth method to set the bootflow sandbox: Allow SPI flash bootdevs to be disabled for tests bootstd: Add a SPI flash bootdev bootstd: Support reading a script from network or SPI flash bootstd: Treat DHCP and PXE as bootdev labels bootstd: Use hunters when scanning for bootflows bootstd: Allow hunting for bootdevs of a given priority bootstd: Add a new pre-scan priority for bootdevs bootstd: Allow hunting for a bootdev by label bootstd: Allow iterating to the next label in a list bootstd: Allow iterating to the next bootdev priortiy extension: Refactor to allow non-command usage bootstd: Add a hunter for the extension feature bootstd: Switch bootdev scanning to use labels bootstd: Allow scanning a single bootdev label bootstd: Drop the old bootflow_scan_first() bootstd: Record the bootdevs used during scanning bootstd: Add a little more logging of bootflows bootstd: Update documentation for new features rockchip: Convert rockpro64-rk3399 to use standard boot arch/sandbox/cpu/state.c | 30 ++ arch/sandbox/dts/sandbox.dtsi | 13 - arch/sandbox/dts/test.dts | 6 + arch/sandbox/include/asm/state.h | 2 + arch/sandbox/include/asm/test.h | 30 ++ boot/bootdev-uclass.c | 551 +++++++++++++++++++--------- boot/bootflow.c | 173 ++++++--- boot/bootmeth-uclass.c | 11 + boot/bootmeth_distro.c | 2 +- boot/bootmeth_efi.c | 220 ++++++++++- boot/bootmeth_efi_mgr.c | 2 +- boot/bootmeth_pxe.c | 5 +- boot/bootmeth_script.c | 98 ++++- boot/bootstd-uclass.c | 17 +- boot/vbe_simple_fw.c | 2 +- cmd/bootdev.c | 42 ++- cmd/bootflow.c | 97 +++-- cmd/dm.c | 10 +- cmd/extension_board.c | 43 ++- cmd/net.c | 35 ++ cmd/vbe.c | 7 +- common/event.c | 2 +- configs/sandbox_defconfig | 2 +- configs/sandbox_flattree_defconfig | 10 +- disk/part.c | 16 + doc/develop/bootstd.rst | 221 +++++++---- doc/develop/driver-model/nvme.rst | 2 +- doc/usage/cmd/bootdev.rst | 48 ++- doc/usage/cmd/bootflow.rst | 17 +- doc/usage/cmd/dm.rst | 5 +- drivers/ata/ahci.c | 6 + drivers/block/ide.c | 86 ++--- drivers/core/dump.c | 65 +++- drivers/mmc/mmc-uclass.c | 2 +- drivers/mmc/mmc_bootdev.c | 33 +- drivers/mmc/sandbox_mmc.c | 2 +- drivers/mtd/spi/Kconfig | 8 + drivers/mtd/spi/Makefile | 1 + drivers/mtd/spi/sf-uclass.c | 11 + drivers/mtd/spi/sf_bootdev.c | 82 +++++ drivers/nvme/nvme-uclass.c | 54 +++ drivers/nvme/nvme.c | 5 + drivers/scsi/Makefile | 7 + drivers/scsi/scsi.c | 32 +- drivers/scsi/scsi_bootdev.c | 62 ++++ drivers/usb/host/usb-uclass.c | 45 +-- drivers/usb/host/usb_bootdev.c | 38 +- drivers/virtio/virtio-uclass.c | 62 +++- drivers/virtio/virtio_sandbox.c | 16 +- include/bootdev.h | 206 ++++++++++- include/bootflow.h | 134 +++++-- include/bootmeth.h | 35 +- include/bootstd.h | 17 +- include/configs/rk3399_common.h | 5 +- include/configs/rockchip-common.h | 2 + include/dm/uclass-id.h | 4 +- include/dm/util.h | 8 +- include/net.h | 31 ++ include/part.h | 8 + include/test/test.h | 72 ++++ include/vsprintf.h | 24 ++ lib/efi_loader/efi_disk.c | 30 +- lib/strto.c | 41 +++ lib/vsprintf.c | 12 + net/eth-uclass.c | 14 +- net/eth_bootdev.c | 68 ++-- net/net.c | 4 + test/boot/bootdev.c | 563 +++++++++++++++++++++++++++-- test/boot/bootflow.c | 138 +++++-- test/boot/bootstd_common.c | 19 + test/boot/bootstd_common.h | 13 + test/cmd_ut.c | 2 +- test/dm/part.c | 37 +- test/dm/virtio_device.c | 3 + test/py/tests/bootstd/mmc1.img.xz | Bin 4448 -> 4480 bytes test/py/tests/test_dm.py | 38 ++ test/py/tests/test_ut.py | 13 +- test/str_ut.c | 82 +++++ test/test-main.c | 24 +- 79 files changed, 3225 insertions(+), 758 deletions(-) create mode 100644 drivers/mtd/spi/sf_bootdev.c create mode 100644 drivers/scsi/scsi_bootdev.c -- 2.39.0.314.g84b9a713c41-goog