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 5BC20C433F5 for ; Mon, 23 May 2022 13:21:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1169E83F63; Mon, 23 May 2022 15:21:30 +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="TtF6jZEB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BC12583E69; Sun, 22 May 2022 10:37:29 +0200 (CEST) Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) (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 C216D83E75 for ; Sun, 22 May 2022 10:37:26 +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: Sun, 22 May 2022 08:37:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1653208642; x=1653467842; bh=RS0pd/LlJoRxPNe+GMX9YdHG6vts75JAH4oo+45eu8A=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:Feedback-ID:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID; b=TtF6jZEBlkyjU/fkSyM+M8yqUkCUACrNjD2llBv7mCe9gmeElvZaSQ7BxT9KFcPIY WnO3Od2hSe6AianbQLvKNuDMHzMfBY5HV+oTLMQ3m4TZqp++rINuTgOo36Ff3hfaiO ycmIw2nowlaB5Oi7y2ZilQIYdYc84KHpNc/Iftggmtuw1Lg8aohPUumhZS2x7co7rf kCFtuYx3U8BWrQu8Ttoc+YxCFK9EN6L16av+9kM/DQE45hl10BVU9Uj6ZNRY20jZZQ 9WgNLIOV7m6fXd2CtZTOxLgdwN4AcrAp3slslqlk6VyulKayeDvqK5QvCV81jygvHi DIVv/dfEqINlw== To: u-boot@lists.denx.de From: Roger Knecht Cc: rknecht@pm.me Subject: [PATCH] cmd: cat: add new command Message-ID: <20220522083711.14528-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-Mailman-Approved-At: Mon, 23 May 2022 15:21:28 +0200 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 --- cmd/Kconfig | 6 ++++++ cmd/Makefile | 1 + cmd/cat.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 cmd/cat.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 69c1814d24..2cb719795c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -385,6 +385,12 @@ config CMD_ABOOTIMG =09 See doc/android/boot-image.rst for details. +config CMD_CAT +=09bool "cat" +=09default y +=09help +=09 print file to standard output + config CMD_ELF =09bool "bootelf, bootvx" =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..4ba3b611aa --- /dev/null +++ b/cmd/cat.c @@ -0,0 +1,54 @@ +// 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 *data; +=09loff_t index; +=09loff_t 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; + +=09ret =3D fs_size(argv[3], &size); +=09if (ret) +=09=09return ret; + +=09data =3D malloc(size); +=09if (!data) +=09=09return -ENOMEM; + +=09ret =3D fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY); +=09if (ret) +=09=09return ret; + +=09ret =3D fs_read(argv[3], (ulong)data, 0, 0, &size); +=09if (ret) +=09=09return ret; + +=09for (index =3D 0; index < size; index++) +=09=09putc(data[index]); + +=09free(data); + +=09return 0; +} + +U_BOOT_CMD(cat, 4, 1, do_cat, +=09 "print file to standard output", +=09 " file\n" +=09 "=09- print file from 'dev' on 'interface' to standard output"); -- 2.17.1