Skip to content

Commit

Permalink
boot_rom tweaks
Browse files Browse the repository at this point in the history
- tweaked ot_logo
- change protocol for compatibility with mainline spiflash
  • Loading branch information
GregAC committed Dec 4, 2019
1 parent 794ccbf commit 12acac9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 59 deletions.
21 changes: 16 additions & 5 deletions sw/device/boot_rom/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,27 @@
extern uint32_t ot_logo[];


// Fills in bit of the progress bar that needs filling for completed frame
// frame_num given total frames frame_total.
//
// Overfills to the left (as it should already have been filled by previous
// frame update) to simplify code.
static void update_oled_progress(uint32_t frame_num, uint32_t frame_total) {
uint32_t cols_per_frame = OLED_BYTE_COLS * 4 / frame_total;
// Multiply by 256 to handle non-integer cols_per_frame
uint32_t cols_per_frame = (OLED_BYTE_COLS * 256) / frame_total;
uint32_t end_cols;

if (frame_num == frame_total - 1) {
end_cols = OLED_BYTE_COLS;
} else {
end_cols = ((frame_num + 1) * cols_per_frame) / 4;
end_cols = ((frame_num + 1) * cols_per_frame) / 256;
}

uint32_t start_cols = ((frame_num * cols_per_frame) >> 4) << 2;
// Want to compute word_col aligned byte_col.
// * >> 8 gives us the byte_col
// * >> 2 gives us the word_col (combine to get >> 10)
// * << 2 gives us the byte_col again round down to word_col boundary
uint32_t start_cols = ((frame_num * cols_per_frame) >> 10) << 2;

for (uint32_t col = start_cols; col < end_cols; col += 4) {
uint32_t xor_mask;
Expand Down Expand Up @@ -92,13 +102,14 @@ static int bootstrap_flash(void) {
for (;;) {
if (spid_bytes_available() >= sizeof(f)) {
spid_read_nb(&f, sizeof(f));
update_oled_progress(f.hdr.frame_num & 0xFFFF, f.hdr.frame_total);
uint32_t frame_total = (f.hdr.frame_num & 0x7FFF0000) >> 16;
update_oled_progress(f.hdr.frame_num & 0xFFFF, frame_total);
uart_send_str("Processing frame no: ");
uart_send_uint(f.hdr.frame_num, 32);
uart_send_str(" exp no: ");
uart_send_uint(expected_frame_no, 32);
uart_send_str(" total no: ");
uart_send_uint(f.hdr.frame_total, 32);
uart_send_uint(frame_total, 32);
uart_send_str("\r\n");

if (FRAME_NO(f.hdr.frame_num) == expected_frame_no) {
Expand Down
4 changes: 1 addition & 3 deletions sw/device/boot_rom/bootstrap_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define RAW_BUFFER_SIZE 1024
#define FRAME_EOF_MARKER 0x80000000
#define FRAME_NO(k) ((k)&0xffffff)
#define FRAME_NO(k) ((k)&0xffff)

typedef struct {
/* SHA2 of the entire frame_t message starting at the |frame_num| offset. */
Expand All @@ -18,8 +18,6 @@ typedef struct {
* FRAME_EOF_MARKER. */
uint32_t frame_num;

uint32_t frame_total;

/* 0-based flash offset where the frame should be written to. */
uint32_t flash_offset;
} frame_hdr_t;
Expand Down
2 changes: 1 addition & 1 deletion sw/device/boot_rom/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ boot_rom_elf = executable(
sw_lib_spi_device,
sw_lib_uart,
sw_lib_log,
sw_lib_oled_display,
sw_lib_oled_display_nofont,
],
)

Expand Down
50 changes: 25 additions & 25 deletions sw/device/boot_rom/ot_logo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ uint32_t ot_logo[] = {
0x00000000,
0x00000000,
0x00000000,
0xc0800000,
0x00000080,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
Expand All @@ -33,9 +33,9 @@ uint32_t ot_logo[] = {
0x00000000,
0x00000000,
0x3f1c1c1c,
0x07073f3f,
0xe0e0e7e7,
0x3f0707e7,
0xf7073f3f,
0xf0f0f7f7,
0x3f07f7f7,
0x1c1c3f3f,
0x0000001c,
0x00000000,
Expand All @@ -52,22 +52,22 @@ uint32_t ot_logo[] = {
0x00f01018,
0xfe181800,
0x181818fe,
0xfbf90000,
0x180000f9,
0x18fefe18,
0x00000018,
0x18187870,
0xf8701818,
0x000000f8,
0x1830f8f8,
0xf0301818,
0x000000e0,
0xfbfb0000,
0x18180000,
0x1818fefe,
0x70000000,
0x18181878,
0xf8f87018,
0xf8000000,
0x181830f8,
0xe0f03018,
0x00000000,
0x00000000,
0x00000000,
0x7e1c1c1c,
0xf0f07e7e,
0x030373f3,
0xfef0f073,
0xf7f07e7e,
0x070777f7,
0xfef0f777,
0x1c1c7e7e,
0x0000001c,
0x00000000,
Expand All @@ -85,15 +85,15 @@ uint32_t ot_logo[] = {
0x07000000,
0x0c0c0c0f,
0x0f0f0000,
0x0000000f,
0x0c0f0700,
0x00000c0c,
0x00000000,
0x0c0c0f07,
0x0f070c0c,
0x0000000f,
0x00000f0f,
0x0700000c,
0x0c0c0c0f,
0x0f0f070c,
0x0f000000,
0x0000000f,
0x0f0f0000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
Expand Down Expand Up @@ -126,5 +126,5 @@ uint32_t ot_logo[] = {
0x00000000,
0x00000000,
0x00000000,
0x00000000
0x00000000,
};
3 changes: 1 addition & 2 deletions sw/device/examples/hello_world/hello_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ int main(int argc, char **argv) {

oled_clear(1);

oled_write_str("RISCV Compliance", 0, 0);
oled_write_str("I-MISALIGN_LDST", 2, 0);
oled_write_str("Hello, World!", 1, 0);

oled_write_disp();

Expand Down
4 changes: 1 addition & 3 deletions sw/host/spiflash/updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ uint32_t Populate(uint32_t frame_number, uint32_t code_offset,
}

// Populate header number, offset and hash.
f->hdr.frame_num = frame_number;
f->hdr.frame_num = (frame_number & 0xFFFF) | ((frame_total & 0xFFFF) << 16);
f->hdr.offset = code_offset;
f->hdr.frame_total = frame_total;
return copy_size;
}

Expand All @@ -45,7 +44,6 @@ void HashFrame(Frame *f) {
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, &f->hdr.frame_num, sizeof(f->hdr.frame_num));
SHA256_Update(&sha256, &f->hdr.frame_total, sizeof(f->hdr.frame_total));
SHA256_Update(&sha256, &f->hdr.offset, sizeof(f->hdr.offset));
SHA256_Update(&sha256, f->data, f->PayloadSize());
SHA256_Final(f->hdr.hash, &sha256);
Expand Down
2 changes: 0 additions & 2 deletions sw/host/spiflash/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ struct Frame {
// Frame number. Starting at 0.
uint32_t frame_num;

uint32_t frame_total;

// Flash target offset.
uint32_t offset;
} hdr;
Expand Down
36 changes: 18 additions & 18 deletions toolchain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,6 @@ has_function_printf = false
# '-Wall',
# '-Werror']

c_args = [
'-fvisibility=hidden',
'-g',
'-mabi=ilp32',
'-march=rv32imc',
'-mcmodel=medany',
'-nostartfiles',
'-nostdlib',
'-mtune=sifive-3-series',
'-falign-functions=16',
'-funroll-all-loops',
'-finline-functions',
'-falign-jumps=4',
'-O3',
'-static',
'-Wall',
'-Werror']
#c_args = [
# '-fvisibility=hidden',
# '-g',
Expand All @@ -78,10 +61,27 @@ c_args = [
# '-mcmodel=medany',
# '-nostartfiles',
# '-nostdlib',
# '-Os',
# '-mtune=sifive-3-series',
# '-falign-functions=16',
# '-funroll-all-loops',
# '-finline-functions',
# '-falign-jumps=4',
# '-O3',
# '-static',
# '-Wall',
# '-Werror']
c_args = [
'-fvisibility=hidden',
'-g',
'-mabi=ilp32',
'-march=rv32imc',
'-mcmodel=medany',
'-nostartfiles',
'-nostdlib',
'-Os',
'-static',
'-Wall',
'-Werror']
c_link_args = ['-nostdlib']

[build_machine]
Expand Down

0 comments on commit 12acac9

Please sign in to comment.