From patchwork Fri Jul 14 05:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702717 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906594wrj; Thu, 13 Jul 2023 22:47:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlEdehH8qpxgfCZtwQyHsAJw9eI+Fekk0XGQwOUFDwQZ+yTVQvrWZG0LrSVyM1jxOJzwb7xG X-Received: by 2002:a17:907:8f17:b0:98d:d26c:e142 with SMTP id wg23-20020a1709078f1700b0098dd26ce142mr3103808ejc.46.1689313665313; Thu, 13 Jul 2023 22:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313665; cv=none; d=google.com; s=arc-20160816; b=c/QBLnDEO9VP3YTLTUw2hADPFERjJLB+Ex+77c1OvKzhqqRaN4ukUTMtHRkYmTJkZD m8fbD4P64bw1rFrq+jute3L8fD3y7hba+2Lfbv2mibqDHvxPFN+7sRiwn4DLSPl1hZIq h52A+mFIq+zxLhKrAC1PMNiWCoOfpzuoLEkPyU28VJ9WirGcQz4OyPtBLc4bwhSvPVlb 9Ns7Y+O7f8z6UI7vEU5R6AMWQWTVTQM9GxVjvfrC1fz86xP58QuGZ43QRr3xyjQx+4/G yQHjS/0zx+ccXtiEd4Em4PByriMEoVOtVwpvlcjY+Wt0hm70P7dAhJ+TH3o/sVXleTrL zY/Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aLYToA/kZ0sQwIIJzTmfa8ikJi13yU4NIih1cYHz/go=; fh=jRN2B8z80fClEYkayl7MjwCY1OA6DAaCfFIm+/EH5dc=; b=ABWDPhbreioWiSJkMIuqJi1TTsIHtIblGvLwI7XS93+Nac/EhGh6CZAiAlIgQxUjJB Mw9t0YvqkHf+Y2/5HKZNYR65mH2bvIM/01P0pbOxZhUDEWigpPHvwqq/VI99bKCJZOAo HLhkZo3PhhpdPE6p82k7ngGKcww+4ZZHbJ4u4odVMZ0KHzUYUfl2Nc75hUPkrk18S7Be hikqsJieS2C0UAaZcVSOnd+5gu5+JPtpHm0lZfz8cTfLW7axkVJEGdZg2YsF6jhTwdsx OLg5NQpoWy9IRCZiAly796v5tRb7MjLm1/T7e1U5Zlx0qu5NuC5qZFgn6rtUBye16e1B aCAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zb4WUsMR; 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 pv7-20020a170907208700b00992bf74c314si8125500ejb.983.2023.07.13.22.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:45 -0700 (PDT) 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=zb4WUsMR; 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 6680186D25; Fri, 14 Jul 2023 07:47:29 +0200 (CEST) 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="zb4WUsMR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1AE1486D13; Fri, 14 Jul 2023 07:47:28 +0200 (CEST) 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=unavailable autolearn_force=no version=3.4.2 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) (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 C0C1F86D2A for ; Fri, 14 Jul 2023 07:47:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-565a8d9d832so1058270eaf.1 for ; Thu, 13 Jul 2023 22:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313644; x=1691905644; 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=aLYToA/kZ0sQwIIJzTmfa8ikJi13yU4NIih1cYHz/go=; b=zb4WUsMR12ongGK03jLSu7y0msjblUItT2p2DCM1u8YN/PfmnLzIKpeD5fduDVQdFD w3B5FVmu6NtS0ZLhlaZ7cAId8787zifxyPBBJdn27lra6l2cqkvMklwquaCk2jA2lB8C JICk946CZRakiDPLmKNWEAVPy2yNmBCDno80dYta47ndLz29YhMWBDKAceaLEsOmcRN5 f5cKPUrYVYa6q4csyMHn6GccGmQplkwGar+SLgf09DyVEDuZJ0pwoTx5h2Q0vj/om7TJ SkQlgZIaDfZeRxOsjA5quKfVJMlwDHmtW0Pl0ruR0JpoD4CC/EiGp15/Mps3Pl4gggzE GRvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313644; x=1691905644; 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=aLYToA/kZ0sQwIIJzTmfa8ikJi13yU4NIih1cYHz/go=; b=MVqEw+JHHSMLA+TVjSBAyb29HJ/5dXCwFDifVordLsnGRBYcZE7Ey0yoSI+jsW1foo VifEQlfXv2DVT9vOs+LAa3+lqIWH0RLNfcYH+Mz7nN6aRf6WX2QS8xu1i3X4rIqP5Wvs BdTGafDnFNvfhar6A2DuxJOKipCzyDWH0fS6sNPllu/kfxntFpsUlsr88A5Fr8D/Oo5M x8/ridQPQ6Z772N/K/T6KAQMjlB1oSg9OZEiE8S7MJhJ62HR9KCI2P3m/vGkvB+ANuTD /6VT6DUX6MXRb9VoTHwMwFYvRd52LhgXHRY6H1zho4AL/dnyxE+rc6H7kv/Y8Ng6CSjn Fb9Q== X-Gm-Message-State: ABy/qLZewZCsGfE+rXBTS1sM687TY4H1wYmDtNGmexzEaxR612T0LWiL RFQ9Neeb8GKeAo55tBlrgr2STSIccYOrUwI+SSw= X-Received: by 2002:a05:6358:9188:b0:134:5667:a16c with SMTP id j8-20020a056358918800b001345667a16cmr4049380rwa.32.1689313644160; Thu, 13 Jul 2023 22:47:24 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id c19-20020aa78e13000000b00682b2fbd20fsm6370579pfr.31.2023.07.13.22.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:23 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Ramon Fried , Sean Edmond , Tobias Waldekranz , Stefan Roese , John Keeping , Neil Armstrong , Roger Knecht , Alexey Romanov , Dzmitry Sankouski Subject: [PATCH v2 3/6] cmd: ramdisk: add ramdisk control command Date: Fri, 14 Jul 2023 14:44:03 +0900 Message-Id: <20230714054406.761508-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230714054406.761508-1-masahisa.kojima@linaro.org> References: <20230714054406.761508-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 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 This introcudes the ramdisk command, to control the ramdisk devices. Signed-off-by: Masahisa Kojima --- Newly introcuded in v2 cmd/Kconfig | 7 ++++ cmd/Makefile | 1 + cmd/ramdisk.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 cmd/ramdisk.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 365371fb51..5f3022b0c9 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1592,6 +1592,13 @@ config CMD_AXI Interface) busses, a on-chip interconnect specification for managing functional blocks in SoC designs, which is also often used in designs involving FPGAs (e.g. communication with IP cores in Xilinx FPGAs). + +config CMD_RAM_DISK + bool "ramdisk" + depends on RAM_DISK + help + This provides commands to control the ramdisk devices. + endmenu diff --git a/cmd/Makefile b/cmd/Makefile index 6c37521b4e..eb7d86a3c6 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -142,6 +142,7 @@ obj-$(CONFIG_CMD_PWM) += pwm.o obj-$(CONFIG_CMD_PXE) += pxe.o obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_CMD_QFW) += qfw.o +obj-$(CONFIG_CMD_RAM_DISK) += ramdisk.o obj-$(CONFIG_CMD_READ) += read.o obj-$(CONFIG_CMD_WRITE) += read.o obj-$(CONFIG_CMD_REGINFO) += reginfo.o diff --git a/cmd/ramdisk.c b/cmd/ramdisk.c new file mode 100644 index 0000000000..8df29729aa --- /dev/null +++ b/cmd/ramdisk.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * ramdisk command + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include +#include + +static int ramdisk_curr_dev; /* current device */ + +static int get_desc(enum uclass_id uclass_id, int devnum, struct blk_desc **descp) +{ + struct udevice *dev; + struct uclass *uc; + int ret; + + *descp = NULL; + ret = uclass_get(UCLASS_BLK, &uc); + if (ret) + return ret; + + uclass_foreach_dev(dev, uc) { + struct blk_desc *desc = dev_get_uclass_plat(dev); + + if (desc->uclass_id == uclass_id) { + if (desc->devnum == devnum) { + *descp = desc; + return 0; + } + } + } + + return -1; +} + +static int do_ramdisk(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int ret; + u64 addr, size; + struct udevice *dev; + + if (strncmp(argv[1], "mount", 5) == 0) { + if (argc != 4) + return CMD_RET_USAGE; + + addr = hextoul(argv[2], NULL); + size = hextoul(argv[3], NULL); + dev = ramdisk_mount(addr, size, NULL); + if (!dev) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; + } + + if (strncmp(argv[1], "umount", 6) == 0) { + struct blk_desc *desc; + + ret = get_desc(UCLASS_RAM_DISK, ramdisk_curr_dev, &desc); + if (ret) { + printf("ramdisk device not found(dev %d)\n", ramdisk_curr_dev); + return CMD_RET_FAILURE; + } + + ret = ramdisk_unmount(desc->bdev); + if (ret) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; + } + + return blk_common_cmd(argc, argv, UCLASS_RAM_DISK, &ramdisk_curr_dev); +} + +U_BOOT_CMD( + ramdisk, 5, 1, do_ramdisk, + "ramdisk sub-system", + "ramdisk info - show available ramdisk devices\n" + "ramdisk mount
- mount ramdisk\n" + "ramdisk umount - unmount ramdisk\n" + "ramdisk device [dev] - show or set current device\n" + "ramdisk part [dev] - print partition table of one or all ramdisk devices\n" + "ramdisk read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" + " to memory address `addr'\n" + "ramdisk write addr blk# cnt - write `cnt' blocks starting at block\n" + " `blk#' from memory address `addr'" +);