A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: main.c 11997 2007-01-13 09:08:18Z miipekk $
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "lcd.h"
22#include "lcd-remote.h"
23#include "font.h"
24#include "system.h"
25#include <stdarg.h>
26#include <stdio.h>
27#include <stdbool.h>
28#include "cpu.h"
29#include "common.h"
30#include "power.h"
31#include "kernel.h"
32#include "config.h"
33#include "logf.h"
34#include "button.h"
35#include "string.h"
36#include "usb.h"
37#include "file.h"
38#include "loader_strerror.h"
39#if defined(MI4_FORMAT)
40#include "mi4-loader.h"
41#elif defined(RKW_FORMAT)
42#include "rkw-loader.h"
43#else
44#include "rb-loader.h"
45#endif
46#include "disk.h"
47
48/* TODO: Other bootloaders need to be adjusted to set this variable to true
49 on a button press - currently only the ipod, H10, Vibe 500, Sansa, and xDuoo x3 versions do. */
50#if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined(IRIVER_H10_5GB) \
51 || defined(SANSA_E200) || defined(SANSA_C200) || defined(GIGABEAT_F) \
52 || (CONFIG_CPU == AS3525) || (CONFIG_CPU == AS3525v2) || defined(COWON_D2) \
53 || defined(MROBE_100) || defined(MROBE_500) \
54 || defined(SAMSUNG_YH925) || defined(SAMSUNG_YH920) \
55 || defined(SAMSUNG_YH820) || defined(PHILIPS_SA9200) \
56 || defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330) \
57 || defined(ONDA_VX747) || defined(PBELL_VIBE500) \
58 || defined(TOSHIBA_GIGABEAT_S) || defined(XDUOO_X3) \
59 || defined(IHIFI770) || defined(IHIFI770C) || defined(IHIFI800)
60bool verbose = false;
61#else
62bool verbose = true;
63#endif
64
65#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
66int line = 0;
67#ifdef HAVE_REMOTE_LCD
68int remote_line = 0;
69#endif
70
71void reset_screen(void)
72{
73 lcd_clear_display();
74 line = 0;
75#ifdef HAVE_REMOTE_LCD
76 lcd_remote_clear_display();
77 remote_line = 0;
78#endif
79}
80
81int printf(const char *format, ...)
82{
83 static char printfbuf[256];
84 int len;
85 unsigned char *ptr;
86 va_list ap;
87 va_start(ap, format);
88
89 ptr = printfbuf;
90 len = vsnprintf(ptr, sizeof(printfbuf), format, ap);
91 va_end(ap);
92
93 lcd_puts(0, line++, ptr);
94 if (verbose)
95 lcd_update();
96 if(line >= LCD_HEIGHT/SYSFONT_HEIGHT)
97 line = 0;
98#ifdef HAVE_REMOTE_LCD
99 lcd_remote_puts(0, remote_line++, ptr);
100 if (verbose)
101 lcd_remote_update();
102 if(remote_line >= LCD_REMOTE_HEIGHT/SYSFONT_HEIGHT)
103 remote_line = 0;
104#endif
105 return len;
106}
107#endif
108
109void error(int errortype, int error, bool shutdown)
110{
111 switch(errortype)
112 {
113 case EATA:
114 printf("ATA error: %d", error);
115 break;
116
117 case EDISK: {
118 printf("No partition found");
119#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
120 for (int i = 0 ; i < NUM_VOLUMES ; i++) {
121 struct partinfo pinfo;
122 disk_partinfo(i, &pinfo);
123 if (pinfo.type)
124 printf("P%d T%02x S%llx",
125 i, pinfo.type, (unsigned long long)pinfo.size);
126 }
127#endif
128 break;
129 }
130 case EBOOTFILE:
131 printf(loader_strerror(error));
132 break;
133 }
134
135 lcd_update();
136 sleep(5*HZ);
137
138 if(shutdown)
139 power_off();
140}
141
142/* Load raw binary image. */
143int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size)
144{
145 int fd;
146 int rc;
147 int len;
148 char filename[MAX_PATH];
149
150 snprintf(filename,sizeof(filename),"%s",firmware);
151 fd = open(filename, O_RDONLY);
152 if(fd < 0)
153 {
154 return EFILE_NOT_FOUND;
155 }
156
157 len = filesize(fd);
158
159 if (len > buffer_size)
160 return EFILE_TOO_BIG;
161
162 rc = read(fd, buf, len);
163 if(rc < len)
164 return EREAD_IMAGE_FAILED;
165
166 close(fd);
167 return len;
168}