116 Commits
Author SHA1 Message Date
rich 9b1a67218d Micron CMD56 Additions MicronCMD56 2023-07-31 14:02:02 +00:00
rich e5b504deeb Micron CMD56 Additions 2023-07-31 13:58:50 +00:00
Avri Altman 6d593efc3c mmc-utils: Assert MMC_IOC_MULTI_CMD in compile time
Notify of mult-ioctl violation during preprocessing instead of bailing out
in runtime. This prevents bogus copies of mmc-utils binaries wondering
about out there.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230609083425.765-1-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-06-12 16:10:11 +02:00
Ahmad Fatoum 9582278906 mmc-utils: support overriding CFLAGS without setting -DVERSION
Build tools like OpenEmbedded set the CFLAGS environment variable to be
in line with distro-wide decisions. Updating OpenEmbedded-core to point
at the new mmc-utils breaks, because VERSION would then be undefined.

Instead of having users workaround this by feeding in -DVERSION from
the outside, let's just move it out of environment-overridable CFLAGS
and into AM_CFLAGS instead.

This will inconvenience users that set their own VERSION a bit: The
Makefile sets -Werror and specifying -DVERSION twice will trigger it
because of the duplicate definition. This can be resolved by specifying
-UVERSION first. Given that the VERSION macro has only been there for a
month, this is deemed acceptable.

Fixes: 145c74ab6f ("mmc-utils: Change version string to git hash")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.kernel.org/r/20230526081100.1741293-1-a.fatoum@pengutronix.de
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-05-26 15:05:46 +02:00
Enrico Jorns 8ac394dd9c mmc-utils: do not hide CID manufacturer information
Reading the MID just to convert it to 'Unlisted' is quite unhelpful for
an info command.
Due to the (constantly increasing) amount of valid MIDs it is quite
unlikely to we have it in the database already anyway.

Thus simply always print the manufacturer ID as 0xNN and understand the
manufacturer name as an additional information held in parenthesis.

Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230522214818.2038252-3-ejo@pengutronix.de
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-05-24 14:54:22 +02:00
Enrico Jorns 78af8638c2 mmc-utils: fix printing OID for mmc in non-verbose mode
It is parsed as an integer and printed as a char which does not really
make sense.
E.g. if OID is '0' (which does not seem to be uncommon), then this
prints a '\0' character and makes output nearly unreadable/unparsable.

Also, do not print it like it would be a string, instead use 0x<digit>
format.

Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230522214818.2038252-2-ejo@pengutronix.de
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-05-24 14:54:22 +02:00
Enrico Jorns 36bcb85951 mmc-utils: add SanDisk to manufacturer database
Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Acked-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230522214818.2038252-1-ejo@pengutronix.de
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-05-24 14:54:22 +02:00
Christian Loehle 145c74ab6f mmc-utils: Change version string to git hash
Since mmc-utils versioning has always been 0.1 and changes are not
made frequently and formal releases do not happen, packaged versions
are just pulled from git anyway, using the git hash for version is
probably the best idea for now.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Link: https://lore.kernel.org/r/28623fa7390242e9b003a44016c0235f@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-04-17 10:29:05 +02:00
Christian Löhle d4c2910981 mmc-utils: Add basic erase error check
Check for erase specific R1 errors so e.g. an OOR erase is not
reported as successful when it never executed.

There could be checks for more error bits but R1_ERASE_SEQ_ERROR
on CMD38 should catch all that are reported by hardware anyway.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/c91cdde6288d4db6aad45f5d50d129c8@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-02-09 15:16:51 +01:00
Sean Anderson a08f08ec67 mmc-utils: Add a command to write extcsd registers
There is a command to read the extcsd and some commands to configure
particular features, but no generic write extcsd command. Such a command
may be useful for not-yet-supported features and manufacturer-specific
registers.

Signed-off-by: Philippe Reynes <philippe.reynes@sagemcom.com>
[ rebased onto latest master and updated commit message ]
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Link: https://lore.kernel.org/r/20221216161625.2924013-1-sean.anderson@seco.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-02-09 15:10:21 +01:00
Christian Löhle c62dd8e415 mmc-utils: Implement alternative boot operation
Implements the alternative boot operation for eMMCs.
Note the limitations of the help.

This is mostly useful for testing purposes if you set
up the boot partition configuration correctly.

