Skip to content

Commit

Permalink
ayufan: introduce recovery button mode selection
Browse files Browse the repository at this point in the history
Press and hold recovery button to choose suitable boot mode.
When given mode is selected release the button.
Each mode exposes device over USB-OTG and can be connected via USB A-to-A cable

1 blink: share eMMC or SD as virtual disk
2 blinks: enter fastboot (Android's)
3 blinks: enter RockUSB download mode
4 blinks: enter MaskROM download mode

Change-Id: I0ce9e67b51d7959ff2877418c2c9dfd4382de2a4
  • Loading branch information
ayufan committed Jan 3, 2018
1 parent 90db2be commit ea6efec
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
9 changes: 7 additions & 2 deletions arch/arm/dts/rk3328-rock64.dts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
};

adc-keys {
compatible = "adc-keys";
io-channels = <&saradc 0>;
};
};

&saradc {
Expand Down Expand Up @@ -154,11 +159,11 @@
};

led1 {
label = "standby_led";
label = "standby";
};

led2 {
label = "power_led";
label = "power";
};

regulators {
Expand Down
67 changes: 62 additions & 5 deletions arch/arm/mach-rockchip/boot_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,72 @@ __weak int rockchip_dnl_key_pressed(void)
return false;
}

int rockchip_dnl_mode(int num_modes)
{
int mode = 0;

while(mode < num_modes) {
++mode;

printf("rockchip_dnl_mode = %d mode\n", mode);

for (int i = 0; i < mode; ++i) {
cli_simple_run_command("led power off", 0);
mdelay(100);
cli_simple_run_command("led power on", 0);
mdelay(100);
}

// wait 2 seconds
for (int i = 0; i < 100; ++i) {
if (!rockchip_dnl_key_pressed()) {
goto end;
}
mdelay(20);
}
}

end:
cli_simple_run_command("led power off", 0);
cli_simple_run_command("led standby on", 0);
return mode;
}

void rockchip_dnl_mode_check(void)
{
if (rockchip_dnl_key_pressed()) {
printf("download key pressed, entering download mode...\n");
/* If failed, we fall back to bootrom download mode */
if (!rockchip_dnl_key_pressed()) {
return 0;
}

switch(rockchip_dnl_mode(4)) {
case 0:
return;

case 1:
printf("entering ums mode...\n");
cli_simple_run_command("ums 0 mmc 0", 0);
cli_simple_run_command("ums 0 mmc 1", 0);
break;

case 2:
printf("entering fastboot mode...\n");
cli_simple_run_command("mmc dev 0; fastboot usb 0", 0);
cli_simple_run_command("mmc dev 1; fastboot usb 0", 0);
break;

case 3:
printf("entering download mode...\n");
cli_simple_run_command("rockusb 0 mmc 0", 0);
set_back_to_bootrom_dnl_flag();
do_reset(NULL, 0, 0, NULL);
cli_simple_run_command("rockusb 0 mmc 1", 0);
break;

case 4:
printf("entering maskrom mode...\n");
break;
}

set_back_to_bootrom_dnl_flag();
do_reset(NULL, 0, 0, NULL);
}

int setup_boot_mode(void)
Expand Down
1 change: 1 addition & 0 deletions configs/rock64-rk3328_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ CONFIG_SPL_CLK=y
CONFIG_TPL_CLK=y
CONFIG_ROCKCHIP_GPIO=y
CONFIG_SYS_I2C_ROCKCHIP=y
CONFIG_DM_KEY=y
CONFIG_LED=y
CONFIG_MISC=y
CONFIG_ROCKCHIP_EFUSE=y
Expand Down

0 comments on commit ea6efec

Please sign in to comment.