2019-11-21 15:02:45 +00:00
# include <stdio.h>
# include <string.h>
# include "te.h"
# include "gfx.h"
# include "../utils/util.h"
2019-11-21 19:54:18 +00:00
# include "tools.h"
2019-12-01 00:49:36 +00:00
# include "fs.h"
2019-12-11 12:18:57 +00:00
# include "../utils/btn.h"
# include "emmc.h"
2019-11-21 15:02:45 +00:00
extern bool sd_mount ( ) ;
extern void sd_unmount ( ) ;
2019-12-20 20:00:47 +00:00
extern bool return_sd_mounted ( int value ) ;
2019-12-01 14:42:37 +00:00
extern int launch_payload ( char * path ) ;
2019-11-21 15:02:45 +00:00
menu_item mainmenu [ MAINMENU_AMOUNT ] = {
2019-11-21 20:27:48 +00:00
{ " [SD:/] SD CARD " , COLOR_GREEN , SD_CARD , 1 } ,
2019-12-11 12:18:57 +00:00
{ " [SYSTEM:/] EMMC " , COLOR_GREEN , EMMC_SYS , 1 } ,
2019-11-21 20:27:48 +00:00
{ " \n Mount/Unmount SD " , COLOR_WHITE , MOUNT_SD , 1 } ,
{ " Tools " , COLOR_VIOLET , TOOLS , 1 } ,
2019-12-11 12:18:57 +00:00
{ " SD format " , COLOR_VIOLET , SD_FORMAT , 1 } ,
2019-11-21 20:27:48 +00:00
{ " \n Credits " , COLOR_WHITE , CREDITS , 1 } ,
{ " Exit " , COLOR_WHITE , EXIT , 1 }
2019-11-21 15:02:45 +00:00
} ;
2019-12-01 14:42:37 +00:00
menu_item shutdownmenu [ 7 ] = {
2019-11-21 19:54:18 +00:00
{ " -- EXIT -- \n " , COLOR_ORANGE , - 1 , 0 } ,
2019-11-21 20:27:48 +00:00
{ " Back " , COLOR_WHITE , - 1 , 1 } ,
{ " \n Reboot to RCM " , COLOR_VIOLET , REBOOT_RCM , 1 } ,
{ " Reboot normally " , COLOR_ORANGE , REBOOT_NORMAL , 1 } ,
2019-12-01 14:42:37 +00:00
{ " Power off \n " , COLOR_BLUE , POWER_OFF , 1 } ,
{ " Reboot to Hekate " , COLOR_GREEN , HEKATE , - 1 } ,
{ " Reboot to Atmosphere " , COLOR_GREEN , AMS , - 1 }
2019-11-21 19:54:18 +00:00
} ;
2019-12-03 16:11:08 +00:00
menu_item toolsmenu [ 5 ] = {
2019-11-21 19:54:18 +00:00
{ " -- TOOLS -- \n " , COLOR_VIOLET , - 1 , 0 } ,
2019-11-21 20:27:48 +00:00
{ " Back " , COLOR_WHITE , - 1 , 1 } ,
2019-12-03 09:06:11 +00:00
{ " \n Display Console Info " , COLOR_GREEN , DISPLAY_INFO , 1 } ,
2019-12-11 13:45:30 +00:00
{ " Display GPIO pins " , COLOR_VIOLET , DISPLAY_GPIO , 1 } ,
{ " Dump Firmware " , COLOR_BLUE , DUMPFIRMWARE , 1 }
} ;
menu_item formatmenu [ 4 ] = {
{ " -- FORMAT SD -- \n " , COLOR_RED , - 1 , 0 } ,
{ " Back \n " , COLOR_WHITE , - 1 , 1 } ,
2019-12-18 15:14:14 +00:00
{ " Format entire SD to FAT32 " , COLOR_RED , FORMAT_ALL_FAT32 , 1 } ,
{ " Format for EmuMMC setup (FAT32/RAW) " , COLOR_RED , FORMAT_EMUMMC , 1 }
2019-11-21 15:02:45 +00:00
} ;
void fillmainmenu ( ) {
int i ;
for ( i = 0 ; i < MAINMENU_AMOUNT ; i + + ) {
switch ( i + 1 ) {
case 1 :
2019-12-12 12:18:43 +00:00
case 5 :
2019-12-20 20:00:47 +00:00
if ( return_sd_mounted ( i + 1 ) )
2019-11-21 15:02:45 +00:00
mainmenu [ i ] . property = 1 ;
else
mainmenu [ i ] . property = - 1 ;
break ;
case 3 :
2019-12-20 20:00:47 +00:00
if ( return_sd_mounted ( 1 ) ) {
2019-11-21 19:54:18 +00:00
mainmenu [ i ] . property = 2 ;
strcpy ( mainmenu [ i ] . name , " \n Unmount SD " ) ;
2019-11-21 16:34:47 +00:00
}
else {
2019-11-21 19:54:18 +00:00
mainmenu [ i ] . property = 1 ;
strcpy ( mainmenu [ i ] . name , " \n Mount SD " ) ;
2019-11-21 16:34:47 +00:00
}
2019-11-21 15:02:45 +00:00
break ;
}
}
}
void te_main ( ) {
int res ;
2019-12-17 12:43:32 +00:00
if ( dump_biskeys ( ) = = - 1 ) {
message ( " Biskeys failed to dump! \n Emmc will not be mounted! " , COLOR_RED ) ;
mainmenu [ 1 ] . property = - 1 ;
}
else {
mount_emmc ( " SYSTEM " , 2 ) ;
}
2019-11-21 16:34:47 +00:00
2019-11-21 15:02:45 +00:00
while ( 1 ) {
fillmainmenu ( ) ;
2019-11-21 16:34:47 +00:00
res = makemenu ( mainmenu , MAINMENU_AMOUNT ) ;
2019-11-21 20:27:48 +00:00
switch ( res ) {
case SD_CARD :
2019-12-01 00:49:36 +00:00
filemenu ( " SD:/ " ) ;
2019-11-21 20:27:48 +00:00
break ;
2019-12-11 12:18:57 +00:00
case EMMC_SYS :
if ( makewaitmenu ( " You're about to enter EMMC \n Modifying anything here \n can result in a BRICK! \n \n Please only continue \n if you know what you're doing \n \n Press Vol+/- to return \n " , " Press Power to enter " , 4 ) )
filemenu ( " emmc:/ " ) ;
break ;
/*
case EMMC_USR :
mount_emmc ( " USER " , 2 ) ;
filemenu ( " emmc:/ " ) ;
2019-11-21 20:27:48 +00:00
break ;
2019-12-11 12:18:57 +00:00
*/
2019-11-21 20:27:48 +00:00
case MOUNT_SD :
2019-12-20 20:00:47 +00:00
if ( return_sd_mounted ( 1 ) )
2019-11-21 20:27:48 +00:00
sd_unmount ( ) ;
else
2019-12-20 20:00:47 +00:00
sd_mount ( ) ;
2019-11-21 20:27:48 +00:00
break ;
case TOOLS :
2019-12-03 16:11:08 +00:00
res = makemenu ( toolsmenu , 5 ) ;
2019-11-21 20:27:48 +00:00
2019-12-11 13:45:30 +00:00
switch ( res ) {
case DISPLAY_INFO :
displayinfo ( ) ;
break ;
case DISPLAY_GPIO :
displaygpio ( ) ;
break ;
case DUMPFIRMWARE :
dumpfirmware ( ) ;
break ;
}
2019-11-21 20:27:48 +00:00
break ;
2019-12-11 13:45:30 +00:00
case SD_FORMAT :
res = makemenu ( formatmenu , 4 ) ;
2019-12-12 12:18:43 +00:00
if ( res > = 0 ) {
if ( makewaitmenu ( " Are you sure you want to format your sd? \n This will delete everything on your SD card \n This action is irreversible! \n \n Press Vol+/- to cancel \n " , " Press Power to continue " , 10 ) ) {
if ( format ( res ) ) {
sd_unmount ( ) ;
2019-12-11 16:17:10 +00:00
}
2019-12-12 12:18:43 +00:00
}
2019-12-11 13:45:30 +00:00
}
2019-12-12 12:18:43 +00:00
2019-12-11 13:45:30 +00:00
break ;
2019-11-21 20:27:48 +00:00
case CREDITS :
message ( CREDITS_MESSAGE , COLOR_WHITE ) ;
break ;
case EXIT :
2019-12-20 20:00:47 +00:00
if ( return_sd_mounted ( 1 ) ) {
2019-12-01 14:42:37 +00:00
if ( checkfile ( " /bootloader/update.bin " ) )
shutdownmenu [ 5 ] . property = 1 ;
else
shutdownmenu [ 5 ] . property = - 1 ;
if ( checkfile ( " /atmosphere/reboot_payload.bin " ) )
shutdownmenu [ 6 ] . property = 1 ;
else
shutdownmenu [ 6 ] . property = - 1 ;
}
else {
shutdownmenu [ 5 ] . property = - 1 ;
shutdownmenu [ 6 ] . property = - 1 ;
}
res = makemenu ( shutdownmenu , 7 ) ;
2019-11-21 20:27:48 +00:00
2019-12-01 00:49:36 +00:00
switch ( res ) {
case REBOOT_RCM :
reboot_rcm ( ) ;
case REBOOT_NORMAL :
reboot_normal ( ) ;
2019-11-21 20:27:48 +00:00
2019-12-01 00:49:36 +00:00
case POWER_OFF :
power_off ( ) ;
2019-12-01 14:42:37 +00:00
case HEKATE :
launch_payload ( " /bootloader/update.bin " ) ;
case AMS :
launch_payload ( " /atmosphere/reboot_payload.bin " ) ;
2019-12-01 00:49:36 +00:00
} //todo declock bpmp
2019-11-21 19:54:18 +00:00
2019-12-01 00:49:36 +00:00
break ;
2019-11-21 15:02:45 +00:00
}
}
}