2021-07-10 18:05:29 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Aidan MacDonald
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-03-05 09:40:57 +00:00
|
|
|
#include "x1000bootloader.h"
|
2021-07-10 18:05:29 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "core_alloc.h"
|
|
|
|
#include "kernel/kernel-internal.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "storage.h"
|
|
|
|
#include "disk.h"
|
2022-03-05 09:40:57 +00:00
|
|
|
#include "file_internal.h"
|
2021-07-10 18:05:29 +00:00
|
|
|
#include "usb.h"
|
2022-03-05 09:40:57 +00:00
|
|
|
#include "i2c-x1000.h"
|
2021-07-10 18:05:29 +00:00
|
|
|
#include "boot-x1000.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2022-03-07 12:27:22 +00:00
|
|
|
static int read_btn(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_BUTTON_DATA
|
|
|
|
int bdata;
|
|
|
|
return button_read_device(&bdata);
|
|
|
|
#else
|
|
|
|
return button_read_device();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-07-10 18:05:29 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
system_init();
|
|
|
|
core_allocator_init();
|
|
|
|
kernel_init();
|
|
|
|
i2c_init();
|
|
|
|
power_init();
|
|
|
|
button_init();
|
2022-03-20 19:51:51 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
touchscreen_set_mode(TOUCHSCREEN_BUTTON);
|
|
|
|
#endif
|
2021-07-10 18:05:29 +00:00
|
|
|
enable_irq();
|
|
|
|
|
|
|
|
if(storage_init() < 0) {
|
2022-03-19 13:54:25 +00:00
|
|
|
splashf(5*HZ, "storage_init() failed");
|
2021-07-10 18:05:29 +00:00
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
|
|
|
|
filesystem_init();
|
|
|
|
|
2022-03-05 09:39:46 +00:00
|
|
|
usb_init();
|
|
|
|
usb_start_monitoring();
|
|
|
|
|
2022-03-05 09:38:13 +00:00
|
|
|
/* It's OK if this doesn't mount anything. Any disk access should
|
|
|
|
* be guarded by a call to check_disk() to see if the disk is really
|
|
|
|
* present, blocking with an "insert SD card" prompt if appropriate. */
|
|
|
|
disk_mount_all();
|
|
|
|
|
2021-07-10 18:05:29 +00:00
|
|
|
/* If USB booting, the user probably needs to enter recovery mode;
|
|
|
|
* let's not force them to hold down the recovery key. */
|
|
|
|
bool recovery_mode = get_boot_flag(BOOT_FLAG_USB_BOOT);
|
|
|
|
|
2022-03-07 12:27:22 +00:00
|
|
|
/* Normal boot - if it fails, we bail to the recovery menu */
|
|
|
|
if(!recovery_mode) {
|
|
|
|
int btn = read_btn();
|
|
|
|
btn &= ~BUTTON_POWER; /* ignore power button */
|
2021-07-10 18:05:29 +00:00
|
|
|
|
2022-03-07 12:27:22 +00:00
|
|
|
if(btn == BL_RECOVERY)
|
|
|
|
recovery_mode = true;
|
|
|
|
#if defined(OF_PLAYER_BTN)
|
|
|
|
else if(btn == OF_PLAYER_BTN)
|
|
|
|
boot_of_player();
|
|
|
|
#endif
|
|
|
|
#if defined(OF_RECOVERY_BTN)
|
|
|
|
else if(btn == OF_RECOVERY_BTN)
|
|
|
|
boot_of_recovery();
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
boot_rockbox();
|
|
|
|
}
|
2021-07-10 18:05:29 +00:00
|
|
|
|
|
|
|
/* This function does not return. */
|
|
|
|
recovery_menu();
|
|
|
|
}
|