@@ -49,7 +49,7 @@ static nvs_handle pycom_nvs_handle;
4949boot_info_t boot_info ;
5050uint32_t boot_info_offset ;
5151
52- static void modpycom_bootmgr (uint8_t boot_partition , uint8_t fs_type , uint8_t safeboot );
52+ static void modpycom_bootmgr (uint8_t boot_partition , uint8_t fs_type , uint8_t safeboot , bool reset );
5353
5454void modpycom_init0 (void ) {
5555 if (nvs_open (NVS_NAMESPACE , NVS_READWRITE , & pycom_nvs_handle ) != ESP_OK ) {
@@ -61,38 +61,60 @@ void modpycom_init0(void) {
6161 }
6262}
6363
64- static void modpycom_bootmgr (uint8_t boot_partition , uint8_t fs_type , uint8_t safeboot ) {
65- bool update_boot = false;
64+ static void modpycom_bootmgr (uint8_t boot_partition , uint8_t fs_type , uint8_t safeboot , bool reset ) {
65+ bool update_part = false;
66+ bool update_fstype = false;
67+ bool update_safeboot = false;
6668
6769 if (boot_partition < 255 ) {
68- if (boot_partition <= 1 ) {
70+ if ((boot_partition <= IMG_ACT_UPDATE1 ) && (boot_info .ActiveImg != boot_partition )) {
71+ boot_info .PrevImg = boot_info .ActiveImg ;
6972 boot_info .ActiveImg = (uint32_t )boot_partition ;
70- boot_info .Status = 0 ;
71- update_boot = true;
73+ boot_info .Status = IMG_STATUS_CHECK ;
74+ update_part = true;
7275 } else {
73- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Error invalid boot partition!" ));
76+ nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Error invalid boot partition! or partition already active! " ));
7477 }
7578 }
7679 if (safeboot < 255 ) {
77- if (safeboot <= 1 ) {
78- boot_info .safeboot = (uint32_t )safeboot ;
79- update_boot = true;
80+ if ((safeboot <= 1 ) && (safeboot != boot_info .safeboot )) {
81+ if (safeboot )
82+ {
83+ boot_info .safeboot = (uint32_t )SAFE_BOOT_SW ;
84+ }
85+ else
86+ {
87+ boot_info .safeboot = (uint32_t )0x00 ;
88+ }
89+ update_safeboot = true;
8090 } else {
8191 nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Error safeboot must be True or False!" ));
8292 }
8393 }
8494 if (fs_type < 255 ) {
8595 if (fs_type <= 1 ) {
86- config_set_boot_fs_type (fs_type );
96+ if (config_get_boot_fs_type () != fs_type )
97+ {
98+ config_set_boot_fs_type (fs_type );
99+ update_fstype = true;
100+ }
87101 }
88102 else {
89103 nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Error invalid filesystem type!" ));
90104 }
91105 }
92- if (update_boot ) {
106+ if (update_part || update_safeboot ) {
93107 if (updater_write_boot_info (& boot_info , boot_info_offset ) == false) {
94108 nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Error writing bootloader information!" ));
95109 }
110+ if (update_part )
111+ {
112+ machine_reset ();
113+ }
114+ }
115+ if ((update_fstype || update_safeboot ) && reset )
116+ {
117+ machine_reset ();
96118 }
97119}
98120
@@ -338,7 +360,7 @@ STATIC mp_obj_t mod_pycom_lte_modem_on_boot (mp_uint_t n_args, const mp_obj_t *a
338360STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mod_pycom_lte_modem_on_boot_obj , 0 , 1 , mod_pycom_lte_modem_on_boot );
339361
340362STATIC mp_obj_t mod_pycom_bootmgr (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
341- enum { ARG_boot_partition , ARG_fs_type , ARG_safeboot , ARG_reset };
363+ enum { ARG_boot_partition , ARG_fs_type , ARG_safeboot , ARG_status };
342364 STATIC const mp_arg_t allowed_args [] = {
343365 { MP_QSTR_boot_partition , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 255 } },
344366 { MP_QSTR_fs_type , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 255 } },
@@ -350,7 +372,7 @@ STATIC mp_obj_t mod_pycom_bootmgr (size_t n_args, const mp_obj_t *pos_args, mp_m
350372 mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
351373
352374 if (args [ARG_boot_partition ].u_int == 255 && args [ARG_fs_type ].u_int == 255 && args [ARG_safeboot ].u_int == 255 ) {
353- mp_obj_tuple_t * t = MP_OBJ_TO_PTR (mp_obj_new_tuple (3 , NULL ));
375+ mp_obj_tuple_t * t = MP_OBJ_TO_PTR (mp_obj_new_tuple (4 , NULL ));
354376
355377 if (boot_info .ActiveImg == 0x00 )
356378 {
@@ -372,21 +394,25 @@ STATIC mp_obj_t mod_pycom_bootmgr (size_t n_args, const mp_obj_t *pos_args, mp_m
372394
373395 if (boot_info .safeboot == 0x00 )
374396 {
375- t -> items [ARG_safeboot ] = mp_obj_new_str ("False" , strlen ("False" ));
397+ t -> items [ARG_safeboot ] = mp_obj_new_str ("SafeBoot: False" , strlen ("SafeBoot: False" ));
376398 }
377399 else
378400 {
379- t -> items [ARG_safeboot ] = mp_obj_new_str ("True" , strlen ("True" ));
401+ t -> items [ARG_safeboot ] = mp_obj_new_str ("SafeBoot: True" , strlen ("SafeBoot: True" ));
402+ }
403+ if (boot_info .Status == 0x00 )
404+ {
405+ t -> items [ARG_status ] = mp_obj_new_str ("Status: Check" , strlen ("Status: Check" ));
406+ }
407+ else
408+ {
409+ t -> items [ARG_status ] = mp_obj_new_str ("Status: Ready" , strlen ("Status: Ready" ));
380410 }
381411
382412 return MP_OBJ_FROM_PTR (t );
383413
384414 } else {
385- modpycom_bootmgr (args [ARG_boot_partition ].u_int , args [ARG_fs_type ].u_int , args [ARG_safeboot ].u_int );
386-
387- if (args [ARG_reset ].u_bool == true) {
388- machine_reset ();
389- }
415+ modpycom_bootmgr (args [ARG_boot_partition ].u_int , args [ARG_fs_type ].u_int , args [ARG_safeboot ].u_int , args [3 ].u_bool );
390416 }
391417
392418 return mp_const_none ;
0 commit comments