Skip to content

Commit

Permalink
sim, bootloader: setup & Handle bootmode properly
Browse files Browse the repository at this point in the history
- in hsoc target:sim option reduces led blink delay
- sim: add bootmode cli option in hsoc backend
  • Loading branch information
saursin committed Oct 20, 2023
1 parent cd916a6 commit 6920f5d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test: sim lib ## Test the build using banner example
.PHONY : boot
boot: lib ## Build bootloader for given target [default: atombones]
@printf "$(CLR_GR)>> Building bootloader [soctarget:$(soctarget)] $(CLR_NC)\n"
make $(MKFLAGS) -C $(bootloader_dir) soctarget=$(soctarget)
make $(MKFLAGS) -C $(bootloader_dir) soctarget=$(soctarget) sim=true


.PHONY: clean-boot
Expand Down
5 changes: 5 additions & 0 deletions sim/backend_hydrogensoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#define BBUART_FRATIO 3

#define BOOTMODE_PIN_OFFSET 8

Backend_atomsim::Backend_atomsim(Atomsim *sim, Backend_config config) : Backend(sim, &(sim->simstate_)),
config_(config),
using_vuart_(config.vuart_portname != "")
Expand Down Expand Up @@ -161,6 +163,9 @@ int Backend_atomsim::tick()
return 1;
}

// Force the bootmode switch value
tb->m_core->gpio_io = (0b11 & config_.bootmode) << BOOTMODE_PIN_OFFSET;

// perform uart transaction (if any)
UART();

Expand Down
1 change: 1 addition & 0 deletions sim/backend_hydrogensoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Backend_config
std::string vuart_portname = "";
uint32_t vuart_baudrate = 115200;
bool enable_uart_dump = false;
int bootmode = 1; // Jump to RAM
};


Expand Down
4 changes: 4 additions & 0 deletions sim/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ void parse_commandline_args(int argc, char**argv, Atomsim_config &sim_config, Ba
("bootrom-image", "Specify bootrom hex image", cxxopts::value<std::string>(backend_config.bootrom_img)->default_value(default_backend_config.bootrom_img))
("ram-size", "Specify size of RAM memory to simulate (in KB)", cxxopts::value<uint32_t>(backend_config.ram_size_kb)->default_value(std::to_string(default_backend_config.ram_size_kb)))
#endif

#ifdef TARGET_HYDROGENSOC
("bootmode", "Specify bootmode signal", cxxopts::value<int>(backend_config.bootmode)->default_value(std::to_string(default_backend_config.bootmode)))
#endif
;

options.add_options("Debug")
Expand Down
7 changes: 7 additions & 0 deletions sw/bootloader/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
EXEC:= bootloader

sim ?= false

RVPREFIX:= riscv64-unknown-elf

CFLAGS:= -mabi=ilp32 -march=rv32i -nostartfiles -ffreestanding -Os
Expand All @@ -9,6 +11,11 @@ LFLAGS:= -L $(RVATOM_LIB)/ -T $(RVATOM_LIB)/link/link_bootloader.ld -lcatom -Xli

CONVELF_ARGS:= -t elf -c

ifeq ($(sim), true)
CFLAGS+= -DSIM
endif


ifeq ($(MAKECMDGOALS),clean)
else
ifeq ($(soctarget), atombones)
Expand Down
20 changes: 16 additions & 4 deletions sw/bootloader/hydrogensoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ extern uint32_t __approm_size;
*/
void led_blink(int pin, int count, int time_period)
{
int halfperiod = time_period >> 1;
#ifdef SIM
halfperiod = 0;
#endif

for(int i=0; i<count; i++)
{
gpio_write(pin, HIGH);
sleep_ms(time_period >> 1);
sleep_ms(halfperiod);
gpio_write(pin, LOW);
sleep_ms(time_period >> 1);
sleep_ms(halfperiod);
}
}

Expand All @@ -67,8 +72,15 @@ void * platform_init() {
led_blink(BOOTLED_PIN, START_LED_FLASHES, 50);

// get bootmode
uint8_t bootmode = (uint8_t)gpio_read(BOOTMODE_PIN0)
| (((uint8_t)gpio_read(BOOTMODE_PIN1)) << 1);
uint8_t pin0_val = (uint8_t)gpio_read(BOOTMODE_PIN0);
uint8_t pin1_val = (uint8_t)gpio_read(BOOTMODE_PIN1);
uint8_t bootmode = pin0_val | pin1_val << 1;

// Print Bootmode
P(putchar('0'+pin0_val);)
P(putchar('0'+pin1_val);)
P(putchar(':');)

/**
* Bootmode:
* 0b00: flashboot
Expand Down

0 comments on commit 6920f5d

Please sign in to comment.