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 5601BC43334 for ; Sat, 4 Jun 2022 11:19:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 82877811A6; Sat, 4 Jun 2022 13:19:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=pm.me 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; secure) header.d=pm.me header.i=@pm.me header.b="htQXS+MF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B824820B7; Sat, 4 Jun 2022 13:19:20 +0200 (CEST) Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C27DE80378 for ; Sat, 4 Jun 2022 13:19:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rknecht@pm.me Date: Sat, 04 Jun 2022 11:19:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1654341557; x=1654600757; bh=h5Bwp0ID32pL3aVvOio+HITd53eU3xqCrv9M0NCj+c8=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:Feedback-ID:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID; b=htQXS+MF46OGGNzv0KS8XsrjyVnX9e+O72noxGZw1AlhvUnfIciYbWHeZ5Vku0cQB QduBARfpIQoovH2PjfKyqGyDFnq5Gi8Z+OZ7dbcpSWOjCsb8ok1S5A+GgH8fmdlsCJ 0mqo9/NX6crZohFuiHYcVNqDaVXwzQkJmtdmN5H6YghcjC6X9phwAVAH++mPf11zID knUFuf20aKqqcmyiTrLIrZlMfHS/C8RuSns81HisD9o0Zuy9BCOCl98QURnQ7EWYEf ig4Thdv01lGMslALcH2vAoUpq7Ys2db5/CkVjUzNEEFa9VQ3AeRrHLD2UQL1dzis8g +oC7r6jb441Xg== To: u-boot@lists.denx.de From: Roger Knecht Cc: Tom Rini , Roger Knecht Subject: [PATCH v2] cmd: cat: add new command Message-ID: <20220604111851.14038-1-rknecht@pm.me> Feedback-ID: 8957232:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: , Reply-To: Roger Knecht Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Add cat command to print file content to standard out Signed-off-by: Roger Knecht --- v2: - Moved cat from boot to shell commands - Added MAINTAINERS entry - Added comments - Improved variable naming MAINTAINERS | 5 +++++ cmd/Kconfig | 6 ++++++ cmd/Makefile | 1 + cmd/cat.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 cmd/cat.c diff --git a/MAINTAINERS b/MAINTAINERS index 56be0bfad0..7c5cd178d9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -729,6 +729,11 @@ M:=09Simon Glass S:=09Maintained F:=09tools/buildman/ +CAT +M:=09Roger Knecht +S:=09Maintained +F:=09cmd/cat.c + CFI FLASH M:=09Stefan Roese S:=09Maintained diff --git a/cmd/Kconfig b/cmd/Kconfig index 69c1814d24..8b531c7ebe 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1492,6 +1492,12 @@ endmenu menu "Shell scripting commands" +config CMD_CAT +=09bool "cat" +=09default y +=09help +=09 Print file to standard output + config CMD_ECHO =09bool "echo" =09default y diff --git a/cmd/Makefile b/cmd/Makefile index 5e43a1e022..589b9680ba 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_CMD_BOOTZ) +=3D bootz.o obj-$(CONFIG_CMD_BOOTI) +=3D booti.o obj-$(CONFIG_CMD_BTRFS) +=3D btrfs.o obj-$(CONFIG_CMD_BUTTON) +=3D button.o +obj-$(CONFIG_CMD_CAT) +=3D cat.o obj-$(CONFIG_CMD_CACHE) +=3D cache.o obj-$(CONFIG_CMD_CBFS) +=3D cbfs.o obj-$(CONFIG_CMD_CLK) +=3D clk.o diff --git a/cmd/cat.c b/cmd/cat.c new file mode 100644 index 0000000000..a027d842ef --- /dev/null +++ b/cmd/cat.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2022 + * Roger Knecht + */ + +#include +#include +#include +#include + +static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc, +=09=09 char *const argv[]) +{ +=09char *file_data; +=09loff_t file_index; +=09loff_t file_size; +=09int ret; + +=09if (argc < 4) +=09=09return CMD_RET_USAGE; + +=09ret =3D fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY); +=09if (ret) +=09=09return ret; + +=09// get file size +=09ret =3D fs_size(argv[3], &file_size); +=09if (ret) +=09=09return ret; + +=09// allocate memory for file content +=09file_data =3D malloc(file_size); +=09if (!file_data) +=09=09return -ENOMEM; + +=09ret =3D fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY); +=09if (ret) +=09=09return ret; + +=09// read file to memory +=09ret =3D fs_read(argv[3], (ulong)file_data, 0, 0, &file_size); +=09if (ret) +=09=09return ret; + +=09// print file content +=09for (file_index =3D 0; file_index < file_size; file_index++) +=09=09putc(file_data[file_index]); + +=09free(file_data); + +=09return 0; +} + +U_BOOT_CMD(cat, 4, 1, do_cat, +=09 "print file to standard output", +=09 " \n" +=09 "=09- Print file from 'dev' on 'interface' to standard output"); -- 2.17.1