summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted/rolo.c
blob: 229a928c8496f9253ac2f3d0cc20287919fdbf3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 *
 * Copyright (C) 2020 Solomon Peachy
 *
 * 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.
 *
 ****************************************************************************/

#include "config.h"
#include "lcd.h"
#ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h"
#endif
#include "audio.h"
#include "button.h"
#include "scroll_engine.h"
#include "storage.h"
#include "rolo.h"
#include "rbpaths.h"

#include <unistd.h>
#include <stdio.h>

#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
#include "bootdata.h"
#include "crc32.h"
extern  int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*rb-loader.c*/
#endif

static void rolo_error(const char *text, const char *text2)
{
    lcd_clear_display();
    lcd_puts(0, 0, "ROLO error:");
    lcd_puts_scroll(0, 1, text);
    if (text2)
      lcd_puts_scroll(0, 2, text2);
    lcd_update();
    button_get(true);
    button_get(true);
    button_get(true);
    lcd_scroll_stop();
}

int rolo_load(const char* filename)
{
    lcd_clear_display();
    lcd_puts(0, 0, "ROLO...");
    lcd_puts(0, 1, "Loading");
    lcd_update();
#ifdef HAVE_REMOTE_LCD
    lcd_remote_clear_display();
    lcd_remote_puts(0, 0, "ROLO...");
    lcd_remote_puts(0, 1, "Loading");
    lcd_remote_update();
#endif

    audio_stop();

#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
    /* write the bootdata as if rolo were the bootloader */
    unsigned int crc = 0;
    if (strcmp(filename, BOOTDIR "/" BOOTFILE) == 0)
        crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff);

    if(crc > 0 && crc == boot_data.crc)
        write_bootdata(filebuf, filebuf_size, boot_data.boot_volume); /* rb-loader.c */
#endif

#ifdef HAVE_STORAGE_FLUSH
    lcd_puts(0, 2, "Flushing storage buffers");
    lcd_update();
    storage_flush();
#endif

    lcd_puts(0, 3, "Executing");
    lcd_update();
#ifdef HAVE_REMOTE_LCD
    lcd_remote_puts(0, 1, "Executing");
    lcd_remote_update();
#endif

#ifdef PIVOT_ROOT
#define EXECDIR PIVOT_ROOT
#else
#define EXECDIR HOME_DIR
#endif

    char buf[256];
    snprintf(buf, sizeof(buf), "%s/%s", EXECDIR, filename);
    execl(buf, BOOTFILE, NULL);

    rolo_error("Failed to launch!", strerror(errno));

    /* never reached */
    return 0;
}