static int do_vbexport_test_key(cmd_tbl_t *cmdtp, int flag,
		int argc, char * const argv[])
{
	int ret = 0;
	uint32_t c = 0;

	VbExDebug("Press any key for test. Press Ctrl-C to exit...\n");
	while (c != KEY_CTRL_C) {
		c = VbExKeyboardRead();
		if (c)
			VbExDebug("Key pressed: 0x%02x\n", c);
	}

	return ret;
}
Пример #2
0
VbError_t VbBootRecovery(VbCommonParams *cparams, LoadKernelParams *p)
{
    VbSharedDataHeader *shared =
        (VbSharedDataHeader *)cparams->shared_data_blob;
    uint32_t retval;
    uint32_t key;
    int i;

    VBDEBUG(("VbBootRecovery() start\n"));

    /*
     * If the dev-mode switch is off and the user didn't press the recovery
     * button, require removal of all external media.
     */
    if (!(shared->flags & VBSD_BOOT_DEV_SWITCH_ON) &&
            !(shared->flags & VBSD_BOOT_REC_SWITCH_ON)) {
        VbDiskInfo *disk_info = NULL;
        uint32_t disk_count = 0;

        VBDEBUG(("VbBootRecovery() forcing device removal\n"));

        /* If no media is detected initially, delay and make one extra
         * attempt, in case devices appear later than expected. */
        if (VBERROR_SUCCESS != VbExDiskGetInfo(&disk_info, &disk_count,
                                               VB_DISK_FLAG_REMOVABLE))
            disk_count = 0;

        VbExDiskFreeInfo(disk_info, NULL);
        if (0 == disk_count)
            VbExSleepMs(REC_MEDIA_INIT_DELAY);

        while (1) {
            disk_info = NULL;
            disk_count = 0;
            if (VBERROR_SUCCESS !=
                    VbExDiskGetInfo(&disk_info, &disk_count,
                                    VB_DISK_FLAG_REMOVABLE))
                disk_count = 0;

            VbExDiskFreeInfo(disk_info, NULL);

            if (0 == disk_count) {
                VbDisplayScreen(cparams, VB_SCREEN_BLANK,
                                0, &vnc);
                break;
            }

            VBDEBUG(("VbBootRecovery() "
                     "waiting for %d disks to be removed\n",
                     (int)disk_count));

            VbDisplayScreen(cparams, VB_SCREEN_RECOVERY_REMOVE,
                            0, &vnc);

            /*
             * Scan keyboard more frequently than media, since x86
             * platforms don't like to scan USB too rapidly.
             */
            for (i = 0; i < REC_DISK_DELAY; i += REC_KEY_DELAY) {
                VbCheckDisplayKey(cparams, VbExKeyboardRead(),
                                  &vnc);
                if (VbWantShutdown(cparams->gbb->flags))
                    return VBERROR_SHUTDOWN_REQUESTED;
                VbExSleepMs(REC_KEY_DELAY);
            }
        }
    }

    /* Loop and wait for a recovery image */
    while (1) {
        VBDEBUG(("VbBootRecovery() attempting to load kernel2\n"));
        retval = VbTryLoadKernel(cparams, p, VB_DISK_FLAG_REMOVABLE);

        /*
         * Clear recovery requests from failed kernel loading, since
         * we're already in recovery mode.  Do this now, so that
         * powering off after inserting an invalid disk doesn't leave
         * us stuck in recovery mode.
         */
        VbSetRecoveryRequest(VBNV_RECOVERY_NOT_REQUESTED);

        if (VBERROR_SUCCESS == retval)
            break; /* Found a recovery kernel */

        VbDisplayScreen(cparams, VBERROR_NO_DISK_FOUND == retval ?
                        VB_SCREEN_RECOVERY_INSERT :
                        VB_SCREEN_RECOVERY_NO_GOOD,
                        0, &vnc);

        /*
         * Scan keyboard more frequently than media, since x86
         * platforms don't like to scan USB too rapidly.
         */
        for (i = 0; i < REC_DISK_DELAY; i += REC_KEY_DELAY) {
            key = VbExKeyboardRead();
            /*
             * We might want to enter dev-mode from the Insert
             * screen if all of the following are true:
             *   - user pressed Ctrl-D
             *   - we can honor the virtual dev switch
             *   - not already in dev mode
             *   - user forced recovery mode
             *   - EC isn't pwned
             */
            if (key == 0x04 &&
                    shared->flags & VBSD_HONOR_VIRT_DEV_SWITCH &&
                    !(shared->flags & VBSD_BOOT_DEV_SWITCH_ON) &&
                    (shared->flags & VBSD_BOOT_REC_SWITCH_ON) &&
                    VbExTrustEC(0)) {
                if (!(shared->flags &
                        VBSD_BOOT_REC_SWITCH_VIRTUAL) &&
                        VbExGetSwitches(
                            VB_INIT_FLAG_REC_BUTTON_PRESSED)) {
                    /*
                     * Is the recovery button stuck?  In
                     * any case we don't like this.  Beep
                     * and ignore.
                     */
                    VBDEBUG(("%s() - ^D but rec switch "
                             "is pressed\n", __func__));
                    VbExBeep(120, 400);
                    continue;
                }

                /* Ask the user to confirm entering dev-mode */
                VbDisplayScreen(cparams,
                                VB_SCREEN_RECOVERY_TO_DEV,
                                0, &vnc);
                /* SPACE means no... */
                uint32_t vbc_flags =
                    VB_CONFIRM_SPACE_MEANS_NO |
                    VB_CONFIRM_MUST_TRUST_KEYBOARD;
                switch (VbUserConfirms(cparams, vbc_flags)) {
                case 1:
                    VBDEBUG(("%s() Enabling dev-mode...\n",
                             __func__));
                    if (TPM_SUCCESS != SetVirtualDevMode(1))
                        return VBERROR_TPM_SET_BOOT_MODE_STATE;
                    VBDEBUG(("%s() Reboot so it will take "
                             "effect\n", __func__));
                    if (VbExGetSwitches
                            (VB_INIT_FLAG_ALLOW_USB_BOOT))
                        VbAllowUsbBoot();
                    return VBERROR_TPM_REBOOT_REQUIRED;
                case -1:
                    VBDEBUG(("%s() - Shutdown requested\n",
                             __func__));
                    return VBERROR_SHUTDOWN_REQUESTED;
                default: /* zero, actually */
                    VBDEBUG(("%s() - Not enabling "
                             "dev-mode\n", __func__));
                    /*
                     * Jump out of the outer loop to
                     * refresh the display quickly.
                     */
                    i = 4;
                    break;
                }
            } else {
                VbCheckDisplayKey(cparams, key, &vnc);
            }
            if (VbWantShutdown(cparams->gbb->flags))
                return VBERROR_SHUTDOWN_REQUESTED;
            VbExSleepMs(REC_KEY_DELAY);
        }
    }

    return VBERROR_SUCCESS;
}
Пример #3
0
VbError_t VbBootDeveloper(VbCommonParams *cparams, LoadKernelParams *p)
{
    GoogleBinaryBlockHeader *gbb = cparams->gbb;
    VbSharedDataHeader *shared =
        (VbSharedDataHeader *)cparams->shared_data_blob;
    uint32_t allow_usb = 0, allow_legacy = 0, ctrl_d_pressed = 0;
    VbAudioContext *audio = 0;

    VBDEBUG(("Entering %s()\n", __func__));

    /* Check if USB booting is allowed */
    VbNvGet(&vnc, VBNV_DEV_BOOT_USB, &allow_usb);
    VbNvGet(&vnc, VBNV_DEV_BOOT_LEGACY, &allow_legacy);

    /* Handle GBB flag override */
    if (gbb->flags & GBB_FLAG_FORCE_DEV_BOOT_USB)
        allow_usb = 1;
    if (gbb->flags & GBB_FLAG_FORCE_DEV_BOOT_LEGACY)
        allow_legacy = 1;

    /* Show the dev mode warning screen */
    VbDisplayScreen(cparams, VB_SCREEN_DEVELOPER_WARNING, 0, &vnc);

    /* Get audio/delay context */
    audio = VbAudioOpen(cparams);

    /* We'll loop until we finish the delay or are interrupted */
    do {
        uint32_t key;

        if (VbWantShutdown(gbb->flags)) {
            VBDEBUG(("VbBootDeveloper() - shutdown requested!\n"));
            VbAudioClose(audio);
            return VBERROR_SHUTDOWN_REQUESTED;
        }

        key = VbExKeyboardRead();
        switch (key) {
        case 0:
            /* nothing pressed */
            break;
        case '\r':
            /* Only disable virtual dev switch if allowed by GBB */
            if (!(gbb->flags & GBB_FLAG_ENTER_TRIGGERS_TONORM))
                break;
        case ' ':
            /* See if we should disable virtual dev-mode switch. */
            VBDEBUG(("%s shared->flags=0x%x\n",
                     __func__, shared->flags));
            if (shared->flags & VBSD_HONOR_VIRT_DEV_SWITCH &&
                    shared->flags & VBSD_BOOT_DEV_SWITCH_ON) {
                /* Stop the countdown while we go ask... */
                VbAudioClose(audio);
                if (gbb->flags & GBB_FLAG_FORCE_DEV_SWITCH_ON) {
                    /*
                     * TONORM won't work (only for
                     * non-shipping devices).
                     */
                    VBDEBUG(("%s() - TONORM rejected by "
                             "FORCE_DEV_SWITCH_ON\n",
                             __func__));
                    VbExDisplayDebugInfo(
                        "WARNING: TONORM prohibited by "
                        "GBB FORCE_DEV_SWITCH_ON.\n\n");
                    VbExBeep(120, 400);
                    break;
                }
                VbDisplayScreen(cparams,
                                VB_SCREEN_DEVELOPER_TO_NORM,
                                0, &vnc);
                /* Ignore space in VbUserConfirms()... */
                switch (VbUserConfirms(cparams, 0)) {
                case 1:
                    VBDEBUG(("%s() - leaving dev-mode.\n",
                             __func__));
                    VbNvSet(&vnc, VBNV_DISABLE_DEV_REQUEST,
                            1);
                    VbDisplayScreen(
                        cparams,
                        VB_SCREEN_TO_NORM_CONFIRMED,
                        0, &vnc);
                    VbExSleepMs(5000);
                    return VBERROR_TPM_REBOOT_REQUIRED;
                case -1:
                    VBDEBUG(("%s() - shutdown requested\n",
                             __func__));
                    return VBERROR_SHUTDOWN_REQUESTED;
                default:
                    /* Stay in dev-mode */
                    VBDEBUG(("%s() - stay in dev-mode\n",
                             __func__));
                    VbDisplayScreen(
                        cparams,
                        VB_SCREEN_DEVELOPER_WARNING,
                        0, &vnc);
                    /* Start new countdown */
                    audio = VbAudioOpen(cparams);
                }
            } else {
                /*
                 * No virtual dev-mode switch, so go directly
                 * to recovery mode.
                 */
                VBDEBUG(("%s() - going to recovery\n",
                         __func__));
                VbSetRecoveryRequest(
                    VBNV_RECOVERY_RW_DEV_SCREEN);
                VbAudioClose(audio);
                return VBERROR_LOAD_KERNEL_RECOVERY;
            }
            break;
        case 0x04:
            /* Ctrl+D = dismiss warning; advance to timeout */
            VBDEBUG(("VbBootDeveloper() - "
                     "user pressed Ctrl+D; skip delay\n"));
            ctrl_d_pressed = 1;
            goto fallout;
            break;
        case 0x0c:
            VBDEBUG(("VbBootDeveloper() - "
                     "user pressed Ctrl+L; Try legacy boot\n"));
            VbTryLegacy(allow_legacy);
            break;

        case VB_KEY_CTRL_ENTER:
        /*
         * The Ctrl-Enter is special for Lumpy test purpose;
         * fall through to Ctrl+U handler.
         */
        case 0x15:
            /* Ctrl+U = try USB boot, or beep if failure */
            VBDEBUG(("VbBootDeveloper() - "
                     "user pressed Ctrl+U; try USB\n"));
            if (!allow_usb) {
                VBDEBUG(("VbBootDeveloper() - "
                         "USB booting is disabled\n"));
                VbExDisplayDebugInfo(
                    "WARNING: Booting from external media "
                    "(USB/SD) has not been enabled. Refer "
                    "to the developer-mode documentation "
                    "for details.\n");
                VbExBeep(120, 400);
                VbExSleepMs(120);
                VbExBeep(120, 400);
            } else {
                /*
                 * Clear the screen to show we get the Ctrl+U
                 * key press.
                 */
                VbDisplayScreen(cparams, VB_SCREEN_BLANK, 0,
                                &vnc);
                if (VBERROR_SUCCESS ==
                        VbTryLoadKernel(cparams, p,
                                        VB_DISK_FLAG_REMOVABLE)) {
                    VBDEBUG(("VbBootDeveloper() - "
                             "booting USB\n"));
                    VbAudioClose(audio);
                    return VBERROR_SUCCESS;
                } else {
                    VBDEBUG(("VbBootDeveloper() - "
                             "no kernel found on USB\n"));
                    VbExBeep(250, 200);
                    VbExSleepMs(120);
                    /*
                     * Clear recovery requests from failed
                     * kernel loading, so that powering off
                     * at this point doesn't put us into
                     * recovery mode.
                     */
                    VbSetRecoveryRequest(
                        VBNV_RECOVERY_NOT_REQUESTED);
                    /* Show dev mode warning screen again */
                    VbDisplayScreen(
                        cparams,
                        VB_SCREEN_DEVELOPER_WARNING,
                        0, &vnc);
                }
            }
            break;
        default:
            VBDEBUG(("VbBootDeveloper() - pressed key %d\n", key));
            VbCheckDisplayKey(cparams, key, &vnc);
            break;
        }
    } while(VbAudioLooping(audio));

fallout:

    /* If defaulting to legacy boot, try that unless Ctrl+D was pressed */
    if ((gbb->flags & GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY) &&
            !ctrl_d_pressed) {
        VBDEBUG(("VbBootDeveloper() - defaulting to legacy\n"));
        VbTryLegacy(allow_legacy);
    }

    /* Timeout or Ctrl+D; attempt loading from fixed disk */
    VBDEBUG(("VbBootDeveloper() - trying fixed disk\n"));
    VbAudioClose(audio);
    return VbTryLoadKernel(cparams, p, VB_DISK_FLAG_FIXED);
}