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 2F572C38A02 for ; Sun, 30 Oct 2022 01:51:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CAB9C85175; Sun, 30 Oct 2022 02:48:19 +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="nKIj7fml"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AFF7E85152; Sun, 30 Oct 2022 02:47:57 +0100 (CET) Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (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 20CBC8510F for ; Sun, 30 Oct 2022 02:47: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-io1-xd2b.google.com with SMTP id z3so7459274iof.3 for ; Sat, 29 Oct 2022 18:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SAFFA7Ilo6W2ETSuj/7YmHjwjP6klPKZcK11oUjeqK8=; b=nKIj7fmlZX8zmx4BgSM4TxRjai5E5sgfQ2Av9aVg/4aGwYRk5UpeDBQbfp2oDyN5dD sltN5T/7ZUPsanmcF9/I4P25x1/ma8HFcEdxhYbpMyXBM3/27v8IJUZLujrfxd1+REzt q/gGWkCVak9pSEqBqKlBe0t2kHZCdbjUlen0w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SAFFA7Ilo6W2ETSuj/7YmHjwjP6klPKZcK11oUjeqK8=; b=2pq8B/d3D80FU4GxWD2fKZvmxzqp+73evpSIOMsFa7h1lproDXIH9Jy2ZIRp956ujK LL8jP+lxGlJf8+fe6wD2EjmlJ+105FrdQK+bQQETx09x6kmOJNvr2e+FGDHneEFP7W7R 2IchVXzuC5AVbocZyR8ctUAEFYRiQa9usLTltJcois4Ta/TOezEWf+scbpeLlUPIWe80 +4mkA4eQLOg8GImDVAW4s5pAK5BqajYury82wlCqmEAJxStN4O17yQiVbX+4BZm7TQMq B2fx0rYrlE3vEdH7kS8cCdGtwsN1ObKCbDFHckH9rTbI0kb6yBsJZlx5/mryUYwCASJf PDAw== X-Gm-Message-State: ACrzQf0oddhSNBGMV5l+c04//2A5LWeaFUPhBV1aGdEP4fk4MyHFCZYn 7uOH4eZI9PkbS4cPNr3pKMo/45ihuKP/8g== X-Google-Smtp-Source: AMsMyM7P2slSad2RrNK3trS5EK0G9zJOz82r4iibCtKS8eEJIleAMWNDXpr+Staz9LsCj96IdV68ug== X-Received: by 2002:a6b:6709:0:b0:6ca:d453:f48b with SMTP id b9-20020a6b6709000000b006cad453f48bmr2869524ioc.12.1667094471300; Sat, 29 Oct 2022 18:47:51 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id x66-20020a0294c8000000b00363c4307bb2sm810287jah.79.2022.10.29.18.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 18:47:51 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , AKASHI Takahiro , Ilias Apalodimas , Marcel Ziswiler , Marek Vasut , Michal Suchanek , Oleksii Bidnichenko , Pavel Herrmann , Ramon Fried , Sean Anderson , Stefan Herbrechtsmeier , schspa Subject: [PATCH 15/17] dm: sandbox: Switch over to using the new host uclass Date: Sat, 29 Oct 2022 19:47:17 -0600 Message-Id: <20221030014719.147327-16-sjg@chromium.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221030014719.147327-1-sjg@chromium.org> References: <20221030014719.147327-1-sjg@chromium.org> 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 Update the sandbox implementation to use UCLASS_HOST and adjust all the pieces to continue to work: - Update the 'host' command to use the new API - Replace various uses of UCLASS_ROOT with UCLASS_HOST - Disable test_eficonfig since it doesn't work (this should have a unit test to allow this to be debugged) - Update the blk test to use the new API - Drop the old header file Unfortunately it does not seem to be possible to split this change up further. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dts | 4 - cmd/host.c | 204 ++++++++++++------ disk/part.c | 4 +- drivers/block/blk-uclass.c | 2 +- drivers/block/sandbox.c | 134 ++---------- include/sandboxblockdev.h | 28 --- lib/efi_loader/efi_device_path.c | 5 +- lib/efi_loader/efi_disk.c | 2 +- test/dm/blk.c | 47 ++-- .../py/tests/test_eficonfig/test_eficonfig.py | 3 + 10 files changed, 184 insertions(+), 249 deletions(-) delete mode 100644 include/sandboxblockdev.h diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index 21f00fcab5e..840b8b503fa 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -65,10 +65,6 @@ reg = <0x10002000 0x1000>; }; - host-fs { - compatible = "sandbox,bootdev-host"; - }; - i2c_0: i2c@0 { #address-cells = <1>; #size-cells = <0>; diff --git a/cmd/host.c b/cmd/host.c index f09ac8d4396..fb1cb1fdd1a 100644 --- a/cmd/host.c +++ b/cmd/host.c @@ -8,12 +8,12 @@ #include #include #include -#include +#include #include +#include +#include #include -static int host_curr_device = -1; - static int do_host_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -42,10 +42,10 @@ static int do_host_bind(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { bool removable = false; - const char *dev_str; + struct udevice *dev; + const char *label; char *file; - char *ep; - int dev; + int ret; /* Skip 'bind' */ argc--; @@ -61,97 +61,158 @@ static int do_host_bind(struct cmd_tbl *cmdtp, int flag, int argc, if (argc > 2) return CMD_RET_USAGE; - dev_str = argv[0]; - dev = hextoul(dev_str, &ep); - if (*ep) { - printf("** Bad device specification %s **\n", dev_str); + label = argv[0]; + file = argc > 1 ? argv[1] : NULL; + + ret = host_create_attach_file(label, file, removable, &dev); + if (ret) { + printf("Cannot create device / bind file\n"); + return CMD_RET_FAILURE; + } + + return 0; +} + +/** + * parse_host_label() - Parse a device label or sequence number + * + * This shows an error if it returns NULL + * + * @label: String containing the label or sequence number + * Returns: Associated device, or NULL if not found + */ +static struct udevice *parse_host_label(const char *label) +{ + struct udevice *dev; + + dev = host_find_by_label(label); + if (!dev) { + int devnum; + char *ep; + + devnum = hextoul(label, &ep); + if (*ep || + uclass_find_device_by_seq(UCLASS_HOST, devnum, &dev)) { + printf("No such device '%s'\n", label); + return NULL; + } + } + + return dev; +} + +static int do_host_unbind(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct udevice *dev; + const char *label; + int ret; + + if (argc < 2) return CMD_RET_USAGE; + + label = argv[1]; + dev = parse_host_label(label); + if (!dev) + return CMD_RET_FAILURE; + + ret = host_detach_file(dev); + if (ret) { + printf("Cannot detach file (err=%d)\n", ret); + return CMD_RET_FAILURE; + } + + ret = device_unbind(dev); + if (ret) { + printf("Cannot attach file\n"); + ret = device_unbind(dev); + if (ret) + printf("Cannot unbind device '%s'\n", dev->name); + return CMD_RET_FAILURE; } - file = argc > 1 ? argv[1] : NULL; - return !!host_dev_bind(dev, file, removable); + return 0; +} + +static void show_host_dev(struct udevice *dev) +{ + struct host_sb_plat *plat = dev_get_plat(dev); + struct blk_desc *desc; + struct udevice *blk; + int ret; + + printf("%3d ", dev_seq(dev)); + if (!plat->fd) { + printf("Not bound to a backing file\n"); + return; + } + ret = blk_get_from_parent(dev, &blk); + if (ret) /* cannot happen */ + return; + + desc = dev_get_uclass_plat(blk); + printf("%12lu %-15s %s\n", (unsigned long)desc->lba, plat->label, + plat->filename); } static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - if (argc < 1 || argc > 2) + struct udevice *dev; + + if (argc < 1) return CMD_RET_USAGE; - int min_dev = 0; - int max_dev = SANDBOX_HOST_MAX_DEVICES - 1; + + dev = NULL; if (argc >= 2) { - char *ep; - char *dev_str = argv[1]; - int dev = hextoul(dev_str, &ep); - if (*ep) { - printf("** Bad device specification %s **\n", dev_str); - return CMD_RET_USAGE; - } - min_dev = dev; - max_dev = dev; + dev = parse_host_label(argv[1]); + if (!dev) + return CMD_RET_FAILURE; } - int dev; - printf("%3s %12s %s\n", "dev", "blocks", "path"); - for (dev = min_dev; dev <= max_dev; dev++) { - struct blk_desc *blk_dev; - int ret; - - printf("%3d ", dev); - ret = host_get_dev_err(dev, &blk_dev); - if (ret) { - if (ret == -ENOENT) - puts("Not bound to a backing file\n"); - else if (ret == -ENODEV) - puts("Invalid host device number\n"); - - continue; - } - struct host_block_dev *host_dev; - host_dev = dev_get_plat(blk_dev->bdev); - printf("%12lu %s\n", (unsigned long)blk_dev->lba, - host_dev->filename); + printf("%3s %12s %-15s %s\n", "dev", "blocks", "label", "path"); + if (dev) { + show_host_dev(dev); + } else { + struct uclass *uc; + + uclass_id_foreach_dev(UCLASS_HOST, dev, uc) + show_host_dev(dev); } + return 0; } static int do_host_dev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - int dev; - char *ep; - struct blk_desc *blk_dev; - int ret; + struct udevice *dev; + const char *label; if (argc < 1 || argc > 3) return CMD_RET_USAGE; if (argc == 1) { - if (host_curr_device < 0) { + struct host_sb_plat *plat; + + dev = host_get_cur_dev(); + if (!dev) { printf("No current host device\n"); - return 1; + return CMD_RET_FAILURE; } - printf("Current host device %d\n", host_curr_device); + plat = dev_get_plat(dev); + printf("Current host device: %d: %s\n", dev_seq(dev), + plat->label); return 0; } - dev = hextoul(argv[1], &ep); - if (*ep) { - printf("** Bad device specification %s **\n", argv[2]); - return CMD_RET_USAGE; - } - - ret = host_get_dev_err(dev, &blk_dev); - if (ret) { - if (ret == -ENOENT) - puts("Not bound to a backing file\n"); - else if (ret == -ENODEV) - puts("Invalid host device number\n"); + label = argv[1]; + dev = parse_host_label(argv[1]); + if (!dev) + return CMD_RET_FAILURE; - return 1; - } + host_set_cur_dev(dev); - host_curr_device = dev; return 0; } @@ -161,6 +222,7 @@ static struct cmd_tbl cmd_host_sub[] = { U_BOOT_CMD_MKENT(save, 6, 0, do_host_save, "", ""), U_BOOT_CMD_MKENT(size, 3, 0, do_host_size, "", ""), U_BOOT_CMD_MKENT(bind, 4, 0, do_host_bind, "", ""), + U_BOOT_CMD_MKENT(unbind, 4, 0, do_host_unbind, "", ""), U_BOOT_CMD_MKENT(info, 3, 0, do_host_info, "", ""), U_BOOT_CMD_MKENT(dev, 0, 1, do_host_dev, "", ""), }; @@ -174,8 +236,7 @@ static int do_host(struct cmd_tbl *cmdtp, int flag, int argc, argc--; argv++; - c = find_cmd_tbl(argv[0], cmd_host_sub, - ARRAY_SIZE(cmd_host_sub)); + c = find_cmd_tbl(argv[0], cmd_host_sub, ARRAY_SIZE(cmd_host_sub)); if (c) return c->cmd(cmdtp, flag, argc, argv); @@ -192,10 +253,11 @@ U_BOOT_CMD( "host save hostfs - [] - " "save a file to host\n" "host size hostfs - - determine size of file on host\n" - "host bind [-r] [] - bind \"host\" device to file\n" + "host bind [-r]