aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-21 16:21:39 +0200
committerSimon Glass <sjg@chromium.org>2022-09-25 08:30:05 -0600
commita3718f1e536c564610f23298e2c0540877ef30f8 (patch)
tree52ea8499e1186884714ab81b9e261bc118143a31
parent0c12d9dd23a3bce38170db2bab0cc326def6a1db (diff)
downloadu-boot-a3718f1e536c564610f23298e2c0540877ef30f8.zip
u-boot-a3718f1e536c564610f23298e2c0540877ef30f8.tar.gz
u-boot-a3718f1e536c564610f23298e2c0540877ef30f8.tar.bz2
sandbox: scsi: Move block size into shared struct
Move this information into struct scsi_emul_info so we can use it in common code. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/usb/emul/sandbox_flash.c11
-rw-r--r--include/scsi_emul.h2
2 files changed, 8 insertions, 5 deletions
diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c
index eaa7f1e..e4a8eb2 100644
--- a/drivers/usb/emul/sandbox_flash.c
+++ b/drivers/usb/emul/sandbox_flash.c
@@ -222,9 +222,9 @@ static void handle_read(struct sandbox_flash_priv *priv, ulong lba,
debug("%s: lba=%lx, transfer_len=%lx\n", __func__, lba, transfer_len);
info->read_len = transfer_len;
if (priv->fd != -1) {
- os_lseek(priv->fd, lba * SANDBOX_FLASH_BLOCK_LEN, OS_SEEK_SET);
+ os_lseek(priv->fd, lba * info->block_size, OS_SEEK_SET);
setup_response(priv, info->buff,
- transfer_len * SANDBOX_FLASH_BLOCK_LEN);
+ transfer_len * info->block_size);
} else {
setup_fail_response(priv);
}
@@ -259,11 +259,11 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat,
uint blocks;
if (priv->file_size)
- blocks = priv->file_size / SANDBOX_FLASH_BLOCK_LEN - 1;
+ blocks = priv->file_size / info->block_size - 1;
else
blocks = 0;
resp->last_block_addr = cpu_to_be32(blocks);
- resp->block_len = cpu_to_be32(SANDBOX_FLASH_BLOCK_LEN);
+ resp->block_len = cpu_to_be32(info->block_size);
setup_response(priv, resp, sizeof(*resp));
break;
}
@@ -332,7 +332,7 @@ static int sandbox_flash_bulk(struct udevice *dev, struct usb_device *udev,
bytes_read = os_read(priv->fd, buff, len);
if (bytes_read != len)
return -EIO;
- info->read_len -= len / SANDBOX_FLASH_BLOCK_LEN;
+ info->read_len -= len / info->block_size;
if (!info->read_len)
info->phase = SCSIPH_STATUS;
} else {
@@ -404,6 +404,7 @@ static int sandbox_flash_probe(struct udevice *dev)
return log_ret(-ENOMEM);
info->vendor = plat->flash_strings[STRINGID_MANUFACTURER - 1].s;
info->product = plat->flash_strings[STRINGID_PRODUCT - 1].s;
+ info->block_size = SANDBOX_FLASH_BLOCK_LEN;
return 0;
}
diff --git a/include/scsi_emul.h b/include/scsi_emul.h
index b281c16..86c9379 100644
--- a/include/scsi_emul.h
+++ b/include/scsi_emul.h
@@ -17,6 +17,7 @@
*
* @vendor: Vendor name
* @product: Product name
+ * @block_size: Block size of device in bytes (normally 512)
*
* @phase: Current SCSI phase
* @buff_used: Number of bytes ready to transfer back to host
@@ -30,6 +31,7 @@ struct scsi_emul_info {
void *buff;
const char *vendor;
const char *product;
+ int block_size;
/* state maintained by the emulator: */
enum scsi_cmd_phase phase;