Usage:
$ sudo dd if=/dev/mmcblk2boot0 of=bootdatammcblk count=2
2+0 records in
2+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.00482308 s, 212 kB/s

$ sudo ./mmc boot_operation bootdata /dev/mmcblk2

$ diff -s bootdata bootdatammcblk
Files bootdata and bootdatammcblk are identical

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/f999a7ed7bb645948ac74d5d5341e913@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-11-09 11:52:52 +01:00
Christian Löhle 4a32d090dc mmc-utils: Add CMD0 softreset and preidle command
CMD0 may be used to see if the hardware can handle a UHS card
that completed the voltage switch. If a UHS card has problems
coming back up after CMD0 your hardware may not support a hard
reset properly.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/0657285aa7c64cbe89f9275fd5598345@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-10-24 19:00:07 +02:00
Christian Löhle 34577b2378 mmc-utils: Allow for custom sanitize timeout
Some cards with certain preconditioning require a higher timeout
when sanitizing. Let the user set the maximum timeout.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/4ddb5a5510d74645b2724d274c96ab02@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-10-24 18:59:46 +02:00
Christian Löhle d939fb5c0f mmc-utils: Refactor switch to allow custom timeout
Certain commands require a longer switch timeout.
Refactor accordingly to allow e.g. for future sanitize change.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/a64ce8be9687452b8da6c9816ca42b5b@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-10-24 18:58:53 +02:00
Avri Altman dfc3b6ecda mmc-utils: Fix a typo for ATP mid
Manufacturer id 0x44 is assign to ATP by 3c-LLC, and not to SanDisk.
mmc-utils inherited this typo when lsmmc got merged into it.

Reported-by: Mark Kanczak <Markk@us.atpinc.com>
Fixes: 4af1749d23 (mmc-utils: Merge the lsmmc tool into mmc-utils)
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220927084317.138-1-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-09-27 14:16:03 +02:00
Bruno Matic 2a934139cf mmc-utils: Fix ffu in case of unsupported MODE_OPERATION_CODES
Move up the return in case MODE_OPERATION_CODES is not supported.
According to the specification when MODE_OPERATION_CODES is not
supported no checks should be done against NUM_OF_FW_SEC_PROG.

Signed-off-by: Bruno Matic <bruno.matic@nokia.com>
Fixes: 89cd01ed86 (mmc_utils: add ffu support)
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220920124749.24073-1-bruno.matic@nokia.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-09-21 14:51:45 +02:00
Giulio Benetti 5086e7c0de mmc-utils: fix warning on uninitialized 'cnt'
When building following warning shows up:
```
In function '__bswap_32',
    inlined from 'do_rpmb_write_block' at mmc_cmds.c:2293:27:
/home/autobuild/autobuild/instance-15/output-1/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/bits/byteswap.h:52:10: error: 'cnt' may be used uninitialized [-Werror=maybe-uninitialized]
   52 |   return __builtin_bswap32 (__bsx);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
mmc_cmds.c: In function 'do_rpmb_write_block':
mmc_cmds.c:2270:22: note: 'cnt' was declared here
2270 |         unsigned int cnt;
      |                      ^~~
cc1: all warnings being treated as errors
```
This is due to function rpmb_read_counter() that doesn't set its
argument 'unsigned int *cnt' in all return points. So let's set
*cnt to 0 in the return point that misses to initialize it.

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220918161751.1132590-1-giulio.benetti@benettiengineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-09-20 11:41:51 +02:00
Bruno Matic c12b53155f mmc-utils: correct and clean up the file handling
Add the check if the whole firmware was loaded.  Cleaned up the leftovers
of handling the file in chunks.

Signed-off-by: Bruno Matic <bruno.matic@nokia.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220909110322.25141-1-bruno.matic@nokia.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-09-19 16:00:06 +02:00
Christian Löhle d7b343fd26 mmc-utils: Fix 4k sector size block count in FFU
FFU used the wrong assumption, that CMD23 work in
4k sector chunks when setting the block count.
Instead the CMD23 block count argument just needs
to be a multiple of 8, which the fw_size is anyway.

Fixes: 89cd01ed86 (mmc_utils: add ffu support)
Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/54477cf05b9148109996dd85c9afc30f@hyperstone.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-07-13 12:57:35 +02:00
Bean Huo b7e4d5a6ae mmc-utils: Add General command CMD56 read support
We can use GEN_CMD (CMD56) to read a  data block with vendor-specific
format and meaning, which is very helpful and useful for customers to
analyze device health. This patch is to add support for this command.

