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 60588C433EF for ; Sun, 19 Jun 2022 15:08:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AAD6E84239; Sun, 19 Jun 2022 17:08:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.net header.i=@gmx.net header.b="FS52d4QD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 54273842FA; Sun, 19 Jun 2022 17:08:47 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (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 6FEB883F6B for ; Sun, 19 Jun 2022 17:08:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655651321; bh=7jdk+gaHt3Hf3kvdOk/oFSfteT3s/q1O0u0v9sh9J9Y=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=FS52d4QDQv9dxHEqquxzcI4+zOnEaF49W2eLhDZpaTLysh+rPskfLEHVvbySP+8kE Ck8bdE/R33rZdkarGENCnrfC4mRgZw2FTZVsmQnx86zfsgyX+nbVPWr87Qk9kv0rn0 YBfvDpx0fgUNhhGuxTpK6yozApsXgQQi/83wGrmw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([62.143.94.109]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MaJ3t-1oEmse2JHR-00WGir; Sun, 19 Jun 2022 17:08:41 +0200 Message-ID: <413b83ea-de6d-261c-c6c2-6e595295b72f@gmx.de> Date: Sun, 19 Jun 2022 17:08:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2] cmd: cat: add new command Content-Language: en-US To: Roger Knecht Cc: u-boot@lists.denx.de, Tom Rini References: <20220604111851.14038-1-rknecht@pm.me> <20220608135912.GD2484912@bill-the-cat> <0Kel7CIIUOspULuCWqCpxGMNRBiPE78WSKr1LYdkkyiCSeZNlS1nY9CS8kznPuyRoEZwAxdKSY-V2LBParCMywJFGS1qUWtF57e9YHicgGA=@pm.me> From: Heinrich Schuchardt In-Reply-To: <0Kel7CIIUOspULuCWqCpxGMNRBiPE78WSKr1LYdkkyiCSeZNlS1nY9CS8kznPuyRoEZwAxdKSY-V2LBParCMywJFGS1qUWtF57e9YHicgGA=@pm.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:OSWTvWwNaWbVkTOGj5Om1xDSAEfWWHdqgaJjXiBaq8FpO4Zqc+L jdra1jFhhOs9L+AdyOi8dTlWaDD+NYWUZnzRtte3VOzdlAKeJaLoQBKxhDcUMRof2utPfqJ nq7C6RPHvz9kL0l/F09TuxPFCwYYH1EjQ91DWQGZHMC0F7mGM1/4d+Zb2MtC1/eakZzmN49 xiqev9YirzYLsPWvp/cvw== X-UI-Out-Filterresults: notjunk:1;V03:K0:IlZqAtIG/E8=:IAI7fHZ+xNqXv194X1pvl6 7ydE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2Zfk aH0IMQyF162dpfMmSAeDUq5+a8/JGrZEHwgfPJ/kFO9b+plsFRzCdROcSuXdQJurha5gJA0aE LQ1yHoAWoUBipUadh+SoyKDfGD 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.5 at phobos.denx.de X-Virus-Status: Clean On 6/19/22 16:23, Roger Knecht wrote: > On Thursday, June 9th, 2022 at 22:27, Roger Knecht wrote= : >> On Wednesday, June 8th, 2022 at 15:59, Tom Rini trini@konsulko.com wrot= e: >> >>> On Sat, Jun 04, 2022 at 11:19:15AM +0000, Roger Knecht wrote: >>> >>>> Add cat command to print file content to standard out >>>> >>>> Signed-off-by: Roger Knecht rknecht@pm.me >>>> --- >>>> 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: Simon Glass sjg@chromium.org >>>> S: Maintained >>>> F: tools/buildman/ >>>> >>>> +CAT >>>> +M: Roger Knecht rknecht@pm.me >>>> +S: Maintained >>>> +F: cmd/cat.c >>>> + >>>> CFI FLASH >>>> M: Stefan Roese sr@denx.de >>>> S: Maintained >>>> 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 >>>> + bool "cat" >>>> + default y >>> >>> New commands shouldn't be default enabled. I also don't see a test. >>> Please add a test, and enable the command in sandbox so the test is ru= n. >>> Thanks! >> >> >> Thanks for the review. Will be fixed in the next version. > > Hi Tom, > > I'm running into issues when writing a test for cat: Dear Roger, tests for console commands should be written in Python, see https://u-boot.readthedocs.io/en/latest/develop/py_testing.html. You will need a test fixture that generates the disk image with the file that you want to load and display in the test function. Have a look at test/py/tests/test_efi_bootmgr/ as an example. We have different files that may be worth printing with 'cat': * UTF-8 text files like uEnv.txt * script files like boot.scr that can be executed with the 'source' comman= d * binary files I suggest that the 'cat' command should support all of these. For binary files you can use the print_hex_dump() function for console output. Please, provide a man-page for the 'cat' command in doc/usage/cmd/. You can use doc/usage/cmd/fatinfo.rst as a template. Best regards Heinrich > > 1. malloc() allocates memory outside the sandbox emulated DRAM which cau= ses fs_read() to fail: > > relevant code: (paddr - allocated by malloc() - is not within the gd->ra= m_size) > ``` > void *phys_to_virt(phys_addr_t paddr) > { > [...] > > /* If the address is within emulated DRAM, calculate the value */ > if (paddr < gd->ram_size) > return (void *)(gd->arch.ram_buf + paddr); > > [...] > > printf("%s: Cannot map sandbox address %lx (SDRAM from 0 to %lx)\n"= , > __func__, (ulong)paddr, (ulong)gd->ram_size); > os_abort(); > > [...] > > ``` > output: > phys_to_virt: Cannot map sandbox address 140093b0 (SDRAM from 0 to 80000= 00) > > trace: > #0 __GI_raise (sig=3Dsig@entry=3D6) at ../sysdeps/unix/sysv/linux/raise= .c:51 > #1 0x00007ffff74e87f1 in __GI_abort () at abort.c:79 > #2 0x000055555558b352 in os_abort () at arch/sandbox/cpu/os.c:948 > #3 0x000055555558c093 in phys_to_virt (paddr=3Dpaddr@entry=3D335582128)= at arch/sandbox/cpu/cpu.c:118 > #4 0x000055555558c1c2 in map_physmem (paddr=3Dpaddr@entry=3D335582128, = len=3D, len@entry=3D0, flags=3Dflags@entry=3D0) at arch/san= dbox/cpu/cpu.c:179 > #5 0x000055555564a5b6 in map_sysmem (len=3D0, paddr=3D335582128) at ./a= rch/sandbox/include/asm/io.h:36 > #6 _fs_read (filename=3D0x1400c5d0 "file", addr=3Daddr@entry=3D33558212= 8, offset=3Doffset@entry=3D0, len=3Dlen@entry=3D0, do_lmb_check=3Ddo_lmb_c= heck@entry=3D0, actread=3Dactread@entry=3D0x7fffffffe740) at fs/fs.c:596 > #7 0x000055555564a68c in fs_read (filename=3D, addr=3Dad= dr@entry=3D335582128, offset=3Doffset@entry=3D0, len=3Dlen@entry=3D0, actr= ead=3Dactread@entry=3D0x7fffffffe740) at fs/fs.c:611 > #8 0x00005555555a2a77 in do_cat (cmdtp=3D, flag=3D, argc=3D, argv=3D0x1400c650) at cmd/cat.c:42 > #9 0x00005555555de75e in cmd_always_repeatable (cmdtp=3D= , flag=3D, argc=3D, argv=3D, = repeatable=3D) at common/command.c:544 > #10 0x00005555555ddb56 in cmd_call (cmdtp=3Dcmdtp@entry=3D0x555555accbe8= <_u_boot_list_2_cmd_2_cat>, flag=3Dflag@entry=3D0, argc=3Dargc@entry=3D4,= argv=3Dargv@entry=3D0x1400c650, repeatable=3Drepeatable@entry=3D0x7ffffff= fe794) at common/command.c:580 > #11 0x00005555555de87c in cmd_process (flag=3D, flag@entr= y=3D0, argc=3D4, argv=3D0x1400c650, repeatable=3Drepeatable@entry=3D0x5555= 55af64d4 , ticks=3Dticks@entry=3D0x0) at common/command.c:635 > #12 0x00005555555cb9fd in run_pipe_real (pi=3Dpi@entry=3D0x1400c500) at = common/cli_hush.c:1676 > #13 0x00005555555cbdc5 in run_list_real (pi=3Dpi@entry=3D0x1400c500) at = common/cli_hush.c:1873 > #14 0x00005555555cbedc in run_list (pi=3D0x1400c500) at common/cli_hush.= c:2022 > #15 0x00005555555cc100 in parse_stream_outer (inp=3Dinp@entry=3D0x7fffff= ffe950, flag=3Dflag@entry=3D2) at common/cli_hush.c:3206 > #16 0x00005555555cc183 in parse_file_outer () at common/cli_hush.c:3289 > #17 0x00005555555dd90f in cli_loop () at common/cli.c:229 > #18 0x00005555555c9acc in main_loop () at common/main.c:69 > #19 0x00005555555ccfd4 in run_main_loop () at common/board_r.c:590 > #20 0x00005555555cd32d in initcall_run_list (init_sequence=3D0x555555ae9= 220 ) at include/initcall.h:46 > #21 board_init_r (new_gd=3D, dest_addr=3D)= at common/board_r.c:824 > #22 0x0000555555589e34 in main (argc=3D, argv=3D0x7ffffff= fed58) at arch/sandbox/cpu/start.c:529 > > Is this a bug in the malloc implementation or does the fs_read() buffer = require a different allocation? > > > 2. Testing the cat command requires a filesystem. How should the filesys= tem be provided for tests? > > Currently I test the command in the sandbox by: > $ ./u-boot > =3D> host bind 0 disk.ext2 > =3D> cat host 0 file > > Shipping a binary filesystem in the patch is not a great idea. > Alternatively the filesystem could be created as part of the test. > What is your recommendation? > > Thanks, > Roger