summaryrefslogtreecommitdiff
path: root/bootloader/fiiom3k.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-02-27 22:08:58 +0000
committerAidan MacDonald <amachronic@protonmail.com>2021-03-28 00:01:37 +0000
commit3ec66893e377b088c1284d2d23adb2aeea6d7965 (patch)
treeb647717f83ad56b15dc42cfdef5d04d68cd9bd6b /bootloader/fiiom3k.c
parent83fcbedc65f4b9ae7e491ecf6f07c0af4b245f74 (diff)
downloadrockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.tar.gz
rockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.zip
New port: FiiO M3K on bare metal
Change-Id: I7517e7d5459e129dcfc9465c6fbd708619888fbe
Diffstat (limited to 'bootloader/fiiom3k.c')
-rw-r--r--bootloader/fiiom3k.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/bootloader/fiiom3k.c b/bootloader/fiiom3k.c
new file mode 100644
index 0000000000..6108a37efc
--- /dev/null
+++ b/bootloader/fiiom3k.c
@@ -0,0 +1,96 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
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
22#include "system.h"
23#include "kernel/kernel-internal.h"
24#include "i2c.h"
25#include "power.h"
26#include "lcd.h"
27#include "backlight.h"
28#include "button.h"
29#include "storage.h"
30#include "file_internal.h"
31#include "disk.h"
32#include "rb-loader.h"
33#include "loader_strerror.h"
34
35/* Load address where the binary needs to be placed */
36extern unsigned char loadaddress[];
37
38/* Fixed buffer to contain the loaded binary in memory */
39extern unsigned char loadbuffer[];
40extern unsigned char loadbufferend[];
41#define MAX_LOAD_SIZE (loadbufferend - loadbuffer)
42
43void exec(void* dst, const void* src, int bytes)
44 __attribute__((noreturn, section(".icode")));
45
46void exec(void* dst, const void* src, int bytes)
47{
48 memcpy(dst, src, bytes);
49 commit_discard_idcache();
50 __asm__ __volatile__ ("jr %0" :: "r"(dst));
51 __builtin_unreachable();
52}
53
54static void error(const char* msg)
55{
56 /* Initialization of the LCD/buttons only if needed */
57 lcd_init();
58 backlight_init();
59 button_init();
60
61 lcd_clear_display();
62 lcd_puts(0, 0, msg);
63 lcd_puts(0, 2, "Press POWER to power off");
64 lcd_update();
65
66 while(button_get(true) != BUTTON_POWER);
67 power_off();
68}
69
70void main(void)
71{
72 system_init();
73 kernel_init();
74 i2c_init();
75 power_init();
76 enable_irq();
77
78 if(storage_init() < 0)
79 error("Storage initialization failed");
80
81 filesystem_init();
82
83 if(!storage_present(0))
84 error("No SD card present");
85
86 if(disk_mount_all() <= 0)
87 error("Unable to mount filesystem");
88
89 int loadsize = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
90 if(loadsize <= 0)
91 error(loader_strerror(loadsize));
92
93 disable_irq();
94
95 exec(loadaddress, loadbuffer, loadsize);
96}