88 Commits

Author SHA1 Message Date
Simon Glass
3f133727bf test: Move disk images to persistent-data directory
It is annoying to have disk images in the source directory since it
clutters up the working space.

Remove cur_dir=True from DiskHelper calls so disk images are written to
the persistent-data directory instead.

Move scsi.img too (used by the bootstd tests) and mmc6.img (used by the
MBR tests.

Add a few comments as to where the images are used.

This keeps the source tree clean and puts disk images in the same place
as other test data.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-29 16:18:51 +00:00
Simon Glass
e52931bd12 scsi: Adjust loop counters once in the loop
The current logic is fairly confusing. We always add to_read to start
and we always subtract it from blks. Even the place where blks is set to
0 is really just subtracting to_read.

So move these additions and subtractions out of the if() logic and to
the end of the loop. This is much easier to follow.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:28 -06:00
Simon Glass
690fbc83fd scsi: Move loop counters down next to the loop
Move buf_addr, start and blks down a bit so it is clear that they are
being set up ready for the loop.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:28 -06:00
Simon Glass
62c57729b2 scsi: Use mapmem functions
Rather than casting between addresses and pointers, use the mapmem
functions provided.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:28 -06:00
Simon Glass
3a2dce9d4e scsi: Reorder the local variables
Adjust the ordering of these so they are easier to read.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:28 -06:00
Simon Glass
fd1a6aa8d3 scsi: Use a variable for the number of blocks to process
Each time around the loop a certain number of blocks are processed. Put
this in a variable (to_read/to_write) and avoid changing the input
parameter

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:27 -06:00
Simon Glass
964e0c43f8 scsi: Tidy up error returns for read/write
The current code never returns an error if something goes wrong. While
it is normally useful to return the number of blocks processed, when
nothing is read/written at all, there is clearly something wrong.

Update the logic to return -EIO in this case.

Avoid changing blkcnt since it is an input parameter and this is
confusing.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:05 -06:00
Simon Glass
3a18b243a7 scsi: Check SCSI spec version for LUN handling
Recent versions of SCSI handle the LUN outside the command region. Check
for this and obey.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:05 -06:00
Simon Glass
58aaaabd8f scsi: Only add the LUN to the command if needed
Newer SCSI controllers handle the LUN in a different place from the SCSI
command. Detect this and adjust the command accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:05 -06:00
Simon Glass
298dd563ac scsi: Create a function to add command and LUN to the ccb
Rather than doing the same shift operation each time, create a function
which writes in the correct command and the LUN. This will allows us to
handle newer controllers which do not want the LUN in the command.

Fix checkpatch warnings about CONFIG_SYS_64BIT_LBA while here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:04 -06:00
Simon Glass
6cbb400bae scsi: Drop use of #ifdef with CONFIG_SYS_64BIT_LBA
Use if() for this condition. Adjust scsi_setup_read16() to use a
standard unaligned access to avoid shifting more than 32 on a 32-bit
architecture (which produces a compiler warning).

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:40:25 -06:00
Simon Glass
038a6b1cb3 scsi: Rename block_dev and dev_desc to desc
The word 'block_dev' suggests it is a device, but this struct is not the
device (now that we use driver model), only some information about it.

We use desc (for descriptor) elsewhere in the code, so update scsi to do
the same.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:08:28 -06:00
Simon Glass
03b83e47a9 scsi: Use a struct to decode the inquiry response
We have a struct for the response data now, so use that instead of
accessing the bytes directly.

Move setting of the device type higher, so that the field is not
overwritten by the following commands.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:08:09 -06:00
Simon Glass
86f23ce420 scsi: Provide some response flags
Rather than open-coding the SCSI-inquiry-response flags, add an enum and
use that.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:07:47 -06:00
Simon Glass
17cfa10fe0 scsi: Use REPORT LUNS to scan the correct number of LUNs
The current algortihm scans all LUNs on all targets. Where the potential
number is very large, as with QEMU (256 targets each with 4K LUNs) this
is a substantial waste of time.

Use the REPORT LUNS command to determine the number of LUNs on each
target. Where that fails, fall back to scanning everything.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:07:33 -06:00
Simon Glass
ee3e499c96 scsi: Use hex in block-device names
Use hex values to fit better with how these devices are accessed with
the 'part list' command and others.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 12:48:45 -06:00
Simon Glass
6cf6b99c9f scsi: Fix off-by-one error when scanning
The maximum values of target and LUN should be used, rather than one
less than those values. Fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 12:48:45 -06:00
Simon Glass
5d008e0414 scsi: Add a constant for the tempbuff size
Use a constant for this size, rather than open-coding the value.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 12:48:45 -06:00
Simon Glass
ddaa12e605 sandbox: Update os_open() to return an error code
It is convenient to be able to report the system error when available.
Update os_open() to return it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 07:53:25 -06:00
Tom Rini
ad42ea0175 blk: Make block subsystems select BLK
The BLK symbol has a few meanings, one of which is that it controls the
driver model portion of a "block device". Rather than having this hidden
symbol be "default y if ..." it should be select'd by the various block
subsystems. Symbols such as PVBLOCK which already select'd BLK are
unchanged".

Reviewed-by: Peter Robinson <pbrobinson@gmail.com>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Signed-off-by: Tom Rini <trini@konsulko.com>
2025-05-16 14:45:25 +02:00
Julius Lehmann
5f7c06bdc3 scsi: fix disk capacity too small by one sector
SCSI READ CAPACITY reports the address of the last block and the block
size. The total number of blocks is thus last block address plus one.

This also fixes the corresponding test case.
2024-11-01 13:34:32 -06:00
Simon Glass
5c10c8badf global: Rename SPL_TPL_ to PHASE_
Use PHASE_ as the symbol to select a particular XPL build. This means
that SPL_TPL_ is no-longer set.

Update the comment in bootstage to refer to this symbol, instead of
SPL_

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-10-11 11:44:48 -06:00
Simon Glass
371dc068bb drivers: Use CONFIG_XPL_BUILD instead of CONFIG_SPL_BUILD
Use the new symbol to refer to any 'SPL' build, including TPL and VPL

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-10-11 11:44:48 -06:00
Marek Vasut
76429988da drivers: scsi: Remove duplicate newlines
Drop all duplicate newlines. No functional change.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2024-07-22 10:53:06 -06:00
Tom Rini
03de305ec4 Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
As part of bringing the master branch back in to next, we need to allow
for all of these changes to exist here.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-20 13:35:03 -06:00
Tom Rini
d678a59d2d Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d, reversing
changes made to 2ee6f3a5f7.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-19 08:16:36 -06:00
Tom Rini
8625f7bb6e scsi: Remove <common.h> and add needed includes
Remove <common.h> from this driver directory and when needed
add missing include files directly.

Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-07 08:00:56 -06:00
Tom Rini
dca7a8958f Merge tag 'v2024.01-rc3' into next
Prepare v2024.01-rc3
2023-11-20 09:19:50 -05:00
Nikita Yushchenko
beeb91aa64 scsi: set dma direction to NONE for TEST UNIT READY
SCSI device scan code was executing TEST UNIT READY command without
explicitly setting dma direction in struct scsi_cmd to NONE, so command
was passed to driver with dma direction set to DMA_FROM_DEVICE,
inherited from older usage.

With WDC SDINDDH6-64G ufs device, that caused TEST UNIT READY to
return error.

Fix that, by explicitly setting dma direction to NONE for
TEST UNIT READY, and restoring it back DMA_FROM_DEVICE for the
following READ CAPACITY.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Reviewed-by: Marek Vasut <marex@denx.de>
2023-11-20 08:34:08 -05:00
Tom Rini
d2174dbff1 scsi: Have scsi_init_dev_desc_priv() use memset
When we do not have CONFIG_BOUNCE_BUFFER enabled, inside of
scsi_init_dev_desc_priv we never set the 'bb' field to false, we only
initialize it to true when CONFIG_BOUNCE_BUFFER is set. Given that we
have a number of other fields here we had been explicitly setting to
zero, change to first calling memset to clear the struct and then
initialize only the fields that need non-zero default values.

Addresses-Coverity-ID: 467407 ("Uninitialized variables (UNINIT)")
Fixes: 81bd22e935 ("rockchip: block: blk-uclass: add bounce buffer flag to blk_desc")
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-11-10 10:59:24 -05:00
Tom Rini
b630f8b3ae scsi: Forceably finish migration to DM_SCSI
The migration deadline for moving to DM_SCSI was v2023.04. A further
reminder was sent out in August 2023 to the remaining platforms that had
not migrated already, and that a few more over the line (or configs
deleted).

With this commit we:
- Rename CONFIG_DM_SCSI to CONFIG_SCSI.
- Remove all of the non-DM SCSI code. This includes removing other
  legacy symbols and code and removes some legacy non-DM AHCI code.
- Some platforms that had previously been DM_SCSI=y && SCSI=n are now
  fully migrated to DM_SCSI as a few corner cases in the code assumed
  DM_SCSI=y meant SCSI=y.

Signed-off-by: Tom Rini <trini@konsulko.com>
2023-11-07 18:36:06 -05:00
Johan Jonker
81bd22e935 rockchip: block: blk-uclass: add bounce buffer flag to blk_desc
Currently bounce buffer support is enabled for all block devices
when available. Add a flag to blk_desc to enable only on demand.

Signed-off-by: Johan Jonker <jbx6244@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
2023-10-24 15:55:17 +08:00
Marek Vasut
4f543e82b9 scsi: Add buffer_aligned check pass-through
Some devices have limited DMA capabilities and require that the
buffers passed to them fit specific properties. Add new optional
callback which can be used at driver level to indicate whether a
buffer alignment is suitable for the device DMA or not. This is
a pass-through callback from block uclass to drivers.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2023-08-22 15:17:53 -04:00
Tom Rini
7e6e40c572 Merge tag 'v2023.10-rc3' into next
Prepare v2023.10-rc3

Signed-off-by: Tom Rini <trini@konsulko.com>
2023-08-21 17:32:17 -04:00
Marek Vasut
02660defdc scsi: Cache align temporary buffer
The temporary buffer may be passed to DMA capable device,
make sure it is cache aligned.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2023-08-17 16:39:20 -04:00
Simon Glass
d7d78576bb bootstd: Rename bootdev_setup_sibling_blk()
This name is a little confusing since it suggests that it sets up the
sibling block device. In fact it sets up a bootdev for it. Rename the
function to make this clearer.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-08-09 23:31:11 +08:00
Simon Glass
4de979f664 bootstd: Use bootdev instead of bootdevice
It seems better to call this a 'bootdev' since this is name used in the
documentation. The older 'Bootdevice' name is no-longer used and may cause
confusion with the 'bootdevice' environment variable.

Update throughout to use bootdev.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2023-07-16 23:13:17 +08:00
Heinrich Schuchardt
854aaf9024 scsi: typo supporedt
%s/supporedt/supported/

Fixes: edca8cf721 ("Convert CONFIG_SCSI_AHCI_PLAT et al to Kconfig")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-04-01 10:11:50 +02:00
Simon Glass
eacc261178 bootstd: Add a new pre-scan priority for bootdevs
We need extensions to be set up before we start trying to boot any of the
bootdevs. Add a new priority before all the others for tht sort of thing.
Also add a 'none' option, so that the first one is not 0.

While we are here, comment enum bootdev_prio_t fully and expand the test
for the 'bootdev hunt' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
8f090b67d0 bootstd: Add a SCSI bootdev
Add a bootdev for SCSI so that these devices can be used with standard
boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:40 -05:00
Simon Glass
6febc26471 scsi: Remove all children of SCSI devices before rescanning
At present this only unbinds block devices of a certain type. But SCSI
device can have different types of children, including bootdevs.

Unbind all children so tht everything is clean and ready for a new scan.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:40 -05:00
Simon Glass
ca93d28171 scsi: Correct allocation of block-device name
This should be allocated so that it does not go out of scope. Fix this and
set the log category while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:40 -05:00
Tom Rini
77d0870c29 global: Migrate CONFIG_SCSI_DEV_LIST to CFG
Perform a simple rename of CONFIG_SCSI_DEV_LIST to CFG_SCSI_DEV_LIST

Signed-off-by: Tom Rini <trini@konsulko.com>
2022-12-23 10:15:11 -05:00
Simon Glass
2ff3db3a1c usb: Update the test to cover reading and writing
Add test coverage for blk_write() as well.

The blk_erase() is not tested for now as the USB stor interface does not
support erase.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-10-31 11:02:44 -04:00
Simon Glass
46df024394 sandbox: Convert to use driver model for SCSI
At present sandbox is producing a warning about SCSI migration. Drop the
legacy code and replace it with a new implementation.

Also drop the SATA command, which does not work with driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-09-25 13:59:50 -06:00
Simon Glass
02cea1145a sandbox: scsi: Move request-handling code to scsi_emul
Move this code into the emulator file so it can be used by multiple
drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-09-25 13:59:38 -06:00
Simon Glass
8149b1500d blk: Rename if_type to uclass_id
Use the word 'uclass' instead of 'if_type' to complete the conversion.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-09-25 08:30:05 -06:00
Simon Glass
e33a5c6be5 blk: Switch over to using uclass IDs
We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-09-16 11:05:16 -04:00
Simon Glass
ca28baf17c blk: Select SPL_LEGACY_BLOCK automatically
Selecting this option can be handled in the Kconfig option itself, as it
is with BLK. Update this an drop the various 'select' clauses.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-09-16 11:05:16 -04:00
Simon Glass
7f8967c2b8 blk: Rename HAVE_BLOCK_DEVICE
This option is fact really related to SPL. For U-Boot proper we always use
driver model for block devices, so CONFIG_BLK is enabled if block devices
are in use.

It is only for SPL that we have two cases:

- SPL_BLK is enabled, in which case we use driver model and blk-uclass.c
- SPL_BLK is not enabled, in which case (if we need block devices) we must
  use blk_legacy.c

Rename the symbol to SPL_LEGACY_BLOCK to make this clear. This is
different enough from BLK and SPL_BLK that there should be no confusion.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-09-16 11:05:16 -04:00