blob: 492353c93dfbc3faf26c0f1fe73889cc6eaa12ad [file] [log] [blame]
Peng Fan617fc292020-05-05 20:28:41 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2020 NXP
4 */
5
Peng Fan617fc292020-05-05 20:28:41 +08006#include <spl.h>
7
Alif Zakuan Yuslaimi23fcaa92025-02-18 16:35:06 +08008char __data_start[0] __section(".__data_start");
Marek BehĂșn4bebdd32021-05-20 13:23:52 +02009char __data_save_start[0] __section(".__data_save_start");
10char __data_save_end[0] __section(".__data_save_end");
Peng Fan617fc292020-05-05 20:28:41 +080011
12u32 cold_reboot_flag = 1;
13
Alif Zakuan Yuslaimi23fcaa92025-02-18 16:35:06 +080014u32 __weak reset_flag(void)
15{
16 return 1;
17}
18
Peng Fan617fc292020-05-05 20:28:41 +080019void spl_save_restore_data(void)
20{
21 u32 data_size = __data_save_end - __data_save_start;
Alif Zakuan Yuslaimi23fcaa92025-02-18 16:35:06 +080022 cold_reboot_flag = reset_flag();
Peng Fan617fc292020-05-05 20:28:41 +080023
24 if (cold_reboot_flag == 1) {
25 /* Save data section to data_save section */
Alif Zakuan Yuslaimi23fcaa92025-02-18 16:35:06 +080026 memcpy(__data_save_start, __data_start, data_size);
Peng Fan617fc292020-05-05 20:28:41 +080027 } else {
28 /* Restore the data_save section to data section */
Alif Zakuan Yuslaimi23fcaa92025-02-18 16:35:06 +080029 memcpy(__data_start, __data_save_start, data_size);
Peng Fan617fc292020-05-05 20:28:41 +080030 }
31
32 cold_reboot_flag++;
33}