From: Conor Dooley <conor@kernel.org>
To: linux-riscv@lists.infradead.org
Cc: conor@kernel.org, Conor Dooley <conor.dooley@microchip.com>,
Daire McNamara <daire.mcnamara@microchip.com>,
Cyril Jean <cyril.jean@microchip.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v1 1/5] firmware: microchip: support writing bitstream info to flash
Date: Wed, 10 Apr 2024 12:58:04 +0100 [thread overview]
Message-ID: <20240410-shabby-fineness-6e8662cf44e2@spud> (raw)
In-Reply-To: <20240410-opulently-epic-8654bdac3422@spud>
From: Conor Dooley <conor.dooley@microchip.com>
Updating the FPGA image might bring with it changes visible to Linux,
so it is helpful to also co-locate dt-overlays that describe the new
image contents. If these are packaged in a specific format [1] (detected
by first 4 bytes being MCHP, since FPGA images have no magic), load
the file to the reserved 1 MiB region immediately after the directory in
flash. The Beagle-V Fire's "gateware" already creates these files and
puts them in flash [2].
Link: exists on confluence, needs to be made public
Link: https://openbeagle.org/beaglev-fire/gateware/-/blob/main/gateware_scripts/generate_gateware_overlays.py?ref_type=heads [2]
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
---
drivers/firmware/microchip/mpfs-auto-update.c | 47 +++++++++++++++----
1 file changed, 39 insertions(+), 8 deletions(-)
diff --git a/drivers/firmware/microchip/mpfs-auto-update.c b/drivers/firmware/microchip/mpfs-auto-update.c
index 32394c24b37d..33343e83373c 100644
--- a/drivers/firmware/microchip/mpfs-auto-update.c
+++ b/drivers/firmware/microchip/mpfs-auto-update.c
@@ -71,8 +71,9 @@
#define AUTO_UPDATE_UPGRADE_DIRECTORY (AUTO_UPDATE_DIRECTORY_WIDTH * AUTO_UPDATE_UPGRADE_INDEX)
#define AUTO_UPDATE_BLANK_DIRECTORY (AUTO_UPDATE_DIRECTORY_WIDTH * AUTO_UPDATE_BLANK_INDEX)
#define AUTO_UPDATE_DIRECTORY_SIZE SZ_1K
-#define AUTO_UPDATE_RESERVED_SIZE SZ_1M
-#define AUTO_UPDATE_BITSTREAM_BASE (AUTO_UPDATE_DIRECTORY_SIZE + AUTO_UPDATE_RESERVED_SIZE)
+#define AUTO_UPDATE_INFO_BASE AUTO_UPDATE_DIRECTORY_SIZE
+#define AUTO_UPDATE_INFO_SIZE SZ_1M
+#define AUTO_UPDATE_BITSTREAM_BASE (AUTO_UPDATE_DIRECTORY_SIZE + AUTO_UPDATE_INFO_SIZE)
#define AUTO_UPDATE_TIMEOUT_MS 60000
@@ -86,6 +87,17 @@ struct mpfs_auto_update_priv {
bool cancel_request;
};
+static bool mpfs_auto_update_is_bitstream_info(const u8 *data, u32 size)
+{
+ if (size < 4)
+ return false;
+
+ if (data[0] == 0x4d && data[1] == 0x43 && data[2] == 0x48 && data[3] == 0x50)
+ return true;
+
+ return false;
+}
+
static enum fw_upload_err mpfs_auto_update_prepare(struct fw_upload *fw_uploader, const u8 *data,
u32 size)
{
@@ -287,22 +299,37 @@ static int mpfs_auto_update_write_bitstream(struct fw_upload *fw_uploader, const
loff_t directory_address = AUTO_UPDATE_UPGRADE_DIRECTORY;
size_t erase_size = AUTO_UPDATE_DIRECTORY_SIZE;
size_t bytes_written = 0;
+ bool is_info = mpfs_auto_update_is_bitstream_info(data, size);
u32 image_address;
int ret;
erase_size = round_up(erase_size, (u64)priv->flash->erasesize);
- image_address = AUTO_UPDATE_BITSTREAM_BASE +
- AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream;
+ if (is_info)
+ image_address = AUTO_UPDATE_INFO_BASE;
+ else
+ image_address = AUTO_UPDATE_BITSTREAM_BASE +
+ AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream;
buffer = devm_kzalloc(priv->dev, erase_size, GFP_KERNEL);
if (!buffer)
return -ENOMEM;
- ret = mpfs_auto_update_set_image_address(priv, buffer, image_address, directory_address);
- if (ret) {
- dev_err(priv->dev, "failed to set image address in the SPI directory: %d\n", ret);
- goto out;
+ /*
+ * For bitstream info, the descriptor is written to a fixed offset,
+ * so there is no need to set the image address.
+ */
+ if (!is_info) {
+ ret = mpfs_auto_update_set_image_address(priv, buffer, image_address, directory_address);
+ if (ret) {
+ dev_err(priv->dev, "failed to set image address in the SPI directory: %d\n", ret);
+ return ret;
+ }
+ } else {
+ if (size > AUTO_UPDATE_INFO_SIZE) {
+ dev_err(priv->dev, "bitstream info exceeds permitted size\n");
+ return -ENOSPC;
+ }
}
/*
@@ -334,6 +361,7 @@ static int mpfs_auto_update_write_bitstream(struct fw_upload *fw_uploader, const
}
*written = bytes_written;
+ dev_info(priv->dev, "Wrote 0x%zx bytes to the flash\n", bytes_written);
out:
devm_kfree(priv->dev, buffer);
@@ -360,6 +388,9 @@ static enum fw_upload_err mpfs_auto_update_write(struct fw_upload *fw_uploader,
goto out;
}
+ if (mpfs_auto_update_is_bitstream_info(data, size))
+ goto out;
+
ret = mpfs_auto_update_verify_image(fw_uploader);
if (ret)
err = FW_UPLOAD_ERR_FW_INVALID;
--
2.43.0
next prev parent reply other threads:[~2024-04-10 11:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-10 11:58 [PATCH v1 0/5] PolarFire SoC Auto Update design info support Conor Dooley
2024-04-10 11:58 ` Conor Dooley [this message]
2024-04-10 11:58 ` [PATCH v1 2/5] firmware: microchip: don't unconditionally print validation success Conor Dooley
2024-04-24 20:26 ` Alexandre Ghiti
2024-04-24 20:59 ` Conor Dooley
2024-04-24 21:04 ` Conor Dooley
2024-04-10 11:58 ` [PATCH v1 3/5] firmware: microchip: clarify that sizes and addresses are in hex Conor Dooley
2024-04-10 11:58 ` [PATCH v1 4/5] firmware: microchip: move buffer allocation into mpfs_auto_update_set_image_address() Conor Dooley
2024-04-10 11:58 ` [PATCH v1 5/5] firmware: microchip: use scope-based cleanup where possible Conor Dooley
2024-06-05 18:42 ` (subset) [PATCH v1 0/5] PolarFire SoC Auto Update design info support Conor Dooley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240410-shabby-fineness-6e8662cf44e2@spud \
--to=conor@kernel.org \
--cc=conor.dooley@microchip.com \
--cc=cyril.jean@microchip.com \
--cc=daire.mcnamara@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®