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