Skip to content

Commit

Permalink
feat: boot original firmwares with default for the board layout
Browse files Browse the repository at this point in the history
Support Ritmix boards at the moment.
  • Loading branch information
volkau-siarhei committed Aug 30, 2022
1 parent cbfddfa commit 46d0fcd
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config-rzx27.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ BOARD := rzx27
VARIANTS := mmc
JZ_VERSION = 4725

CFLAGS_all := -mips32
CFLAGS_all := -mips32 -DTRY_ORIGINAL_FIRMWARE
CFLAGS_mmc := -DHAVE_MBR
2 changes: 1 addition & 1 deletion config-rzx50.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ BOARD := rzx50
VARIANTS := mmc
JZ_VERSION = 4755

CFLAGS_all := -mips32
CFLAGS_all := -mips32 -DTRY_ORIGINAL_FIRMWARE
CFLAGS_mmc := -DHAVE_MBR
25 changes: 25 additions & 0 deletions src/board-rzx27.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,28 @@ void nand_init(void)
(EMC_STRV << EMC_SMCR_STRV_BIT);
}
#endif

void original_firmware_load(void)
{
// internal MSC0 shall be initialized first
// original firmware is at 256kiB offset on SD card.
// shall be loaded at 0x00800000 offset in RAM

const uint32_t load_addr = 0x00800000;
// load 1MiB bytes into RAM from 512 blocks (256kiB) offset on SD card.
if (!mmc_block_read(0, (void *) (KSEG1 + load_addr), 512, 2048)) {

SERIAL_PUTS("Trying original RZX-27 firmware from internal SD.\n");

// TODO check that loaded data not a crap
// reset the LCD controller for proper reintialization
__gpio_clear_pin(GPIOD, 21);
udelay(1000);
__gpio_set_pin(GPIOD, 21);

// jump into firmware
void (*entry)(void) = (void (*)(void))(KSEG1 + load_addr);
entry();
while (1);
}
}
37 changes: 37 additions & 0 deletions src/board-rzx50.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,40 @@ void nand_init(void)
(EMC_STRV << EMC_SMCR_STRV_BIT);
}
#endif

#define USB_BASE 0xB3040000

#define REG_USB_FADDR REG8(USB_BASE + 0x00) /* Function Address 8-bit */
#define REG_USB_POWER REG8(USB_BASE + 0x01) /* Power Managemetn 8-bit */

void original_firmware_load(void)
{
// internal MSC0 shall be initialized first
// original u-boot is at 16kiB offset on SD card.
// shall be loaded at 0x00100000 offset in RAM
// loading up to 1MiB is sufficient

const uint32_t load_addr = 0x00100000;
const uint32_t entry_offset = 0x200;

SERIAL_PUTS("Trying original RZX-50 firmware from internal SD.\n");

if (!mmc_block_read(0, (void *) (KSEG1 + load_addr), 32, 2048-32)) {
uint32_t cmd_1st = *(uint32_t*)(KSEG1 + load_addr + entry_offset);

// first uboot command is always `bal 1f` => 0x04110002 in hex
if (cmd_1st != 0x04110002) {
SERIAL_PUTS("Unexpected content, booting might fail.\n");
}

/* reset USB to defaults, otherwise it won't work in original kernel.
* starting UBIBoot over USB case */
REG_USB_POWER = 0x20;
REG_USB_FADDR = 0x80;

void (*entry)(void) = (void (*)(void))(KSEG1 + load_addr + entry_offset);
entry();
while (1);
}
SERIAL_PUTS("Can't read firmware from SD.\n");
}
4 changes: 4 additions & 0 deletions src/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ unsigned int get_memory_size(void);
void nand_init(void);
void nand_wait_ready(void);

#ifdef TRY_ORIGINAL_FIRMWARE
void original_firmware_load(void);
#endif

#endif

9 changes: 9 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ void c_main(void)
}
}

#ifdef TRY_ORIGINAL_FIRMWARE
if (!exec_addr) {
for (unsigned i = 0; i < MMCS_COUNT; i++) {
/* MMC0 is internal usually on dual-MMC devices */
if (mmc_ids[i] == 0 && mmc_inited[i])
original_firmware_load();
}
}
#endif
if (!exec_addr) {
SERIAL_PUTS("Unable to boot from SD."
#ifdef USE_NAND
Expand Down

0 comments on commit 46d0fcd

Please sign in to comment.