25
25
26
26
// SimpleApp.bin gets loaded into ram between these addresses.
27
27
// See CMakeLists.txt for details on how this is done.
28
- extern " C" uint8_t _binary_SimpleApp_bin_start ;
29
- extern " C" uint8_t _binary_SimpleApp_bin_end ;
30
- const size_t SimpleApp_bin_length = &_binary_SimpleApp_bin_end - &_binary_SimpleApp_bin_start ;
28
+ extern " C" uint8_t _binary_SimpleApp_update_image_bin_start ;
29
+ extern " C" uint8_t _binary_SimpleApp_update_image_bin_end ;
30
+ const size_t SimpleApp_update_image_bin_length = &_binary_SimpleApp_update_image_bin_end - &_binary_SimpleApp_update_image_bin_start ;
31
31
32
32
int main ()
33
33
{
@@ -37,6 +37,16 @@ int main()
37
37
38
38
DigitalIn btn (DEMO_BUTTON);
39
39
40
+ // Use a buffered block device to allow arbitrary length writes to the underlying BD
41
+ BlockDevice *secondary_bd = get_secondary_bd ();
42
+ BufferedBlockDevice bufferedSecBD (secondary_bd);
43
+ int ret = bufferedSecBD.init ();
44
+ if (ret == 0 ) {
45
+ tr_info (" Secondary BlockDevice inited" );
46
+ } else {
47
+ tr_error (" Cannot init secondary BlockDevice: %d" , ret);
48
+ }
49
+
40
50
// Erase secondary slot
41
51
// On the first boot, the secondary BlockDevice needs to be clean
42
52
// If the first boot is not normal, please run the erase step, then reboot
@@ -47,17 +57,6 @@ int main()
47
57
ThisThread::sleep_for (10ms);
48
58
}
49
59
50
- BlockDevice *secondary_bd = get_secondary_bd ();
51
- int ret = secondary_bd->init ();
52
- if (ret == 0 ) {
53
- tr_info (" Secondary BlockDevice inited" );
54
- } else {
55
- tr_error (" Cannot init secondary BlockDevice: %d" , ret);
56
- }
57
-
58
- // Use a buffered block device to allow arbitrary length writes to the underlying BD
59
- BufferedBlockDevice bufferedSecBD (secondary_bd);
60
-
61
60
tr_info (" Erasing secondary BlockDevice..." );
62
61
ret = bufferedSecBD.erase (0 , bufferedSecBD.size ());
63
62
if (ret == 0 ) {
@@ -73,7 +72,7 @@ int main()
73
72
}
74
73
75
74
// Copy the update image from internal flash to secondary BlockDevice
76
- bufferedSecBD.program (&_binary_SimpleApp_bin_start , 0 , SimpleApp_bin_length );
75
+ bufferedSecBD.program (&_binary_SimpleApp_update_image_bin_start , 0 , SimpleApp_update_image_bin_length );
77
76
78
77
// Activate the image in the secondary BlockDevice
79
78
tr_info (" > Image copied to secondary BlockDevice, press button to activate" );
0 commit comments