Lines Matching +full:mpfs +full:- +full:can
1 // SPDX-License-Identifier: GPL-2.0
8 * Copyright (c) 2022-2023 Microchip Corporation. All rights reserved.
21 #include <soc/microchip/mpfs.h>
44 * |------------------------------| 0x0000000
47 * |------------------------------| 0x0000400
51 * |------------------------------| 0x0100400
54 * |------------------------------| 0x1500400
57 * |------------------------------| 0x2900400
59 * | Reserved for multi-image IAP |
61 * |------------------------------| 0x3D00400
64 * |------------------------------| 0x?
102 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_prepare()
107 * against the currently programmed image and thus may fail - due to in mpfs_auto_update_prepare()
109 * or if the version is the same as that of the in-use image. in mpfs_auto_update_prepare()
116 priv->flash = mpfs_sys_controller_get_flash(priv->sys_controller); in mpfs_auto_update_prepare()
117 if (!priv->flash) in mpfs_auto_update_prepare()
120 erase_size = round_up(erase_size, (u64)priv->flash->erasesize); in mpfs_auto_update_prepare()
131 priv->size_per_bitstream = priv->flash->size - SZ_1K - SZ_1M; in mpfs_auto_update_prepare()
132 priv->size_per_bitstream = round_down(priv->size_per_bitstream / 3, erase_size); in mpfs_auto_update_prepare()
133 if (priv->size_per_bitstream > 20 * SZ_1M) in mpfs_auto_update_prepare()
134 priv->size_per_bitstream = 20 * SZ_1M; in mpfs_auto_update_prepare()
136 if (priv->size_per_bitstream < size) { in mpfs_auto_update_prepare()
137 dev_err(priv->dev, in mpfs_auto_update_prepare()
142 priv->cancel_request = false; in mpfs_auto_update_prepare()
149 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_cancel()
151 priv->cancel_request = true; in mpfs_auto_update_cancel()
161 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_verify_image()
171 return -ENOMEM; in mpfs_auto_update_verify_image()
174 * The system controller can verify that an image in the flash is valid. in mpfs_auto_update_verify_image()
181 response->resp_msg = response_msg; in mpfs_auto_update_verify_image()
182 response->resp_size = AUTO_UPDATE_AUTHENTICATE_RESP_SIZE; in mpfs_auto_update_verify_image()
183 message->cmd_opcode = AUTO_UPDATE_AUTHENTICATE_CMD_OPCODE; in mpfs_auto_update_verify_image()
184 message->cmd_data_size = AUTO_UPDATE_AUTHENTICATE_CMD_DATA_SIZE; in mpfs_auto_update_verify_image()
185 message->response = response; in mpfs_auto_update_verify_image()
186 message->cmd_data = AUTO_UPDATE_AUTHENTICATE_CMD_DATA; in mpfs_auto_update_verify_image()
187 message->mbox_offset = AUTO_UPDATE_UPGRADE_INDEX; in mpfs_auto_update_verify_image()
188 message->resp_offset = AUTO_UPDATE_DEFAULT_RESP_OFFSET; in mpfs_auto_update_verify_image()
190 dev_info(priv->dev, "Running verification of Upgrade Image\n"); in mpfs_auto_update_verify_image()
191 ret = mpfs_blocking_transaction(priv->sys_controller, message); in mpfs_auto_update_verify_image()
192 if (ret | response->resp_status) { in mpfs_auto_update_verify_image()
193 dev_warn(priv->dev, "Verification of Upgrade Image failed!\n"); in mpfs_auto_update_verify_image()
194 return ret ? ret : -EBADMSG; in mpfs_auto_update_verify_image()
197 dev_info(priv->dev, "Verification of Upgrade Image passed!\n"); in mpfs_auto_update_verify_image()
206 size_t erase_size = round_up(AUTO_UPDATE_DIRECTORY_SIZE, (u64)priv->flash->erasesize); in mpfs_auto_update_set_image_address()
212 return -ENOMEM; in mpfs_auto_update_set_image_address()
220 * this is spi-nor, we have to read the first eraseblock, erase that in mpfs_auto_update_set_image_address()
225 ret = mtd_read(priv->flash, AUTO_UPDATE_DIRECTORY_BASE, erase_size, &bytes_read, in mpfs_auto_update_set_image_address()
231 return -EIO; in mpfs_auto_update_set_image_address()
237 ret = mtd_erase(priv->flash, &erase); in mpfs_auto_update_set_image_address()
250 dev_info(priv->dev, "Writing the image address (0x%x) to the flash directory (0x%llx)\n", in mpfs_auto_update_set_image_address()
253 ret = mtd_write(priv->flash, 0x0, erase_size, &bytes_written, (u_char *)buffer); in mpfs_auto_update_set_image_address()
258 return -EIO; in mpfs_auto_update_set_image_address()
266 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_write_bitstream()
275 erase_size = round_up(erase_size, (u64)priv->flash->erasesize); in mpfs_auto_update_write_bitstream()
281 AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream; in mpfs_auto_update_write_bitstream()
290 dev_err(priv->dev, "failed to set image address in the SPI directory: %d\n", ret); in mpfs_auto_update_write_bitstream()
295 dev_err(priv->dev, "bitstream info exceeds permitted size\n"); in mpfs_auto_update_write_bitstream()
296 return -ENOSPC; in mpfs_auto_update_write_bitstream()
301 * Now the .spi image itself can be written to the flash. Preservation in mpfs_auto_update_write_bitstream()
305 erase.len = round_up(size, (size_t)priv->flash->erasesize); in mpfs_auto_update_write_bitstream()
308 dev_info(priv->dev, "Erasing the flash at address (0x%x)\n", image_address); in mpfs_auto_update_write_bitstream()
309 ret = mtd_erase(priv->flash, &erase); in mpfs_auto_update_write_bitstream()
315 * will do all of that itself - including verifying that the bitstream in mpfs_auto_update_write_bitstream()
318 dev_info(priv->dev, "Writing the image to the flash at address (0x%x)\n", image_address); in mpfs_auto_update_write_bitstream()
319 ret = mtd_write(priv->flash, (loff_t)image_address, size, &bytes_written, data); in mpfs_auto_update_write_bitstream()
324 return -EIO; in mpfs_auto_update_write_bitstream()
327 dev_info(priv->dev, "Wrote 0x%zx bytes to the flash\n", bytes_written); in mpfs_auto_update_write_bitstream()
335 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_write()
342 if (priv->cancel_request) in mpfs_auto_update_write()
373 return -ENOMEM; in mpfs_auto_update_available()
380 response->resp_msg = response_msg; in mpfs_auto_update_available()
381 response->resp_size = AUTO_UPDATE_FEATURE_RESP_SIZE; in mpfs_auto_update_available()
382 message->cmd_opcode = AUTO_UPDATE_FEATURE_CMD_OPCODE; in mpfs_auto_update_available()
383 message->cmd_data_size = AUTO_UPDATE_FEATURE_CMD_DATA_SIZE; in mpfs_auto_update_available()
384 message->response = response; in mpfs_auto_update_available()
385 message->cmd_data = AUTO_UPDATE_FEATURE_CMD_DATA; in mpfs_auto_update_available()
386 message->mbox_offset = AUTO_UPDATE_DEFAULT_MBOX_OFFSET; in mpfs_auto_update_available()
387 message->resp_offset = AUTO_UPDATE_DEFAULT_RESP_OFFSET; in mpfs_auto_update_available()
389 ret = mpfs_blocking_transaction(priv->sys_controller, message); in mpfs_auto_update_available()
401 if (response->resp_status) in mpfs_auto_update_available()
402 return -EIO; in mpfs_auto_update_available()
409 return -EPERM; in mpfs_auto_update_available()
416 struct device *dev = &pdev->dev; in mpfs_auto_update_probe()
423 return -ENOMEM; in mpfs_auto_update_probe()
425 priv->sys_controller = mpfs_sys_controller_get(dev); in mpfs_auto_update_probe()
426 if (IS_ERR(priv->sys_controller)) in mpfs_auto_update_probe()
427 return dev_err_probe(dev, PTR_ERR(priv->sys_controller), in mpfs_auto_update_probe()
430 priv->dev = dev; in mpfs_auto_update_probe()
436 "The current bitstream does not support auto-update\n"); in mpfs_auto_update_probe()
438 fw_uploader = firmware_upload_register(THIS_MODULE, dev, "mpfs-auto-update", in mpfs_auto_update_probe()
444 priv->fw_uploader = fw_uploader; in mpfs_auto_update_probe()
453 firmware_upload_unregister(priv->fw_uploader); in mpfs_auto_update_remove()
458 .name = "mpfs-auto-update",