At the same time, in order to make CMD56 universal, let more users of
mmc-utils can benefit from this. We will allow the user to enter [arg]
for special commands. Because some eMMC vendors provide an additional
set of commands beyond the GEN_CMD (CMD56) definition in the JEDEC
specification. These additional commands are implemented using generic
CMD56 commands, and they return a wealth of useful information about the
state of the NAND device. For these special purposes, the [31:1]stuff
bits in the CMD56 argument are used. You can refer to  Micron eMMC
"TN-FC-32: e·MMC Device Health Report" as an example.

I didn't add data parsing, just print the raw data as it is vendor-specific.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <Avri.Altman@wdc.com>
Tested-by: Rossler Jakob (Nokia - DE/Ulm) <jakob.rossler@nokia.com>
Link: https://lore.kernel.org/r/20220417111622.621650-1-huobean@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-04-26 13:48:57 +02:00
Ulf Hansson 0d493fb091 mmc-utils: Fix build error MMC_BLOCK_MAJOR undeclared
The reported build error:
In function read_extcsd: mmc_cmds.c:72:18: error: MMC_BLOCK_MAJOR
undeclared (first use in this function)

In commit 118dc4a090 ("mmc-utils: Remove unused MMC_BLOCK_MAJOR") the
define for MMC_BLOCK_MAJOR was dropped. In a way this commit is still
correct, but unfortunately it also introduced a dependency to a commit for
the Linux kernel (83fc5dd57f86 mmc: fix compilation of user API), which
fixes the mmc uapi header file.

Rather than relying on the commit in the kernel, let's include the missing
header for MMC_BLOCK_MAJOR.

Reported-by: Ming Liu <liu.ming50@gmail.com>
Fixes: 118dc4a090 ("mmc-utils: Remove unused MMC_BLOCK_MAJOR")
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220426100605.36019-1-ulf.hansson@linaro.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-04-26 13:45:29 +02:00
Shankar Athanikar 4303889c8b Enhancement to do_status_get() function for detailed Response info
This enhancement covers detailed status register decoding with
ERROR/STATUS information when host sends CMD13(with SQS=0)

