Commit Graph

137 Commits

Author SHA1 Message Date
Bean Huo
523d8f3cfb mmc-utils: Add FFU optional mode 4 for firmware download using repeated CMD24 single-block write command
Add FFU mode 4 which enters FFU mode with CMD6, followed by repeated CMD24 commands to perform
single-block writes for the firmware download. After downloading all firmware data, CMD6 is issued
to exit FFU mode.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Message-ID: <20241025203454.162710-6-beanhuo@iokpp.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-10-28 12:45:38 +01:00
Bean Huo
29ff877964 mmc-utils: Add FFU optional mode 3 that uses CMD6 and CMD24 single-block write to download firmware
Add FFU optional mode 3, which initiates firmware download with CMD6 to enter FFU mode, followed
by CMD24 for single-block write, after each CMD24 single-block write, CMD6 is issued to exit FFU
mode. Which means in this mode, during FW downloading, the device will not remain FFU mode.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Message-ID: <20241025203454.162710-5-beanhuo@iokpp.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-10-28 12:45:38 +01:00
Bean Huo
f3d144021c mmc-utils: Add FFU optional mode 2 using CMD25+CMD12 for Open-ended write download FW
Introduced a new FFU mode 2 of leveraging CMD25+CMD12 for Open-ended Multiple-block write to
download the firmware bundle. In this mmode, the device remains in FFU mode during firmware
download until the downloading is completed.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Message-ID: <20241025203454.162710-4-beanhuo@iokpp.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-10-28 12:45:38 +01:00
Bean Huo
b9c9eff4c4 mmc-utils: Add FFU optional mode 1
Added optional FFU mode 1, in this mode, begins with CMD6, followed by repeated CMD23+CMD25
for downloading the firmware bundle. Once the entire firmware image is downloaded, the FFU
mode is exited with CMD6, ensuring the download is treated as an atomic operation.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Message-ID: <20241025203454.162710-3-beanhuo@iokpp.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-10-28 12:45:38 +01:00
Bean Huo
b3455d831a mmc-utils: Refactor common FFU code into functions to support additional FFU modes
Refactor common FFU code into functions to support additional FFU modes. Follow-up
patches will focus on implementing additional FFU modes and enhancements.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Message-ID: <20241025203454.162710-2-beanhuo@iokpp.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-10-28 12:45:38 +01:00
Rudi Heitbaum
123fd8b2ac mmc-utils: create mandir during install
fixes install faikure when mandir is not already created

  install -m 644 mmc.1 /usr/share/man/man1
  install: cannot create regular file '/usr/share/man/man1': No such file or directory

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/ZpxwXEKy1bAOCes_@378c8c72e398
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-08-01 12:49:20 +02:00
Avri Altman
f884bfe684 mmc-utils: Make functions static for local scope enforcement
Run Sparse and fix its warnings.  Apparently, running make C=1 is rarely
done, so make running sparse default.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240706171412.1613019-1-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-07-08 11:30:08 +02:00
Avri Altman
c8cef0598b mmc-utils: Add Read-the-Docs configuration
Prior of building the documentation page, read-the-docs expects a github
project to be imported into it, so I had to mirror the mmc-utils repo
into https://github.com/avri-altman-wdc/mmc-utils.  It also expects some
mandatory settings in a configuration file - .readthedocs.yaml, add
those as well.  Finally, the public documentation is in
https://mmc-utils.readthedocs.io/en/latest/

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240624112542.25657-3-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-07-08 11:10:34 +02:00
Avri Altman
1d1b1159ce mmc-utils: Add documentation section
This commit adds the essentials for mmc-utils documentation to meet
read-the-docs requirements. run `make html-docs` and direct your browser
to ./docs/_build/html/index.html.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240624112542.25657-2-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-07-08 11:09:56 +02:00
Avri Altman
f757f413de mmc-utils: man 1 mmc-utils
I have put together a draft man page for mmc-utils.  The contents are
from mmc-utils help documents and edited for brevity.  The point is not
to replace the existing docmentation, but to serve as a quick reference.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240329072839.1400-1-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-04-02 12:39:34 +02:00
Giulio Benetti
e1281d4de9 mmc-utils: mmc_cmds: fix type-punned warning on &ext_csd[] casting
When building with -Werror=strict-aliasing error is thrown:

mmc_cmds.c: In function 'do_ffu':
mmc_cmds.c:2972:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  sect_done = htole32(*((__u32 *)&ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0]));
  ^
cc1: all warnings being treated as errors

Let's fix type-punned breaking strict-aliasing by implementing local
per_byte_htole32(__u8 *) and use it for the 2 present occurences of
htole32(). Let's also change sect_done type to __u32 for consistency.

Suggested-by: Avri Altman <Avri.Altman@wdc.com>
Fixes: a1b594ca73 ("mmc-utils: ffu: Simplify ext_csd bytes parsing")
Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20240305184513.400364-1-giulio.benetti@benettiengineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2024-03-07 11:59:00 +01:00
Avri Altman
b5ca140312 mmc-utils: lsmmc: Fix emmc capacity calculation
When the device capacity is larger than 2GB, it shouldn't use c_size but
instead it follows a different calculation using the SEC_COUNT field of
the ext-csd[215:212] - see eMMC spec JESD84-B51 paragraph 7.3.12.

