Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toerb
flow3r firmware
Commits
14f92377
Commit
14f92377
authored
1 year ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
recovery: select image for writing
parent
c4e9c913
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
recovery/main/rec_main.c
+31
-26
31 additions, 26 deletions
recovery/main/rec_main.c
with
31 additions
and
26 deletions
recovery/main/rec_main.c
+
31
−
26
View file @
14f92377
...
@@ -34,6 +34,12 @@ static menu_t _erasedone_menu;
...
@@ -34,6 +34,12 @@ static menu_t _erasedone_menu;
static
menu_entry_t
_list_menu_entries
[];
static
menu_entry_t
_list_menu_entries
[];
static
bool
_usb_initialized
=
false
;
static
bool
_usb_initialized
=
false
;
typedef
struct
{
char
path
[
64
];
char
label
[
64
];
}
image_entry_t
;
static
image_entry_t
image_list
[
64
];
static
void
_main_reboot
(
void
)
{
esp_restart
();
}
static
void
_main_reboot
(
void
)
{
esp_restart
();
}
...
@@ -89,26 +95,24 @@ static void _list_exit(void) {
...
@@ -89,26 +95,24 @@ static void _list_exit(void) {
}
}
static
void
_list_select
(
void
)
{
static
void
_list_select
(
void
)
{
// TODO: copy selected image over to app partition
_cur_menu
=
&
_main_menu
;
_cur_menu
->
selected
=
0
;
// app, app, ota_0, 0x90000, 0x300000,
// app, app, ota_0, 0x90000, 0x300000,
const
esp_partition_t
*
p
=
esp_partition_find_first
(
const
esp_partition_t
*
p
=
esp_partition_find_first
(
ESP_PARTITION_TYPE_APP
,
ESP_PARTITION_SUBTYPE_APP_OTA_0
,
"app"
);
ESP_PARTITION_TYPE_APP
,
ESP_PARTITION_SUBTYPE_APP_OTA_0
,
"app"
);
if
(
p
==
NULL
)
{
if
(
p
==
NULL
)
{
ESP_LOGE
(
TAG
,
"app partition not found"
);
rec_fatal
(
"App partition not found"
);
return
;
}
}
printf
(
"erase size: %lu
\n
"
,
p
->
erase_size
);
uint8_t
buf
[
p
->
erase_size
];
// Erase size of internal flash is 4096
uint8_t
buf
[
p
->
erase_size
];
size_t
n
;
size_t
n
;
size_t
offset
=
0
;
size_t
offset
=
0
;
char
path
[
128
]
=
"/flash/hello.bin"
;
ESP_LOGI
(
TAG
,
"Opening %s"
,
image_list
[
_cur_menu
->
selected
].
path
);
FILE
*
f
=
fopen
(
path
,
"rb"
);
FILE
*
f
=
fopen
(
image_list
[
_cur_menu
->
selected
].
path
,
"rb"
);
if
(
f
==
NULL
)
{
ESP_LOGW
(
TAG
,
"fopen failed: %s"
,
strerror
(
errno
));
rec_fatal
(
"Could not open file :("
);
}
do
{
do
{
n
=
fread
(
buf
,
1
,
sizeof
(
buf
),
f
);
n
=
fread
(
buf
,
1
,
sizeof
(
buf
),
f
);
...
@@ -116,11 +120,14 @@ static void _list_select(void) {
...
@@ -116,11 +120,14 @@ static void _list_select(void) {
esp_partition_erase_range
(
p
,
offset
,
sizeof
(
buf
));
esp_partition_erase_range
(
p
,
offset
,
sizeof
(
buf
));
esp_partition_write
(
p
,
offset
,
buf
,
n
);
esp_partition_write
(
p
,
offset
,
buf
,
n
);
offset
+=
n
;
offset
+=
n
;
printf
(
"wrote %u bytes
\n
"
,
offset
);
ESP_LOGI
(
TAG
,
"wrote %u bytes"
,
offset
);
}
}
}
while
(
n
==
sizeof
(
buf
));
}
while
(
n
==
sizeof
(
buf
));
fclose
(
f
);
fclose
(
f
);
_cur_menu
=
&
_main_menu
;
_cur_menu
->
selected
=
0
;
}
}
typedef
struct
{
typedef
struct
{
...
@@ -133,15 +140,15 @@ static void _main_list(void) {
...
@@ -133,15 +140,15 @@ static void _main_list(void) {
_cur_menu
=
&
_list_menu
;
_cur_menu
=
&
_list_menu
;
_cur_menu
->
selected
=
0
;
_cur_menu
->
selected
=
0
;
int
entr
ies
=
1
;
int
entr
y
=
1
;
struct
dirent
*
pDirent
;
struct
dirent
*
pDirent
;
DIR
*
pDir
;
DIR
*
pDir
;
// TODO: also consider the SD card
// TODO
(schneider)
: also consider the SD card
pDir
=
opendir
(
"/flash"
);
pDir
=
opendir
(
"/flash"
);
if
(
pDir
!=
NULL
)
{
if
(
pDir
!=
NULL
)
{
while
(((
pDirent
=
readdir
(
pDir
))
!=
NULL
)
&&
(
entr
ies
<
64
))
{
while
(((
pDirent
=
readdir
(
pDir
))
!=
NULL
)
&&
(
entr
y
<
64
))
{
ESP_LOGI
(
TAG
,
"Checking header of %s"
,
pDirent
->
d_name
);
ESP_LOGI
(
TAG
,
"Checking header of %s"
,
pDirent
->
d_name
);
char
*
s
=
pDirent
->
d_name
;
char
*
s
=
pDirent
->
d_name
;
...
@@ -150,7 +157,7 @@ static void _main_list(void) {
...
@@ -150,7 +157,7 @@ static void _main_list(void) {
if
(
l
>
4
&&
strcmp
(
".bin"
,
&
s
[
l
-
4
])
==
0
)
{
if
(
l
>
4
&&
strcmp
(
".bin"
,
&
s
[
l
-
4
])
==
0
)
{
esp32_standard_header_t
hdr
;
esp32_standard_header_t
hdr
;
char
path
[
128
];
char
path
[
64
];
snprintf
(
path
,
sizeof
(
path
)
/
sizeof
(
char
),
"/flash/%s"
,
snprintf
(
path
,
sizeof
(
path
)
/
sizeof
(
char
),
"/flash/%s"
,
pDirent
->
d_name
);
pDirent
->
d_name
);
FILE
*
f
=
fopen
(
path
,
"rb"
);
FILE
*
f
=
fopen
(
path
,
"rb"
);
...
@@ -172,23 +179,21 @@ static void _main_list(void) {
...
@@ -172,23 +179,21 @@ static void _main_list(void) {
continue
;
continue
;
}
}
// TODO have this in a global list, so the select function
image_entry_t
*
ie
=
&
image_list
[
entry
];
// can get the actual path
snprintf
(
ie
->
label
,
sizeof
(
ie
->
label
),
"%s: %s"
,
size_t
n
=
strlen
(
pDirent
->
d_name
)
+
2
+
pDirent
->
d_name
,
hdr
.
app
.
project_name
);
strlen
(
hdr
.
app
.
project_name
)
+
1
;
snprintf
(
ie
->
path
,
sizeof
(
ie
->
path
),
"%s"
,
path
);
char
*
label
=
malloc
(
n
);
snprintf
(
label
,
n
,
"%s: %s"
,
pDirent
->
d_name
,
_list_menu_entries
[
entry
].
label
=
ie
->
label
;
hdr
.
app
.
project_name
);
_list_menu_entries
[
entry
].
enter
=
_list_select
;
_list_menu_entries
[
entries
].
label
=
label
;
entry
++
;
_list_menu_entries
[
entries
].
enter
=
_list_select
;
entries
++
;
}
}
}
}
closedir
(
pDir
);
closedir
(
pDir
);
}
else
{
}
else
{
ESP_LOGE
(
TAG
,
"Opening /flash failed"
);
ESP_LOGE
(
TAG
,
"Opening /flash failed"
);
}
}
_list_menu
.
entries_count
=
entr
ies
;
_list_menu
.
entries_count
=
entr
y
;
}
}
static
menu_entry_t
_main_menu_entries
[]
=
{
static
menu_entry_t
_main_menu_entries
[]
=
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment