Skip to content

Commit 936baa3

Browse files
Merge pull request #1013 from FrameworkComputer/marigold.rw_support
Marigold: add system ro/rw support
2 parents d3c5beb + c75100f commit 936baa3

8 files changed

Lines changed: 83 additions & 1 deletion

File tree

common/system.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,21 @@ static int handle_pending_reboot(struct ec_params_reboot_ec *p)
10431043
return system_run_image_copy_with_flags(
10441044
EC_IMAGE_RO, EC_RESET_FLAG_STAY_IN_RO);
10451045
case EC_REBOOT_JUMP_RW:
1046+
#if defined(CONFIG_CUSTOMIZED_DESIGN) && defined(CONFIG_PLATFORM_EC_SYSTEM_JUMP_RW_SUPPORT)
1047+
system_set_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_FLAG, 1);
1048+
system_set_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS, 0);
1049+
#endif
10461050
return system_run_image_copy(system_get_active_copy());
10471051
case EC_REBOOT_COLD:
10481052
case EC_REBOOT_COLD_AP_OFF:
1053+
#if defined(CONFIG_CUSTOMIZED_DESIGN) && defined(CONFIG_PLATFORM_EC_SYSTEM_JUMP_RW_SUPPORT)
1054+
/*
1055+
* Flash RW image doesn't work if you're already in RW. Need to reboot to RO
1056+
* and then jump again, so clear the flag here.
1057+
*/
1058+
system_set_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_FLAG, 0);
1059+
system_set_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS, 0);
1060+
#endif
10491061
/*
10501062
* Reboot the PD chip(s) as well, but first suspend the ports
10511063
* if this board has PD tasks running so they don't query the

include/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ enum system_bbram_idx {
516516
SYSTEM_BBRAM_IDX_CHASSIS_TOTAL,
517517
SYSTEM_BBRAM_IDX_CHASSIS_VTR_OPEN,
518518
SYSTEM_BBRAM_IDX_VPRO_STATUS,
519+
SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_FLAG,
520+
SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS,
519521
#endif
520522
};
521523

zephyr/Kconfig.system

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,12 @@ config PLATFORM_EC_HOST_COMMAND_MEMORY_DUMP
122122
debugging panics. May not dump all memory, e.g. sensitive memory will
123123
not be dumped.
124124

125+
config PLATFORM_EC_SYSTEM_JUMP_RW_SUPPORT
126+
bool "Enable system jump to rw support"
127+
default n
128+
help
129+
Enable system boot to rw support, system will check bbram flag (SYSTEM_
130+
BBRAM_IDX_SYSTEM_JUMP_RW_FLAG and SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS)
131+
to determine whether to jump to rw on boot. Default will boot from ro.
132+
125133
endif # PLATFORM_EC

zephyr/app/ec/ec_app_main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ static void boot_allow_sleep(struct k_timer *timer)
2929
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
3030
}
3131

32+
#if defined(CONFIG_CUSTOMIZED_DESIGN) && defined(CONFIG_PLATFORM_EC_SYSTEM_JUMP_RW_SUPPORT)
33+
void check_rw_boot(void)
34+
{
35+
if (system_get_image_copy() == EC_IMAGE_RW)
36+
system_set_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS, 1);
37+
else
38+
system_set_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS, 0);
39+
40+
}
41+
DECLARE_DEFERRED(check_rw_boot);
42+
#endif
43+
3244
/* For testing purposes this is not named main. See main_shim.c for the real
3345
* main() function.
3446
*/
@@ -80,6 +92,22 @@ void ec_app_main(void)
8092
button_init();
8193
}
8294

95+
#if defined(CONFIG_CUSTOMIZED_DESIGN) && defined(CONFIG_PLATFORM_EC_SYSTEM_JUMP_RW_SUPPORT)
96+
uint8_t rw_flag, rw_success;
97+
98+
system_get_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_FLAG, &rw_flag);
99+
system_get_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS, &rw_success);
100+
ccprints("Get boot rw_flag:%d, rw_success:%d", rw_flag, rw_success);
101+
102+
if (rw_flag && rw_success) {
103+
/*Clear flag and boot to RW*/
104+
system_set_bbram(SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS, 0);
105+
system_run_image_copy(system_get_active_copy());
106+
}
107+
108+
hook_call_deferred(&check_rw_boot_data, 5 * SECOND);
109+
#endif
110+
83111
if (IS_ENABLED(CONFIG_PLATFORM_EC_VBOOT_EFS2)) {
84112
/*
85113
* For RO, it behaves as follows:

zephyr/program/framework/marigold/overlay.dtsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@
134134
offset = <0x4c>;
135135
size = <0x01>;
136136
};
137+
system_jump_rw_flag {
138+
offset = <0x4d>;
139+
size = <0x01>;
140+
};
141+
system_jump_rw_success {
142+
offset = <0x4e>;
143+
size = <0x01>;
144+
};
137145
};
138146
};
139147

zephyr/program/framework/marigold/project.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ CONFIG_PLATFORM_EC_8042_AUX=y
4949
# PD
5050
CONFIG_PD_COMMON_VBUS_CONTROL=n
5151
CONFIG_PD_USB_PID=0x001A
52+
53+
# TP test
54+
CONFIG_PLATFORM_IGNORED_TOUCHPAD_ID=y
55+
56+
57+
# System
58+
CONFIG_PLATFORM_EC_SYSTEM_JUMP_RW_SUPPORT=y

zephyr/program/framework/src/board_host_command.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,12 @@ static enum ec_status host_command_get_simple_version(struct host_cmd_handler_a
384384
char temp_version[32] = {0};
385385
int idx;
386386
int shift = CONFIG_PLATFORM_SIMPLE_VERSION_SHIFT_IDX;
387-
enum ec_image active_slot = system_get_active_copy();
387+
enum ec_image active_slot;
388+
389+
if (system_get_image_copy() == EC_IMAGE_RO)
390+
active_slot = EC_IMAGE_RO;
391+
else
392+
active_slot = system_get_active_copy();
388393

389394
strzcpy(temp_version, system_get_version(active_slot),
390395
sizeof(temp_version));

zephyr/shim/src/system.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ static int bbram_lookup(enum system_bbram_idx idx, int *offset_out,
131131
break;
132132

133133
#endif
134+
#if BBRAM_HAS_REGION(system_jump_rw_flag)
135+
case SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_FLAG:
136+
*offset_out = BBRAM_REGION_OFFSET(system_jump_rw_flag);
137+
*size_out = BBRAM_REGION_SIZE(system_jump_rw_flag);
138+
break;
139+
#endif
140+
#if BBRAM_HAS_REGION(system_jump_rw_success)
141+
case SYSTEM_BBRAM_IDX_SYSTEM_JUMP_RW_SUCCESS:
142+
*offset_out = BBRAM_REGION_OFFSET(system_jump_rw_success);
143+
*size_out = BBRAM_REGION_SIZE(system_jump_rw_success);
144+
break;
145+
#endif
134146
#endif /* CONFIG_PLATFORM_EC_CUSTOMIZED_DESIGN */
135147
default:
136148
return EC_ERROR_INVAL;

0 commit comments

Comments
 (0)