Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kestrel Collaboration
Kestrel Firmware
Zephyr Firmware
Commits
0313fee2
Commit
0313fee2
authored
3 years ago
by
Raptor Engineering Development Team
Browse files
Options
Download
Email Patches
Plain Diff
Add BMC/Flash firmware write support
parent
76bcf0b0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
2 deletions
+68
-2
kestrel/src/flash_filesystem.c
kestrel/src/flash_filesystem.c
+54
-0
kestrel/src/flash_filesystem.h
kestrel/src/flash_filesystem.h
+2
-0
kestrel/src/shell.c
kestrel/src/shell.c
+8
-1
kestrel/src/webservice.c
kestrel/src/webservice.c
+4
-1
No files found.
kestrel/src/flash_filesystem.c
View file @
0313fee2
...
...
@@ -12,14 +12,19 @@ LOG_MODULE_REGISTER(flash_filesystem, LOG_LEVEL_DBG);
#include <ctype.h>
#include <zephyr.h>
#include <device.h>
#include <sys/crc.h>
#include <fs/fs.h>
#include <fs/littlefs.h>
#include <drivers/flash.h>
#include <storage/flash_map.h>
#define WITH_ZEPHYR 1
#include "kestrel.h"
extern
const
struct
flash_area
*
flash_map
;
extern
const
int
flash_map_entries
;
// Matches LFS_NAME_MAX */
#define MAX_PATH_LEN 255
...
...
@@ -103,3 +108,52 @@ fail:
return
-
1
;
}
int
write_firmware_to_flash
(
const
char
*
device_name
,
int
partition_number
,
const
uint8_t
*
data
,
size_t
length
,
int
add_litex_header
)
{
static
struct
flash_area
const
*
flash_area
;
int
result
;
// Find BMC firmware Flash map area
flash_area
=
NULL
;
for
(
int
i
=
0
;
i
<
flash_map_entries
;
i
++
)
{
if
(
strcmp
(
flash_map
[
i
].
fa_dev_name
,
"bmc"
)
==
0
)
{
if
(
flash_map
[
i
].
fa_id
==
partition_number
)
{
flash_area
=
&
flash_map
[
i
];
break
;
}
}
}
if
(
!
flash_area
)
{
return
-
ENODEV
;
}
if
(
length
>
flash_area
->
fa_size
)
{
length
=
flash_area
->
fa_size
;
}
LOG_INF
(
"Erasing %s firmware partition %d..."
,
device_name
,
partition_number
);
result
=
flash_area_erase
(
flash_area
,
0x0
,
flash_area
->
fa_size
);
if
(
result
<
0
)
{
LOG_INF
(
"Erase failed!"
);
return
result
;
}
LOG_INF
(
"Writing %s firmware partition %d..."
,
device_name
,
partition_number
);
if
(
add_litex_header
)
{
result
=
flash_area_write
(
flash_area
,
0x0
,
&
length
,
4
);
if
(
!
result
)
{
uint32_t
crc
=
crc32_ieee
(
data
,
length
);
result
=
flash_area_write
(
flash_area
,
0x4
,
&
crc
,
4
);
}
}
if
(
!
result
)
{
result
=
flash_area_write
(
flash_area
,
(
add_litex_header
)
?
0x8
:
0x0
,
data
,
length
);
}
if
(
result
<
0
)
{
LOG_INF
(
"Write failed!"
);
return
result
;
}
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
kestrel/src/flash_filesystem.h
View file @
0313fee2
...
...
@@ -8,4 +8,6 @@
int
initialize_flash_filesystem
(
void
);
int
write_firmware_to_flash
(
const
char
*
device_name
,
int
partition_number
,
const
uint8_t
*
data
,
size_t
length
,
int
add_litex_header
);
#endif // _FLASH_FILESYSTEM_H
\ No newline at end of file
This diff is collapsed.
Click to expand it.
kestrel/src/shell.c
View file @
0313fee2
...
...
@@ -12,6 +12,7 @@
#define WITH_ZEPHYR 1
#include "kestrel.h"
#include "flash_filesystem.h"
#define KESTREL_CONSOLE_THREAD_PRIORITY K_PRIO_PREEMPT(CONFIG_NUM_PREEMPT_PRIORITIES - 1)
static
K_THREAD_STACK_DEFINE
(
kestrel_console_thread_stack
,
16384
);
...
...
@@ -94,7 +95,7 @@ static void print_kestrel_utility_command_usage(const struct shell *shell, char*
}
static
void
print_kestrel_reflash_command_usage
(
const
struct
shell
*
shell
,
char
*
command_name
)
{
shell_print
(
shell
,
"Usage: %s <pnor>"
,
command_name
);
shell_print
(
shell
,
"Usage: %s <
fpga bmc
pnor>"
,
command_name
);
}
static
void
print_kestrel_memdump_command_usage
(
const
struct
shell
*
shell
,
char
*
command_name
)
{
...
...
@@ -138,6 +139,12 @@ static int kestrel_shell_cmd_reflash(const struct shell *shell, size_t argc, cha
return
write_flash_buffer_to_flash
();
}
else
if
(
strcmp
(
argv
[
1
],
"bmc"
)
==
0
)
{
return
write_firmware_to_flash
(
"bmc"
,
1
,
main_firmware_buffer
.
buffer_address
,
main_firmware_buffer
.
valid_bytes
,
1
);
}
else
if
(
strcmp
(
argv
[
1
],
"fpga"
)
==
0
)
{
return
write_firmware_to_flash
(
"bmc"
,
0
,
main_firmware_buffer
.
buffer_address
,
main_firmware_buffer
.
valid_bytes
,
0
);
}
else
{
shell_print
(
shell
,
"%s: Invalid parameter"
,
argv
[
0
]);
print_kestrel_reflash_command_usage
(
shell
,
argv
[
0
]);
...
...
This diff is collapsed.
Click to expand it.
kestrel/src/webservice.c
View file @
0313fee2
...
...
@@ -152,7 +152,7 @@ int firmware_upload_form_handler(struct mg_connection *conn, void *cbdata)
"enctype=
\"
multipart/form-data
\"
>
\n
"
,
(
const
char
*
)
cbdata
);
mg_printf
(
conn
,
"<input type=
\"
file
\"
name=
\"
firmwarefile
\"
multiple>
\n
"
);
mg_printf
(
conn
,
"<input type=
\"
submit
\"
value=
\"
Submit
\"
>
\n
"
);
mg_printf
(
conn
,
"<input type=
\"
submit
\"
value=
\"
Upload
\"
>
\n
"
);
mg_printf
(
conn
,
"</form>
\n
"
);
SEND_STANDARD_FOOTER
(
conn
);
...
...
@@ -213,6 +213,9 @@ int firmware_upload_handler(struct mg_connection *conn, void *cbdata)
/* Call the form handler */
ret
=
mg_handle_form_request
(
conn
,
&
fdh
);
// Clear out the remainder of the buffer
memset
(
main_firmware_buffer
.
buffer_address
+
main_firmware_buffer
.
valid_bytes
,
0xff
,
main_firmware_buffer
.
buffer_length
-
main_firmware_buffer
.
valid_bytes
);
main_firmware_buffer
.
locked
=
0
;
mg_printf
(
conn
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment