Lines Matching +full:bitstream +full:- +full:flash

1 // SPDX-License-Identifier: GPL-2.0
8 * Copyright (c) 2022-2023 Microchip Corporation. All rights reserved.
42 * SPI Flash layout example:
43 * |------------------------------| 0x0000000
46 * |------------------------------| 0x0000400
49 * | Used for bitstream info |
50 * |------------------------------| 0x0100400
53 * |------------------------------| 0x1500400
56 * |------------------------------| 0x2900400
58 * | Reserved for multi-image IAP |
60 * |------------------------------| 0x3D00400
63 * |------------------------------| 0x?
82 struct mtd_info *flash; member
92 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_prepare()
97 * against the currently programmed image and thus may fail - due to in mpfs_auto_update_prepare()
99 * or if the version is the same as that of the in-use image. in mpfs_auto_update_prepare()
106 priv->flash = mpfs_sys_controller_get_flash(priv->sys_controller); in mpfs_auto_update_prepare()
107 if (!priv->flash) in mpfs_auto_update_prepare()
110 erase_size = round_up(erase_size, (u64)priv->flash->erasesize); in mpfs_auto_update_prepare()
113 * We need to calculate if we have enough space in the flash for the in mpfs_auto_update_prepare()
121 priv->size_per_bitstream = priv->flash->size - SZ_1K - SZ_1M; in mpfs_auto_update_prepare()
122 priv->size_per_bitstream = round_down(priv->size_per_bitstream / 3, erase_size); in mpfs_auto_update_prepare()
123 if (priv->size_per_bitstream > 20 * SZ_1M) in mpfs_auto_update_prepare()
124 priv->size_per_bitstream = 20 * SZ_1M; in mpfs_auto_update_prepare()
126 if (priv->size_per_bitstream < size) { in mpfs_auto_update_prepare()
127 dev_err(priv->dev, in mpfs_auto_update_prepare()
128 "flash device has insufficient capacity to store this bitstream\n"); in mpfs_auto_update_prepare()
132 priv->cancel_request = false; in mpfs_auto_update_prepare()
139 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_cancel()
141 priv->cancel_request = true; in mpfs_auto_update_cancel()
146 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_poll_complete()
154 ret = wait_for_completion_timeout(&priv->programming_complete, in mpfs_auto_update_poll_complete()
164 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_verify_image()
170 response_msg = devm_kzalloc(priv->dev, AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), in mpfs_auto_update_verify_image()
173 return -ENOMEM; in mpfs_auto_update_verify_image()
175 response = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GFP_KERNEL); in mpfs_auto_update_verify_image()
177 ret = -ENOMEM; in mpfs_auto_update_verify_image()
181 message = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERNEL); in mpfs_auto_update_verify_image()
183 ret = -ENOMEM; in mpfs_auto_update_verify_image()
188 * The system controller can verify that an image in the flash is valid. in mpfs_auto_update_verify_image()
192 * mbox_offset with the image index in the flash's SPI directory where in mpfs_auto_update_verify_image()
193 * the bitstream is located. in mpfs_auto_update_verify_image()
195 response->resp_msg = response_msg; in mpfs_auto_update_verify_image()
196 response->resp_size = AUTO_UPDATE_AUTHENTICATE_RESP_SIZE; in mpfs_auto_update_verify_image()
197 message->cmd_opcode = AUTO_UPDATE_AUTHENTICATE_CMD_OPCODE; in mpfs_auto_update_verify_image()
198 message->cmd_data_size = AUTO_UPDATE_AUTHENTICATE_CMD_DATA_SIZE; in mpfs_auto_update_verify_image()
199 message->response = response; in mpfs_auto_update_verify_image()
200 message->cmd_data = AUTO_UPDATE_AUTHENTICATE_CMD_DATA; in mpfs_auto_update_verify_image()
201 message->mbox_offset = AUTO_UPDATE_UPGRADE_INDEX; in mpfs_auto_update_verify_image()
202 message->resp_offset = AUTO_UPDATE_DEFAULT_RESP_OFFSET; in mpfs_auto_update_verify_image()
204 dev_info(priv->dev, "Running verification of Upgrade Image\n"); in mpfs_auto_update_verify_image()
205 ret = mpfs_blocking_transaction(priv->sys_controller, message); in mpfs_auto_update_verify_image()
206 if (ret | response->resp_status) { in mpfs_auto_update_verify_image()
207 dev_warn(priv->dev, "Verification of Upgrade Image failed!\n"); in mpfs_auto_update_verify_image()
208 ret = ret ? ret : -EBADMSG; in mpfs_auto_update_verify_image()
211 dev_info(priv->dev, "Verification of Upgrade Image passed!\n"); in mpfs_auto_update_verify_image()
213 devm_kfree(priv->dev, message); in mpfs_auto_update_verify_image()
215 devm_kfree(priv->dev, response); in mpfs_auto_update_verify_image()
217 devm_kfree(priv->dev, response_msg); in mpfs_auto_update_verify_image()
230 erase_size = round_up(erase_size, (u64)priv->flash->erasesize); in mpfs_auto_update_set_image_address()
237 * the system controller where to find the actual bitstream. Since in mpfs_auto_update_set_image_address()
238 * this is spi-nor, we have to read the first eraseblock, erase that in mpfs_auto_update_set_image_address()
239 * portion of the flash, modify the data and then write it back. in mpfs_auto_update_set_image_address()
243 ret = mtd_read(priv->flash, AUTO_UPDATE_DIRECTORY_BASE, erase_size, &bytes_read, in mpfs_auto_update_set_image_address()
249 return -EIO; in mpfs_auto_update_set_image_address()
255 ret = mtd_erase(priv->flash, &erase); in mpfs_auto_update_set_image_address()
268 dev_info(priv->dev, "Writing the image address (%x) to the flash directory (%llx)\n", in mpfs_auto_update_set_image_address()
271 ret = mtd_write(priv->flash, 0x0, erase_size, &bytes_written, (u_char *)buffer); in mpfs_auto_update_set_image_address()
284 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_write_bitstream()
293 erase_size = round_up(erase_size, (u64)priv->flash->erasesize); in mpfs_auto_update_write_bitstream()
296 AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream; in mpfs_auto_update_write_bitstream()
298 buffer = devm_kzalloc(priv->dev, erase_size, GFP_KERNEL); in mpfs_auto_update_write_bitstream()
300 return -ENOMEM; in mpfs_auto_update_write_bitstream()
304 dev_err(priv->dev, "failed to set image address in the SPI directory: %d\n", ret); in mpfs_auto_update_write_bitstream()
309 * Now the .spi image itself can be written to the flash. Preservation in mpfs_auto_update_write_bitstream()
313 erase.len = round_up(size, (size_t)priv->flash->erasesize); in mpfs_auto_update_write_bitstream()
316 dev_info(priv->dev, "Erasing the flash at address (%x)\n", image_address); in mpfs_auto_update_write_bitstream()
317 ret = mtd_erase(priv->flash, &erase); in mpfs_auto_update_write_bitstream()
322 * No parsing etc of the bitstream is required. The system controller in mpfs_auto_update_write_bitstream()
323 * will do all of that itself - including verifying that the bitstream in mpfs_auto_update_write_bitstream()
326 dev_info(priv->dev, "Writing the image to the flash at address (%x)\n", image_address); in mpfs_auto_update_write_bitstream()
327 ret = mtd_write(priv->flash, (loff_t)image_address, size, &bytes_written, data); in mpfs_auto_update_write_bitstream()
332 ret = -EIO; in mpfs_auto_update_write_bitstream()
339 devm_kfree(priv->dev, buffer); in mpfs_auto_update_write_bitstream()
346 struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; in mpfs_auto_update_write()
350 reinit_completion(&priv->programming_complete); in mpfs_auto_update_write()
358 if (priv->cancel_request) { in mpfs_auto_update_write()
368 complete(&priv->programming_complete); in mpfs_auto_update_write()
387 response_msg = devm_kzalloc(priv->dev, in mpfs_auto_update_available()
391 return -ENOMEM; in mpfs_auto_update_available()
393 response = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GFP_KERNEL); in mpfs_auto_update_available()
395 return -ENOMEM; in mpfs_auto_update_available()
397 message = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERNEL); in mpfs_auto_update_available()
399 return -ENOMEM; in mpfs_auto_update_available()
406 response->resp_msg = response_msg; in mpfs_auto_update_available()
407 response->resp_size = AUTO_UPDATE_FEATURE_RESP_SIZE; in mpfs_auto_update_available()
408 message->cmd_opcode = AUTO_UPDATE_FEATURE_CMD_OPCODE; in mpfs_auto_update_available()
409 message->cmd_data_size = AUTO_UPDATE_FEATURE_CMD_DATA_SIZE; in mpfs_auto_update_available()
410 message->response = response; in mpfs_auto_update_available()
411 message->cmd_data = AUTO_UPDATE_FEATURE_CMD_DATA; in mpfs_auto_update_available()
412 message->mbox_offset = AUTO_UPDATE_DEFAULT_MBOX_OFFSET; in mpfs_auto_update_available()
413 message->resp_offset = AUTO_UPDATE_DEFAULT_RESP_OFFSET; in mpfs_auto_update_available()
415 ret = mpfs_blocking_transaction(priv->sys_controller, message); in mpfs_auto_update_available()
427 if (response->resp_status) in mpfs_auto_update_available()
428 return -EIO; in mpfs_auto_update_available()
435 return -EPERM; in mpfs_auto_update_available()
442 struct device *dev = &pdev->dev; in mpfs_auto_update_probe()
449 return -ENOMEM; in mpfs_auto_update_probe()
451 priv->sys_controller = mpfs_sys_controller_get(dev); in mpfs_auto_update_probe()
452 if (IS_ERR(priv->sys_controller)) in mpfs_auto_update_probe()
453 return dev_err_probe(dev, PTR_ERR(priv->sys_controller), in mpfs_auto_update_probe()
456 priv->dev = dev; in mpfs_auto_update_probe()
462 "The current bitstream does not support auto-update\n"); in mpfs_auto_update_probe()
464 init_completion(&priv->programming_complete); in mpfs_auto_update_probe()
466 fw_uploader = firmware_upload_register(THIS_MODULE, dev, "mpfs-auto-update", in mpfs_auto_update_probe()
470 "Failed to register the bitstream uploader\n"); in mpfs_auto_update_probe()
472 priv->fw_uploader = fw_uploader; in mpfs_auto_update_probe()
481 firmware_upload_unregister(priv->fw_uploader); in mpfs_auto_update_remove()
486 .name = "mpfs-auto-update",