From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C260AC433F5 for ; Sat, 13 Nov 2021 11:47:27 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 009CB60F42 for ; Sat, 13 Nov 2021 11:47:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 009CB60F42 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 35A0583104; Sat, 13 Nov 2021 12:47:25 +0100 (CET) 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="ib2/YsF/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4F024830BF; Sat, 13 Nov 2021 12:47:24 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (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 3D9CD83110 for ; Sat, 13 Nov 2021 12:47:06 +0100 (CET) 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=1636804025; bh=wZgBQU8TazzoKa5iwdMEm1hJVsDzwrBJlFi8xNuqzDw=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=ib2/YsF/i2gIwphADUIAEVxDECYLeoVF92wS5IB7obYaIclTor+ntiF2ZPXo/r3l6 zOFMA9kNsnZv1RzrfHYM+8nWg7W+xKenxJ2D54+PHVSuZoHHbQUiJ+CZZ71fSYt4mO 2HrsUvdTONfnYmGvpcMnZ/q65cpNv427PdaC7rCA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.35] ([88.152.144.157]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MSKyI-1nA6TI3Z84-00SbcV; Sat, 13 Nov 2021 12:47:04 +0100 Message-ID: <35de6992-6b1d-6fb0-9c22-346c0a393941@gmx.de> Date: Sat, 13 Nov 2021 12:47:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH v4 5/5] sf: Provide a command to access memory-mapped SPI Content-Language: en-US To: Simon Glass Cc: Jagan Teki , Mike Frysinger , U-Boot Mailing List References: <20210919214937.3829422-1-sjg@chromium.org> <20210919214937.3829422-6-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20210919214937.3829422-6-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:cBK0MwzF4OffbrzaA8j6JTJRoHXIcGb0zGuP2eCd+NIHcWoLqJJ 8JQBFOetjP1zknDOsVkeIvkHEXkI8WuVy4w8qB2/3c8ZJCCPKfXmRbz8E28uzT+nyF/kQZm 07Sp/2JolbtmNfhkDDfTX4JD0oQvKC4ap78FIAkXBEoxzQwbai7kTU/3glR0liY0ohzZXLy C0Ojm0rt0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1EC6SfyruOA5MEnCVOFARXmE 8HmTcJbEIJMfkhR22c1tHaIRYz5mpXK3VDdDFQjPoTsTzHAZhP9pRZCEcKZjLFtfJ5OEZCMDq U0LJWpZPNNdHMQ= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.35 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.2 at phobos.denx.de X-Virus-Status: Clean On 9/19/21 23:49, Simon Glass wrote: > Add a new 'sf mmap' function to show the address of a SPI offset, if the I would expect a 'spi info' command to provide this information. Best regards Heinrich > hardware supports it. This is useful on x86 systems. > > Signed-off-by: Simon Glass > --- > > (no changes since v3) > > Changes in v3: > - Add configuration and return value also > > arch/Kconfig | 2 ++ > cmd/Kconfig | 8 ++++++ > cmd/sf.c | 35 +++++++++++++++++++++++++++ > doc/usage/sf.rst | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 108 insertions(+) > > diff --git a/arch/Kconfig b/arch/Kconfig > index 8f8daadcf92..406e5a6c627 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -136,6 +136,7 @@ config SANDBOX > imply CMD_LZMADEC > imply CMD_SATA > imply CMD_SF > + imply CMD_SF_MMAP > imply CMD_SF_TEST > imply CRC32_VERIFY > imply FAT_WRITE > @@ -200,6 +201,7 @@ config X86 > imply CMD_IRQ > imply CMD_PCI > imply CMD_SF > + imply CMD_SF_MMAP > imply CMD_SF_TEST > imply CMD_ZBOOT > imply DM_ETH > diff --git a/cmd/Kconfig b/cmd/Kconfig > index 3a857b3f6e2..44485f1588c 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -1273,6 +1273,14 @@ config CMD_SF > help > SPI Flash support > > +config CMD_SF_MMAP > + bool "sf mmap - Access memory-mapped SPI flash" > + depends on CMD_SF > + help > + On some systems part of the SPI flash is mapped into mmemory. This > + command provides a way to map a SPI-flash offset to a memory address= , > + so that the contents can be browsed using 'md', for example. > + > config CMD_SF_TEST > bool "sf test - Allow testing of SPI flash" > depends on CMD_SF > diff --git a/cmd/sf.c b/cmd/sf.c > index 72246d912fe..c78cd7e6342 100644 > --- a/cmd/sf.c > +++ b/cmd/sf.c > @@ -384,6 +384,36 @@ static int do_spi_protect(int argc, char *const arg= v[]) > return ret =3D=3D 0 ? 0 : 1; > } > > +static int do_spi_flash_mmap(int argc, char *const argv[]) > +{ > + loff_t offset, len, maxsize; > + uint map_offset, map_size; > + ulong map_base; > + int dev =3D 0; > + int ret; > + > + if (argc < 2) > + return CMD_RET_USAGE; > + > + ret =3D mtd_arg_off_size(argc - 1, &argv[1], &dev, &offset, &len, > + &maxsize, MTD_DEV_TYPE_NOR, flash->size); > + if (ret) > + return ret; > + > + ret =3D dm_spi_get_mmap(flash->dev, &map_base, &map_size, &map_offset)= ; > + if (ret) { > + printf("Mapping not available (err=3D%d)\n", ret); > + return CMD_RET_FAILURE; > + } > + if (offset < 0 || offset + len > map_size) { > + printf("Offset out of range (map size %x)\n", map_size); > + return CMD_RET_FAILURE; > + } > + printf("%lx\n", map_base + (ulong)offset); > + > + return 0; > +} > + > enum { > STAGE_ERASE, > STAGE_CHECK, > @@ -580,6 +610,8 @@ static int do_spi_flash(struct cmd_tbl *cmdtp, int f= lag, int argc, > ret =3D do_spi_flash_erase(argc, argv); > else if (strcmp(cmd, "protect") =3D=3D 0) > ret =3D do_spi_protect(argc, argv); > + else if (IS_ENABLED(CONFIG_CMD_SF_MMAP) && !strcmp(cmd, "mmap")) > + ret =3D do_spi_flash_mmap(argc, argv); > else if (IS_ENABLED(CONFIG_CMD_SF_TEST) && !strcmp(cmd, "test")) > ret =3D do_spi_flash_test(argc, argv); > else > @@ -611,6 +643,9 @@ static const char long_help[] =3D > " or to start of mtd `partition'\n" > "sf protect lock/unlock sector len - protect/unprotect 'len' bytes st= arting\n" > " at address 'sector'" > +#ifdef CONFIG_CMD_SF_MMAP > + "\nsf mmap offset len - get memory address of SPI-flash offset\n" > +#endif > #ifdef CONFIG_CMD_SF_TEST > "\nsf test offset len - run a very basic destructive test" > #endif > diff --git a/doc/usage/sf.rst b/doc/usage/sf.rst > index 71bd1be5175..93fb8409370 100644 > --- a/doc/usage/sf.rst > +++ b/doc/usage/sf.rst > @@ -14,6 +14,7 @@ Synopis > sf erase | > sf update | > sf protect lock|unlock > + sf mmap | > sf test | > > Description > @@ -143,6 +144,16 @@ lock|unlock > Number of bytes to lock/unlock > > > +Memory-mapped flash > +------------------- > + > +On some systems part of the SPI flash is mapped into mmemory. With *sf = mmap* > +you can map a SPI-flash offset to a memory address, so that the content= s can be > +browsed using 'md', for example. > + > +The command will fail if this is not supported by the hardware or drive= r. > + > + > Test > ~~~~ > > @@ -240,6 +251,58 @@ This second example is running on coral, an x86 Chr= omebook:: > 2 write: 227 ticks, 2255 KiB/s 18.040 Mbps > 3 read: 189 ticks, 2708 KiB/s 21.664 Mbps > > + # On coral, SPI flash offset 0 corresponds to address ff081000 in me= mory > + =3D> sf mmap 0 1000 > + device 0 offset 0x0, size 0x1000 > + ff081000 > + > + # See below for how this address was obtained > + =3D> sf mmap e80000 11e18 > + device 0 offset 0xe80000, size 0x11e18 > + fff01000 > + =3D> md fff01000 > + fff01000: b2e8e089 89000030 30b4e8c4 c0310000 ....0......0..1. > + fff01010: 002c95e8 2ce8e800 feeb0000 dfe8c489 ..,....,........ > + fff01020: f400002c 83f4fdeb d4e80cec 3100001e ,..............1 > + fff01030: 0cc483c0 f883c3c3 8b0b770a df408504 .........w....@. > + fff01040: c085fef1 c8b80575 c3fef1e5 53565755 ....u.......UWVS > + fff01050: 89c38951 2404c7c5 80000002 8924048b Q......$......$. > + fff01060: 89a20fdf 89fb89de 75890045 084d8904 ........E..u..M. > + fff01070: ff0c5589 c5832404 243c8110 80000005 .U...$....<$.... > + fff01080: 43c6da75 3b800030 43037520 d889f8eb u..C0..; u.C.... > + fff01090: 5f5e5b5a 80e6c35d 535657c3 e7e8c689 Z[^_]....WVS.... > + fff010a0: 89000069 00a164c3 8b000000 408b4c56 i....d......VL.@ > + fff010b0: 0cec837c ddb9ff6a e8fef1e5 00004e01 |...j........N.. > + fff010c0: a1640389 00000000 1c80b60f 66000001 ..d............f > + fff010d0: b80c4389 00000001 a20fdf89 fb89de89 .C.............. > + fff010e0: 89104389 c4831453 5bc03110 56c35f5e .C..S....1.[^_.V > + fff010f0: 14ec8353 ce89d389 0000a164 b60f0000 S.......d....... > + > + > +The offset e80000 was obtained using the following binman command, to f= ind the > +location of U-Boot SPL:: > + > + $ binman ls -i /tmp/b/chromebook_coral/u-boot.rom > + Name Image-pos Size Entry-ty= pe Offset Uncomp-size > + --------------------------------------------------------------------= ---------------------------------- > + main-section 0 1000000 section = 0 > + spl e80000 11e18 u-boot-s= pl ffe80000 > + u-boot d00000 9106e u-boot = ffd00000 > + ... > + > > .. _SPI documentation: > https://en.wikipedia.org/wiki/Serial_Peripheral_Interface > + > + > +Configuration > +------------- > + > +The *sf* command is only available if `CONFIG_CMD_SF=3Dy`. Note that it= depends on > +`CONFIG_DM_SPI_FLASH`. > + > +Return value > +------------ > + > +The return value $? is set to 0 (true) if the command succeded and to 1= (false) > +otherwise. >