This bug was already in lsmmc when it got merged into mmc-utils, hence
the fixes tag.

Fixes: 4af1749d23 (mmc-utils: Merge the lsmmc tool into mmc-utils)
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230928180658.1795491-5-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-10-10 16:30:03 +02:00
Avri Altman
d1d8a05eeb mmc-utils: lsmmc: Disintegrade print_mmc_csd
Make it more readable and manageable.  No functional change.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230928180658.1795491-4-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-10-10 16:29:55 +02:00
Avri Altman
3b055a2129 mmc-utils: lsmmc: Simplify interface processing functions
Call those directly form process_dir() and remove the no longer needed
print_info().

While at it remove the deprecated EXT_CSD handling.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230928180658.1795491-3-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-10-10 16:29:45 +02:00
Avri Altman
e82719f1d2 mmc-utils: lsmmc: Simplify prinitng manufacturer name
We used to have this odd way of printing the manufacturer name. To that
end we cached the entire database beforehand which is completely
useless.

While at it, get rid of some more redundant code.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230928180658.1795491-2-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-10-10 16:29:34 +02:00
Avri Altman
80271e9a6f mmc-utils: lsmmc: Reuse do_read_reg
All 3 register parsing: CID, CSD, and CSR follow the same structure -
reuse it instead of duplicating the code 3 times. No functional change.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230926100006.1789276-2-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-09-27 12:49:39 +02:00
Giulio Benetti
0b3b45b00d mmc-utils: fix potential overflow
Building with _FORTIFY_SOURCE=3 results in:
                 from mmc_cmds.c:20:
In function ‘read’,
    inlined from ‘do_rpmb_write_key’ at mmc_cmds.c:2233:8:
..unistd.h:38:10: error: ‘__read_alias’ writing 228 or more bytes into a region of size 32 overflows the destination [-Werror=stringop-overflow=]
   38 |   return __glibc_fortify (read, __nbytes, sizeof (char),
      |          ^~~~~~~~~~~~~~~
mmc_cmds.c: In function ‘do_rpmb_write_key’:
mmc_cmds.c:2087:19: note: destination object ‘key_mac’ of size 32
 2087 |         u_int8_t  key_mac[32];
      |                   ^~~~~~~
..unistd.h:26:16: note: in a call to function ‘__read_alias’ declared with attribute ‘access (write_only, 2, 3)’
   26 | extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
      |                ^~~~~~~~~~

To work around this let's check if the return of read() is lower than the
nbyte requested instead of not equal.

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230926131128.3771508-1-giulio.benetti@benettiengineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-09-27 12:47:22 +02:00
Avri Altman
613495ecac mmc-utils: ffu: Add optional chunk-size argument
Normally one would like to perform ffu using the largest possible chunk.
However, since the ffu-timeout is vendor specific, there are times in
which smaller chunks would lead to a more robust ffu process.  Allow
this via an additional optional argument.

Tested-by: Lund Austin <Austin.Lund@garmin.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230625103814.105-7-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-08-07 13:14:42 +02:00
Avri Altman
4d99f67e1c mmc-utils: ffu: Allow ffu of large images
ffu is done using a single multi-ioctl to carry the entire firmware
image. This is limiting the fw image size to be at most 512KB, as the
mmc driver restricts each single ioc data to be at most
MMC_IOC_MAX_BYTES.

the spec however, allows the fw image to be written using multiple write
commands.

To overcome this limitation, if the fw image is larger than 512KB,
split it into a series of 512KB chunks.

fixes: 1b8b13beb4 (mmc-utils: let FFU mode use CMD23 and CMD25)
Reported-by: Lund Austin <Austin.Lund@garmin.com>
Tested-by: Lund Austin <Austin.Lund@garmin.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230625103814.105-6-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-08-07 13:14:42 +02:00
Avri Altman
5ba644bf99 mmc-utils: ffu: Add ffu multi-command set handler
In preparation of sending the fw image in several chunks.
While at it, make use of set_single_cmd() to preapare CMD23 and CMD25.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230625103814.105-5-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-08-07 13:14:25 +02:00
Avri Altman
a1b594ca73 mmc-utils: ffu: Simplify ext_csd bytes parsing
The ext_csd register has this habbit of linking a contiguous set of
bytes into one meaningful double-word.  It does that where the least
significant value is in the lower index - hence little-endian.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230625103814.105-4-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-08-07 13:09:16 +02:00
Avri Altman
6c8944a900 mmc-utils: Add arg argument to set_single_cmd
Will prove itself useful in a minute.
No functional change.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230625103814.105-3-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-08-07 13:08:21 +02:00
Avri Altman
731a1cca55 mmc-utils: Add fill_switch_cmd handler
Writing the ext_csd (MMC_SWITCH) is done in several places throught the
code.  Prepare a single handler for that.

This patch has no functional change.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20230625103814.105-2-avri.altman@wdc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2023-08-07 13:08:21 +02: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