1
0
Fork 0
forked from len0rd/rockbox

x1000: bootloader: refactor splash/splash2

Allow the use of printf formatting and multiple lines of text
using newlines in the string.

Change-Id: I65919bf29c16c34c38cf3995e02d2ddbbaa4bdf3
This commit is contained in:
Aidan MacDonald 2022-03-19 13:54:25 +00:00
parent 41a8b874d2
commit fbe9e4ac10
6 changed files with 82 additions and 39 deletions

View file

@ -43,14 +43,14 @@ void boot_rockbox(void)
void shutdown(void) void shutdown(void)
{ {
splash(HZ, "Shutting down"); splashf(HZ, "Shutting down");
power_off(); power_off();
while(1); while(1);
} }
void reboot(void) void reboot(void)
{ {
splash(HZ, "Rebooting"); splashf(HZ, "Rebooting");
system_reboot(); system_reboot();
while(1); while(1);
} }
@ -70,13 +70,13 @@ static int read_linux_args(const char* filename)
size_t max_size; size_t max_size;
int handle = core_alloc_maximum("args", &max_size, &buflib_ops_locked); int handle = core_alloc_maximum("args", &max_size, &buflib_ops_locked);
if(handle <= 0) { if(handle <= 0) {
splash(5*HZ, "Out of memory"); splashf(5*HZ, "Out of memory");
return -2; return -2;
} }
int fd = open(filename, O_RDONLY); int fd = open(filename, O_RDONLY);
if(fd < 0) { if(fd < 0) {
splash2(5*HZ, "Can't open args file", filename); splashf(5*HZ, "Can't open args file\n%s", filename);
ret = -3; ret = -3;
goto err_free; goto err_free;
} }
@ -84,7 +84,7 @@ static int read_linux_args(const char* filename)
/* this isn't 100% correct but will be good enough */ /* this isn't 100% correct but will be good enough */
off_t fsize = filesize(fd); off_t fsize = filesize(fd);
if(fsize < 0 || fsize+1 > (off_t)max_size) { if(fsize < 0 || fsize+1 > (off_t)max_size) {
splash(5*HZ, "Arguments too long"); splashf(5*HZ, "Arguments too long");
ret = -4; ret = -4;
goto err_close; goto err_close;
} }
@ -96,7 +96,7 @@ static int read_linux_args(const char* filename)
close(fd); close(fd);
if(rdres != (ssize_t)fsize) { if(rdres != (ssize_t)fsize) {
splash(5*HZ, "Can't read args file"); splashf(5*HZ, "Can't read args file");
ret = -5; ret = -5;
goto err_free; goto err_free;
} }
@ -191,7 +191,7 @@ void boot_of_helper(uint32_t addr, uint32_t flash_size, const char* args)
void* jump_addr = core_get_data(handle); void* jump_addr = core_get_data(handle);
uint32_t entry_addr = mips_linux_stub_get_entry(&jump_addr, img_length); uint32_t entry_addr = mips_linux_stub_get_entry(&jump_addr, img_length);
if(entry_addr >= 0xa0000000 || entry_addr < 0x80000000) { if(entry_addr >= 0xa0000000 || entry_addr < 0x80000000) {
splash2(5*HZ, "Kernel patch failed", "Please send bugreport"); splashf(5*HZ, "Kernel patch failed\nPlease send bugreport");
return; return;
} }
@ -216,7 +216,7 @@ void boot_of_player(void)
#if defined(OF_PLAYER_ADDR) #if defined(OF_PLAYER_ADDR)
boot_of_helper(OF_PLAYER_ADDR, OF_PLAYER_LENGTH, OF_PLAYER_ARGS); boot_of_helper(OF_PLAYER_ADDR, OF_PLAYER_LENGTH, OF_PLAYER_ARGS);
#else #else
splash(HZ, "Not supported"); splashf(HZ, "Not supported");
#endif #endif
} }
@ -225,6 +225,6 @@ void boot_of_recovery(void)
#if defined(OF_RECOVERY_ADDR) #if defined(OF_RECOVERY_ADDR)
boot_of_helper(OF_RECOVERY_ADDR, OF_RECOVERY_LENGTH, OF_RECOVERY_ARGS); boot_of_helper(OF_RECOVERY_ADDR, OF_RECOVERY_LENGTH, OF_RECOVERY_ARGS);
#else #else
splash(HZ, "Not supported"); splashf(HZ, "Not supported");
#endif #endif
} }

View file

