A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 178 lines 4.8 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2008 by Rafaël Carré 11 * 12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing 13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach 14 * 15 * This program is free software; you can redistribute it and/or 16 * modify it under the terms of the GNU General Public License 17 * as published by the Free Software Foundation; either version 2 18 * of the License, or (at your option) any later version. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 ****************************************************************************/ 24 25#include <stdio.h> 26#include <system.h> 27#include <inttypes.h> 28#include "config.h" 29#include "gcc_extensions.h" 30#include "../kernel-internal.h" 31#include "lcd.h" 32#ifdef HAVE_BOOTLOADER_USB_MODE 33#include "usb.h" 34#include "sysfont.h" 35#endif /* HAVE_BOOTLOADER_USB_MODE */ 36#include "backlight.h" 37#include "button-target.h" 38#include "common.h" 39#include "rb-loader.h" 40#include "loader_strerror.h" 41#include "storage.h" 42#include "file_internal.h" 43#include "disk.h" 44#include "panic.h" 45#include "power.h" 46 47void show_logo(void); 48 49#ifdef HAVE_BOOTLOADER_USB_MODE 50static void usb_mode(void) 51{ 52 if(usb_detect() != USB_INSERTED) 53 { 54 static const char msg[] = "Plug USB cable"; 55 reset_screen(); 56 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2, 57 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); 58 lcd_update(); 59 60 /* wait until USB is plugged */ 61 while(usb_detect() != USB_INSERTED) ; 62 } 63 64 static const char msg[] = "Bootloader USB mode"; 65 reset_screen(); 66 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2, 67 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); 68 lcd_update(); 69 70 while(usb_detect() == USB_INSERTED) 71 sleep(HZ); 72 73 reset_screen(); 74 lcd_update(); 75} 76#endif /* HAVE_BOOTLOADER_USB_MODE */ 77 78void main(void) NORETURN_ATTR; 79void main(void) 80{ 81 unsigned char* loadbuffer; 82 int buffer_size; 83 void(*kernel_entry)(void); 84 int ret; 85 86 system_init(); 87 kernel_init(); 88 89 enable_irq(); 90 91 lcd_init(); 92 show_logo(); 93 94 backlight_init(); 95 96 button_init_device(); 97 int btn = button_read_device(); 98 99#if !defined(SANSA_FUZE) && !defined(SANSA_CLIP) && !defined(SANSA_CLIPV2) \ 100 && !defined(SANSA_CLIPPLUS) && !defined(SANSA_CLIPZIP) 101 if (button_hold()) 102 { 103 verbose = true; 104 lcd_clear_display(); 105 printf("Hold switch on"); 106 printf("Shutting down..."); 107 sleep(HZ); 108 power_off(); 109 } 110#endif 111 112 /* Enable bootloader messages if any button is pressed */ 113 if (btn) 114 { 115 lcd_clear_display(); 116 verbose = true; 117 } 118 119 ret = storage_init(); 120 if(ret < 0) 121 error(EATA, ret, true); 122 123 filesystem_init(); 124 125#ifdef HAVE_BOOTLOADER_USB_MODE 126 usb_init(); 127 128 /* Enter USB mode if USB is plugged and SELECT button is pressed */ 129 if(btn & BUTTON_SELECT) { 130 usb_start_monitoring(); 131 if(usb_detect() == USB_INSERTED) 132 usb_mode(); 133 } 134#endif /* HAVE_BOOTLOADER_USB_MODE */ 135 136 while((ret = disk_mount_all()) <= 0) 137 { 138#ifdef HAVE_BOOTLOADER_USB_MODE 139 error(EDISK, ret, false); 140 usb_start_monitoring(); 141 usb_mode(); 142#else 143 error(EDISK, ret, true); 144#endif 145 } 146 147 printf("Loading firmware"); 148 149 loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */ 150 buffer_size = (int)(loadbuffer + (DRAM_SIZE) - TTB_SIZE); 151 152 while((ret = load_firmware(loadbuffer, BOOTFILE, buffer_size)) <= EFILE_EMPTY) 153 { 154#ifdef HAVE_BOOTLOADER_USB_MODE 155 error(EBOOTFILE, ret, false); 156 usb_start_monitoring(); 157 usb_mode(); 158#else 159 error(EBOOTFILE, ret, true); 160#endif 161 } 162 163#if defined(SANSA_FUZEV2) || defined(SANSA_CLIPPLUS) || defined(SANSA_CLIPZIP) 164 /* It is necessary for proper detection AMSv2 variant 1. 165 * We should restore initial state of GPIOB_PIN(5) as it used for 166 * variant detection, but can be changed if we switch SD card. */ 167 if (amsv2_variant == 1) 168 GPIOB_PIN(5) = 1 << 5; 169#endif 170 kernel_entry = (void*) loadbuffer; 171 commit_discard_idcache(); 172 printf("Executing"); 173 kernel_entry(); 174 printf("ERR: Failed to boot"); 175 176 /* never returns */ 177 while(1) ; 178}