Signed-off-by: Shankar Athanikar <shankar.ma@samsung.com>
Reviewed-by: Mohan Raj Veerasamy <mohanraj.v@samsung.com>
Link: https://lore.kernel.org/r/20220211120449.195052-1-shankar.ma@samsung.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-02-17 16:15:21 +01:00
Marius Strobl 4637a7c0df mmc-utils: Display STROBE_SUPPORT when printing EXT_CSD
Support for Enhanced Strobe mode introduced in eMMC 5.1 JESD84-B51
can be determined via EXT_CSD[184]. Along with the identification of
HS400 data rates added in commit 3969aa4804 ("mmc_cmds: add HS400
data rates"), this allows to differentiate support for HS400/HS400ES.

Signed-off-by: Marius Strobl <marius@FreeBSD.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220205205647.7677-3-marius@FreeBSD.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-02-08 16:15:35 +01:00
Marius Strobl 118dc4a090 mmc-utils: Remove unused MMC_BLOCK_MAJOR
It was added in commit 294bf86972 ("mmc-utils: Remove dependency on
linux/major.h.") but never actually used, apparently.

Signed-off-by: Marius Strobl <marius@FreeBSD.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220205205647.7677-2-marius@FreeBSD.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-02-08 16:15:23 +01:00
Marius Strobl 0c316a505b mmc-utils: manpage: Document -c option for partitioning commands
The 'continue' option was added in commit 752072dafe ("Add -c option
for partitioning commands).

Signed-off-by: Marius Strobl <marius@FreeBSD.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20220205205647.7677-1-marius@FreeBSD.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-02-08 16:15:10 +01:00
Shankar Athanikar fd41dca5b1 mmc_cmds: Display BARRIER_CTRL Status when printing EXT_CSD
The status of BARRIER_CTRL can be read from this byte: EXT_CSD[31](R/W)
Signed-off-by: Shankar Athanikar <shankar.ma@samsung.com>
Reviewed-by: <mohanraj.v@samsung.com>
Link: https://lore.kernel.org/r/20211224111917.707440-1-shankar.ma@samsung.com
[Ulf: Cleaned up whitespace and corrected sob-tag]
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-01-25 18:29:56 +01:00
Quentin Schulz 4465006b3c add README
This adds a README to the project so that the contribution process is
explicit as well as the licenses that apply to the source code.

Cc: Quentin Schulz <foss+kernel@0leil.net>
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Link: https://lore.kernel.org/r/20220113094404.64510-1-quentin.schulz@theobroma-systems.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2022-01-25 17:19:41 +01:00
Quentin Schulz 3969aa4804 mmc_cmds: add HS400 data rates
JEDEC 5.1 JESD84-B50.1 DEVICE_TYPE [196] specifies that bit 6 is for
"HS400 Dual Data Rate e•MMC at 200 MHz – 1.8 V I/O" and bit 7 for
"HS400 Dual Data Rate e•MMC at 200 MHz – 1.2 V I/O" so let's add those.

Cc: Quentin Schulz <foss+kernel@0leil.net>
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Link: https://lore.kernel.org/r/20211202161910.3944640-1-quentin.schulz@theobroma-systems.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-12-20 11:04:18 +01:00
Oleh Kravchenko a1b233c2a3 mmc-utils: Use printf() to extract and print fw version
This patch also fixes a compile error with a newer version of GCC:
error: '__builtin_strncpy' output may be truncated copying 8 bytes from
a string of length 511 [-Werror=stringop-truncation]

Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Fixes: 0eea71e4f2 (mmc-utils: Fix for Firmware Version string printing)
Link: https://lore.kernel.org/r/20211130142715.11014-1-oleg@kaa.org.ua
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-12-02 15:23:52 +01:00
Bean Huo ad3fb9fe14 mmc-utils: Add note for CMDQ_MODE_EN runtime value
Since the Linux kernel commit 70b52f090805 ("mmc: block: Disable CMDQ on
the ioctl path"), CMDQ in CMDQ_MODE_EN[15] is disabled before reading EXT_CSD.
Therefore, it is more accurate to use sysfs node to check CMDQ_MODE_EN value.
Add a note print to highlight.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20211114204331.39555-3-huobean@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-11-15 15:59:55 +01:00
Michael Heimpold 7769a4d7ab mmc-utils: One further optimization of trimming routine
The last change to the trimming routine made it more efficient,
however, we can even get rid of the memmove() as we leave the
function with strdup() anyway.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20210920194633.814-1-mhei@heimpold.de
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-09-30 11:46:07 +02:00
Kimito Sakata 0eea71e4f2 mmc-utils: Fix for Firmware Version string printing
Added a local buffer to create a NULL terminated string to print the
Firmware Version instead of attempting to print directly from
ext_csd buffer. The last byte of the Firmware Version field may not
be NULL and the next field may also not be which may cause it to
print garbage.

Tested on x86 platform.

Signed-off-by: Kimito Sakata <kimito.sakata@oracle.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Fixes: 89cd01ed86 (mmc_utils: add ffu support)
Link: https://lore.kernel.org/r/20210713053458.1441-1-oracleks043021@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-08-24 10:57:33 +02:00
Kimito Sakata 43282e80e1 mmc-utils: Add eMMC erase command support
we have been using this erase feature for a while, but it is
still not merged into the upstream mmc-utils. Especially, for
the customer, every time when they update the mmc-utils, they
should re-install this patch again, let's try to make this
erase command upstreamed in the mmc-utils.

We need to send 3 MMC commands and it is important that they
stay in sequence. Therefore we are using MMC_IOC_MULTI_CMD.

Co-developed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Kimito Sakata <kimito.sakata@oracle.com>
Reviewed-by: Kenneth Gibbons <kenny.gibbons@oracle.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20210506191041.1178-1-oracleks043021@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-05-11 12:45:55 +02:00
Stephane Fillod e9654ebc4a Various fixes
These warnings were mainly found using cppcheck.

Signed-off-by: Stephane Fillod <f8cfe@free.fr>
Reviewed-by: Michael Heimpold <mhei@heimpold.de>
Link: https://lore.kernel.org/r/1254580747.16828401.1547561163645.JavaMail.root@zimbra64-e11.priv.proxad.net
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:28:34 +02:00
Stephane Fillod 5edc6a4ed1 Add various SD/eMMC vendors to table
Part if this list update comes from a compilation of this web site[1].

[1] https://www.cameramemoryspeed.com/sd-memory-card-faq/reading-sd-card-cid-serial-psn-internal-numbers/

Signed-off-by: Stephane Fillod <f8cfe@free.fr>
Link: https://lore.kernel.org/r/886907785.16708970.1547560575203.JavaMail.root@zimbra64-e11.priv.proxad.net
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:28:10 +02:00
Stephane Fillod 51434a7ab2 Fix parsing of Product Revision and Serial Number
According to MMC Standard (similar to SDCard Standard).

Signed-off-by: Stephane Fillod <f8cfe@free.fr>
Acked-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/1823652044.3512532.1547484650178.JavaMail.root@zimbra64-e11.priv.proxad.net
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:19:53 +02:00
Fabrice Fontaine 520f54eb94 mmc_cmds.c: fix build with gcc 4.9
Fix following error with gcc 4.9:

mmc_cmds.c:1918:9: error: missing braces around initializer [-Werror=missing-braces]
  struct rpmb_frame frame_status = {0};

Fixes:
 - http://autobuild.buildroot.org/results/bf3b6f9f6ef39b99842b3c92495b7bf359c68158

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Link: https://lore.kernel.org/r/20190928185107.21125-1-fontaine.fabrice@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:17:07 +02:00
Lars Pedersen ad6890a2dd mmc-utils: Add AUTO_EN support in the BKOPS_EN
This patch adds support to enable auto(AUTO_EN) and
manual(MANUAL_EN) in BKOPS_EN register. Auto bkops
can only be used on eMMC 5.0 or newer.

Signed-off-by: Lars Pedersen <lapeddk@gmail.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20191111110051.16490-1-lapeddk@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:12:23 +02:00
Julius Werner be4cac34ea mmc-utils: Expand 'writeprotect boot'
This patch updates 'mmc writeprotect boot set' with a few more optional
parameters, so that it can be used to enable permanent write-protection
and so that the two boot partitions can be protected independently. It
also splits protection information output by 'mmc writeprotect boot get'
by partition.

(Note: eMMC boot partitions are named "Area 1" and "Area 2" by the eMMC
spec, but mmcblk0boot0 and mmcblk0boot1 by Linux. To avoid confusion
between the two numbering schemes, this patch uses 0 and 1 throughout,
even when defining EXT_CSD register bits.)

Signed-off-by: Julius Werner <jwerner@chromium.org>
Link: https://lore.kernel.org/r/20200316202221.107714-1-jwerner@chromium.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:09:25 +02:00
Patrick Oppenlander 5b3e56f708 mmc-utils: Fix scaling of cache size
JESD84-B51 7.4.30 CACHE_SIZE [252:249] states that "the size is
indicated as multiple of kilobits". This is also supported by Table 39,
"e.MMC internal sizes and related Units / Granularities" which lists
"32Kb (=4KB)" as the cache size granularity for 4KiB native devices.

Signed-off-by: Patrick Oppenlander <patrick.oppenlander@gmail.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20200401221453.267360-1-patrick.oppenlander@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:05:57 +02:00
John Ernberg 271bdfc6f2 rpmb: Zero-init MMC_IOC_MULTI_CMD structures
On our board we would occationally see what looked like a
kernel hang while doing RPMB operations, some additional
printk debugging revealed that in the trouble case data
such as this was being sent to the kernel:

    [  109.076981] idata[0]->ic->opcode = 0x19
    [  109.077027] idata[0]->ic->arg = 0x0
    [  109.080954] idata[0]->ic->write_flag = 0x1
    [  109.084691] idata[0]->ic->is_acmd = 0x0
    [  109.089007] idata[0]->ic->flags = 0xb5
    [  109.092949] idata[0]->ic->blocks = 0x1
    [  109.096865] idata[0]->ic->blksz = 0x200
    [  109.100791] idata[0]->ic->postsleep_min_us = 0x7473696e
    [  109.104745] idata[0]->ic->postsleep_max_us = 0x34383370
    [  109.110167] idata[0]->ic->data_timeout_ns = 0x7265632d
    [  109.115494] idata[0]->ic->data_ptr = 00000000e7ddd4cd
    [  109.120832] idata[0]->rpmb = 00000000ffab5640
    [  109.126077] idata[1]->ic->opcode = 0x12
    [  109.130622] idata[1]->ic->arg = 0x0
    [  109.135451] idata[1]->ic->write_flag = 0x0
    [  109.139153] idata[1]->ic->is_acmd = 0x0
    [  109.143437] idata[1]->ic->flags = 0xb5
    [  109.147553] idata[1]->ic->blocks = 0x1
    [  109.151420] idata[1]->ic->blksz = 0x200
    [  109.155251] idata[1]->ic->postsleep_min_us = 0x652d6873
    [  109.159166] idata[1]->ic->postsleep_max_us = 0x35353264
    [  109.164561] idata[1]->ic->data_timeout_ns = 0x632d3931
    [  109.169915] idata[1]->ic->data_ptr = 00000000bc641ed4
    [  109.175152] idata[1]->rpmb = 00000000ffab5640

Therefor, zero-init the MMC_IOC_MULTI_CMD structures to
avoid the obscene sleep values.

Signed-off-by: John Ernberg <john.ernberg@actia.se>
Link: https://lore.kernel.org/r/20201216093146.6218-1-john.ernberg@actia.se
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 15:02:54 +02:00
Shivamurthy Shastri (sshivamurthy) 1b8b13beb4 mmc-utils: let FFU mode use CMD23 and CMD25
As per specification, the host can use either CMD24 or CMD25 in
closed-ended or open-ended way.
CMD25 is better option as it can flash the firmware image in one go.

Signed-off-by: Shivamurthy Shastri <sshivamurthy@micron.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Tested-by: Bean Huo <beanhuo@micron.com>
Link: https://lore.kernel.org/r/MN2PR08MB63973BF8F3C6959487BF5707B86A9@MN2PR08MB6397.namprd08.prod.outlook.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2021-03-30 14:55:52 +02:00
Michael Heimpold 73d6c59af8 Add eMMC vendor Micron to table
Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
2019-10-04 20:47:33 -04:00
Michael Heimpold 6c595aea07 Optimize to_binstr() function
Appending multiple times to same string is slow since strcat() needs
to determine the end during each run. So manually maintain a pointer
to the end to speed-up things.

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
2019-10-04 20:47:30 -04:00
Michael Heimpold c19c7694d2 Fix parsing of character in to_binstr()
When a hex-digit > 'a' or 'A' is read, we have to add an offset of 10
to access the valid symbol in our mapping table.

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
2019-10-04 20:47:27 -04:00
Michael Heimpold de27fd9752 Cleanup memory in error case
In case that we leave due to malformed string,
free the allocated memory before returning.

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
2019-10-04 20:47:24 -04:00
Michael Heimpold de0715d5b0 Check calloc's return value before using the pointer
If calloc fails, bail out immediately instead of trying to
use the NULL pointer.

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
2019-10-04 20:47:11 -04:00
Jungseung Lee d40ec535b9 mmc-utils: feature spec 5.0+, add secure removal type fields to Extended CSD
Display secure removal type when printing Extended CSD
Example:
	# mmc extcsd read /dev/mmcblk0
	...
        Secure Removal Type [SECURE_REMOVAL_TYPE]: 0x39
         information is configured to be removed using a vendor defined
         Supported Secure Removal Type:
          information removed by an erase of the physical memory
          information removed using a vendor defined

Signed-off-by: Jungseung Lee <js07.lee@samsung.com>
Reviewed-by: Avri Altman <Avri.Altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
2019-08-08 18:42:38 -04:00
Nikita Maslov aef913e31b mmc-utils: use MMC_IOC_MULTI_CMD for RPMB access
On some systems which use MMC as a main storage device
it is possible that RPMB commands are mixed with
generic MMC access commands which invalidates RPMB.

This patch uses MMC_IOC_MULTI_CMD.

Signed-off-by: Clément Péron <peron.clem@gmail.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
2018-12-14 20:11:14 -05:00
Wolfram Sang 485b05ec40 use proper type for RPMB blocks_cnt
The JEDEC standard is confusing. The number of max blocks for reading
RPMB is determined by CMD23 which can hold an unsigned int and not only
u16. It is true that the current maximum is 64K of blocks, yet this may
be extended in the future. Let's not apply a limit here which should be
checked by the card.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Chris Ball <chris@printf.net>
2018-12-08 00:51:37 -05:00