| Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| Sandrine Bailleux | 7d34d30 | 2018-11-26 10:13:51 +0100 | [diff] [blame] | 8 | #include <bl1.h> |
| Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 9 | #include <debug.h> |
| 10 | #include <firmware_image_package.h> |
| 11 | #include <fwu_nvm.h> |
| 12 | #include <platform.h> |
| 13 | #include <platform_def.h> |
| 14 | |
| 15 | extern const char version_string[]; |
| 16 | |
| 17 | void ns_bl2u_main(void) |
| 18 | { |
| 19 | smc_args fwu_params = {0}; |
| 20 | smc_ret_values fwu_result = {0}; |
| 21 | |
| 22 | NOTICE("NS_BL2U: %s\n", version_string); |
| 23 | NOTICE("NS_BL2U: %s\n", build_message); |
| 24 | |
| 25 | tftf_platform_setup(); |
| 26 | |
| 27 | #if FWU_BL_TEST |
| 28 | unsigned int toc_header; |
| 29 | STATUS status = fwu_nvm_read(0, &toc_header, 4); |
| 30 | if (status != STATUS_SUCCESS) { |
| 31 | ERROR("NS_BL2U: Failed to read NVM\n"); |
| 32 | panic(); |
| 33 | } |
| 34 | |
| 35 | /* Update the TOC if found invalid. */ |
| 36 | if (toc_header != TOC_HEADER_NAME) { |
| 37 | toc_header = TOC_HEADER_NAME; |
| 38 | status = fwu_nvm_write(0, &toc_header, 4); |
| 39 | if (status != STATUS_SUCCESS) { |
| 40 | ERROR("NS_BL2U: Failed to update TOC value\n"); |
| 41 | panic(); |
| 42 | } |
| 43 | INFO("NS_BL2U: Updated TOC value\n"); |
| 44 | } |
| 45 | #endif |
| 46 | |
| 47 | /* Update the FIP image. */ |
| 48 | if (fwu_update_fip(FIP_BKP_ADDRESS) != STATUS_SUCCESS) { |
| 49 | ERROR("NS_BL2U: Firmware Image Update Failed\n"); |
| 50 | panic(); |
| 51 | } |
| 52 | |
| 53 | /* Call FWU_SMC_UPDATE_DONE to indicate image update done. */ |
| 54 | INFO("NS_BL2U: Calling FWU_SMC_UPDATE_DONE\n"); |
| Sandrine Bailleux | 1779506 | 2018-12-13 16:02:41 +0100 | [diff] [blame] | 55 | fwu_params.fid = FWU_SMC_UPDATE_DONE; |
| Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 56 | fwu_result = tftf_smc(&fwu_params); |
| 57 | ERROR("NS_BL2U: Unexpected return from FWU process (%d)\n", |
| 58 | (int)fwu_result.ret0); |
| 59 | panic(); |
| 60 | } |