@ -29,6 +29,8 @@
#include "button.h" #include "button.h"
#include "version.h" #include "version.h"
#include <string.h> #include <string.h>
#include <stdarg.h>
#include <stdio.h>
static bool lcd_inited = false; static bool lcd_inited = false;
extern bool is_usb_connected; extern bool is_usb_connected;
@ -53,27 +55,70 @@ void putcenter_y(int y, const char* msg)
lcd_putsxy(x, y, msg); lcd_putsxy(x, y, msg);
} }
void putcenter_line(int line, const char* msg) static void get_splash_size(const char* str, int* width, int* height)
{ {
int y = LCD_HEIGHT/2 + (line - 1)*SYSFONT_HEIGHT; *width = 0;
putcenter_y(y, msg); *height = 0;
while(str) {
const char* np = strchr(str, '\n');
int len;
if(np) {
len = np - str;
np++;
} else {
len = strlen(str);
}
*width = MAX(len, *width);
*height += 1;
str = np;
}
} }
void splash2(long delay, const char* msg, const char* msg2) void splashf(long delay, const char* msg, ...)
{ {
static char buf[512];
va_list ap;
va_start(ap, msg);
int len = vsnprintf(buf, sizeof(buf), msg, ap);
va_end(ap);
if(len < 0)
return;
int xpos, ypos;
int width, height;
get_splash_size(buf, &width, &height);
width *= SYSFONT_WIDTH;
height *= SYSFONT_HEIGHT;
xpos = (LCD_WIDTH - width) / 2;
ypos = (LCD_HEIGHT - height) / 2;
const int padding = 10;
clearscreen(); clearscreen();
putcenter_line(0, msg); lcd_drawrect(xpos-padding, ypos-padding,
if(msg2) width+2*padding, height+2*padding);
putcenter_line(1, msg2);
char* str = buf;
do {
char* np = strchr(str, '\n');
if(np) {
*np = '\0';
np++;
}
lcd_putsxyf(xpos, ypos, "%s", str);
ypos += SYSFONT_HEIGHT;
str = np;
} while(str);
lcd_update(); lcd_update();
sleep(delay); sleep(delay);
} }
void splash(long delay, const char* msg)
{
splash2(delay, msg, NULL);
}
int get_button(int timeout) int get_button(int timeout)
{ {
int btn = button_get_w_tmo(timeout); int btn = button_get_w_tmo(timeout);

View file

@ -34,7 +34,7 @@ enum {
static void bootloader_action(int which) static void bootloader_action(int which)
{ {
if(check_disk(true) != DISK_PRESENT) { if(check_disk(true) != DISK_PRESENT) {
splash2(5*HZ, "Install aborted", "Cannot access SD card"); splashf(5*HZ, "Install aborted\nCannot access SD card");
return; return;
} }
@ -46,7 +46,7 @@ static void bootloader_action(int which)
default: return; /* can't happen */ default: return; /* can't happen */
} }
splash(0, msg); splashf(0, msg);
int rc; int rc;
switch(which) { switch(which) {
@ -60,7 +60,7 @@ static void bootloader_action(int which)
snprintf(buf, sizeof(buf), "%s (%d)", installer_strerror(rc), rc); snprintf(buf, sizeof(buf), "%s (%d)", installer_strerror(rc), rc);
const char* msg1 = rc == 0 ? "Success" : buf; const char* msg1 = rc == 0 ? "Success" : buf;
const char* msg2 = "Press " BL_QUIT_NAME " to continue"; const char* msg2 = "Press " BL_QUIT_NAME " to continue";
splash2(0, msg1, msg2); splashf(0, "%s\n%s", msg1, msg2);
while(get_button(TIMEOUT_BLOCK) != BL_QUIT); while(get_button(TIMEOUT_BLOCK) != BL_QUIT);
} }

View file

@ -44,7 +44,7 @@ void main(void)
enable_irq(); enable_irq();
if(storage_init() < 0) { if(storage_init() < 0) {
splash(5*HZ, "storage_init() failed"); splashf(5*HZ, "storage_init() failed");
power_off(); power_off();
} }

View file

@ -46,13 +46,13 @@ int check_disk(bool wait)
return DISK_ABSENT; return DISK_ABSENT;
while(!storage_present(IF_MD(0))) { while(!storage_present(IF_MD(0))) {
splash2(0, "Insert SD card", "Press " BL_QUIT_NAME " to cancel"); splashf(0, "Insert SD card\nPress " BL_QUIT_NAME " to cancel");
if(get_button(HZ/4) == BL_QUIT) if(get_button(HZ/4) == BL_QUIT)
return DISK_CANCELED; return DISK_CANCELED;
} }
/* a lie intended to give time for mounting the disk in the background */ /* a lie intended to give time for mounting the disk in the background */
splash(HZ, "Scanning disk"); splashf(HZ, "Scanning disk");
return DISK_PRESENT; return DISK_PRESENT;
} }
@ -60,19 +60,19 @@ int check_disk(bool wait)
void usb_mode(void) void usb_mode(void)
{ {
if(!is_usb_connected) if(!is_usb_connected)
splash2(0, "Waiting for USB", "Press " BL_QUIT_NAME " to cancel"); splashf(0, "Waiting for USB\nPress " BL_QUIT_NAME " to cancel");
while(!is_usb_connected) while(!is_usb_connected)
if(get_button(TIMEOUT_BLOCK) == BL_QUIT) if(get_button(TIMEOUT_BLOCK) == BL_QUIT)
return; return;
splash(0, "USB mode"); splashf(0, "USB mode");
usb_acknowledge(SYS_USB_CONNECTED_ACK); usb_acknowledge(SYS_USB_CONNECTED_ACK);
while(is_usb_connected) while(is_usb_connected)
get_button(TIMEOUT_BLOCK); get_button(TIMEOUT_BLOCK);
splash(3*HZ, "USB disconnected"); splashf(3*HZ, "USB disconnected");
} }
int load_rockbox(const char* filename, size_t* sizep) int load_rockbox(const char* filename, size_t* sizep)
@ -82,7 +82,7 @@ int load_rockbox(const char* filename, size_t* sizep)
int handle = core_alloc_maximum("rockbox", sizep, &buflib_ops_locked); int handle = core_alloc_maximum("rockbox", sizep, &buflib_ops_locked);
if(handle < 0) { if(handle < 0) {
splash(5*HZ, "Out of memory"); splashf(5*HZ, "Out of memory");
return -2; return -2;
} }
@ -90,7 +90,7 @@ int load_rockbox(const char* filename, size_t* sizep)
int rc = load_firmware(loadbuffer, filename, *sizep); int rc = load_firmware(loadbuffer, filename, *sizep);
if(rc <= 0) { if(rc <= 0) {
core_free(handle); core_free(handle);
splash2(5*HZ, "Error loading Rockbox", loader_strerror(rc)); splashf(5*HZ, "Error loading Rockbox\n%s", loader_strerror(rc));
return -3; return -3;
} }
@ -108,13 +108,13 @@ int load_uimage_file(const char* filename,
int fd = open(filename, O_RDONLY); int fd = open(filename, O_RDONLY);
if(fd < 0) { if(fd < 0) {
splash2(5*HZ, "Can't open file", filename); splashf(5*HZ, "Can't open file\n%s", filename);
return -2; return -2;
} }
int handle = uimage_load(uh, sizep, uimage_fd_reader, (void*)(intptr_t)fd); int handle = uimage_load(uh, sizep, uimage_fd_reader, (void*)(intptr_t)fd);
if(handle <= 0) { if(handle <= 0) {
splash2(5*HZ, "Cannot load uImage", filename); splashf(5*HZ, "Cannot load uImage\n%s", filename);
return -3; return -3;
} }
@ -155,7 +155,7 @@ int load_uimage_flash(uint32_t addr, uint32_t length,
nand_lock(n.ndrv); nand_lock(n.ndrv);
if(nand_open(n.ndrv) != NAND_SUCCESS) { if(nand_open(n.ndrv) != NAND_SUCCESS) {
splash(5*HZ, "NAND open failed"); splashf(5*HZ, "NAND open failed");
nand_unlock(n.ndrv); nand_unlock(n.ndrv);
return -1; return -1;
} }
@ -166,7 +166,7 @@ int load_uimage_flash(uint32_t addr, uint32_t length,
nand_unlock(n.ndrv); nand_unlock(n.ndrv);
if(handle <= 0) { if(handle <= 0) {
splash(5*HZ, "uImage load failed"); splashf(5*HZ, "uImage load failed");
return -2; return -2;
} }

View file

@ -118,9 +118,7 @@ struct bl_list {
void clearscreen(void); void clearscreen(void);
void putversion(void); void putversion(void);
void putcenter_y(int y, const char* msg); void putcenter_y(int y, const char* msg);
void putcenter_line(int line, const char* msg); void splashf(long delay, const char* msg, ...);
void splash2(long delay, const char* msg, const char* msg2);
void splash(long delay, const char* msg);
int get_button(int timeout); int get_button(int timeout);
void init_lcd(void); void init_lcd(void);