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$
9 *
10 * Copyright (C) 2006 by Barry Wardell
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 <stdlib.h>
27#include "common.h"
28#include "cpu.h"
29#include "system.h"
30#include "../kernel-internal.h"
31#include "lcd.h"
32#include "font.h"
33#include "storage.h"
34#include "file_internal.h"
35#include "file.h"
36#include "button.h"
37#include "disk.h"
38#include "crc32.h"
39#include <string.h>
40#include "i2c.h"
41#include "backlight-target.h"
42#include "power.h"
43#include "version.h"
44
45#define START_SECTOR_OF_ROM 1
46#define ROMSECTOR_TO_HACK 63
47#define HACK_OFFSET 498
48#define KNOWN_CRC32 0x5a09c266 /* E200R CRC before patching */
49#define PATCHED_CRC32 0x0a162b34 /* E200R CRC after patching */
50
51static unsigned char knownBytes[] = {0x00, 0x24, 0x07, 0xe1};
52static unsigned char changedBytes[] = {0xc0, 0x46, 0xc0, 0x46 };
53
54/*
55 CRC32s of sector 63 from E200 bootloaders - so we can tell users if they're
56 trying to use e200rpatcher with a vanilla e200.
57
58 These are all known E200 bootloaders as of 8 November 2007.
59
60*/
61
62static uint32_t e200_crcs[] =
63{
64 0xbeceba58,
65 0x4e6b038f,
66 0x5e4f4219,
67 0xae087742,
68 0x3dd94852,
69 0x72fa69f3,
70 0x4ce0d10b
71};
72
73#define NUM_E200_CRCS ((int)((sizeof(e200_crcs) / sizeof(uint32_t))))
74
75static bool is_e200(uint32_t crc)
76{
77 int i;
78
79 for (i = 0 ; i < NUM_E200_CRCS ; i++)
80 {
81 if (crc == e200_crcs[i])
82 return true;
83 }
84
85 return false;
86}
87
88
89void* main(void)
90{
91 int i;
92 int btn;
93 int num_partitions;
94 int crc32;
95 char sector[512];
96 struct partinfo pinfo;
97
98 system_init();
99 kernel_init();
100 lcd_init();
101 font_init();
102 button_init();
103 i2c_init();
104 backlight_hw_on();
105
106 lcd_set_foreground(LCD_WHITE);
107 lcd_set_background(LCD_BLACK);
108 lcd_clear_display();
109
110 btn = button_read_device();
111 verbose = true;
112
113 lcd_setfont(FONT_SYSFIXED);
114
115 printf("Rockbox e200R installer");
116 printf("Version: %s", rbversion);
117 printf(MODEL_NAME);
118 printf("");
119
120 i=storage_init();
121 filesystem_init();
122 num_partitions = disk_mount_all();
123
124 if (num_partitions<=0)
125 {
126 error(EDISK, num_partitions, true);
127 }
128
129 disk_partinfo(1, &pinfo);
130
131#if 0 /* not needed in release builds */
132 printf("--- Partition info ---");
133 printf("start: %x", pinfo.start);
134 printf("size: %x", pinfo.size);
135 printf("type: %x", pinfo.type);
136 printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512);
137#endif
138
139 storage_read_sectors(pinfo.start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
140 1 , sector);
141 crc32 = crc_32r (sector, 512, 0);
142
143#if 0 /* not needed in release builds */
144 printf("--- Hack Status ---");
145 printf("Sector checksum: %x", crc32);
146#endif
147
148 if (crc32 == PATCHED_CRC32)
149 {
150 /* Bootloader already patched */
151 printf("Already unlocked");
152 printf("Proceed to Step 2");
153 } else if ((crc32 == KNOWN_CRC32) &&
154 !memcmp(§or[HACK_OFFSET], knownBytes,
155 sizeof(knownBytes)/sizeof(*knownBytes)))
156 {
157 /* E200R bootloader detected - patch it */
158 memcpy(§or[HACK_OFFSET], changedBytes,
159 sizeof(changedBytes)/sizeof(*changedBytes));
160 storage_write_sectors(
161 pinfo.start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
162 1 , sector);
163 printf("Firmware unlocked");
164 printf("Proceed to Step 2");
165 } else if (is_e200(crc32))
166 {
167 printf("Vanilla E200 detected!");
168 printf("Please install using");
169 printf("Sansapatcher");
170 }
171 else
172 {
173 printf("Unknown bootloader");
174 printf("Rockbox installer cannot");
175 printf("continue");
176 }
177
178 /* Turn button lights off */
179 GPIOG_OUTPUT_VAL &=~0x80;
180
181 printf("");
182
183 if (button_hold())
184 printf("Release Hold and");
185
186 printf("Press any key to shutdown");
187
188 while(button_read_device() == BUTTON_NONE);
189
190 power_off();
191
192 return NULL;
193}