Expand Up
@@ -21,6 +21,8 @@
#include <curses.h>
#include <flash_access.h>
#include <sec_reg_menu.h>
#include <spi/spi_lock_menu.h>
#include "version.h"
/*** defines ***/
Expand All
@@ -30,27 +32,46 @@
// These names come from bootorder_map file
// indexes depend on device order in this file
#define USB_1_SS 0
#define USB_2_SS 1
#define USB_1_HS 2
#define USB_2_HS 3
#define SDCARD 4
#define MSATA 5
#define SATA 6
#define MPCIE1_SATA1 7
#define MPCIE1_SATA2 8
#define IPXE 9
#define USB_1 0
#define USB_2 1
#define USB_3 2
#define USB_4 3
#define USB_5 4
#define USB_6 5
#define USB_7 6
#define USB_8 7
#define USB_9 8
#define USB_10 9
#define USB_11 10
#define USB_12 11
#define SDCARD 12
#define MSATA 13
#define SATA 14
#define MPCIE1_SATA1 15
#define MPCIE1_SATA2 16
#define IPXE 17
#define RESET () outb(0x06, 0x0cf9)
/*** prototypes ***/
static void show_boot_device_list ( char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line_cnt , u8 lineDef_cnt );
static void move_boot_list ( char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line , u8 max_lines );
static void copy_list_line ( char * src , char * dest );
static int fetch_file_from_cbfs ( char * filename , char destination [MAX_DEVICES ][MAX_LENGTH ], u8 * line_count );
static int get_line_number (u8 line_start , u8 line_end , char key );
static void int_ids ( char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line_cnt , u8 lineDef_cnt );
static void update_tag_value (char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 * max_lines , const char * tag , char value );
static void show_boot_device_list (char buffer [MAX_DEVICES ][MAX_LENGTH ],
u8 line_cnt , u8 lineDef_cnt );
static void move_boot_list (char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line ,
u8 max_lines );
static void copy_list_line (char * src , char * dest );
static int fetch_file_from_cbfs (char * filename ,
char destination [MAX_DEVICES ][MAX_LENGTH ],
u8 * line_count );
static int get_line_number (u8 line_start , u8 line_end , char key );
static void int_ids (char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line_cnt ,
u8 lineDef_cnt );
static void update_tag_value (char buffer [MAX_DEVICES ][MAX_LENGTH ],
u8 * max_lines , const char * tag , char value );
#ifndef TARGET_APU1
static void update_wdg_timeout (char buffer [MAX_DEVICES ][MAX_LENGTH ],
u8 * max_lines , u16 value );
#endif
static void update_tags (char bootlist [MAX_DEVICES ][MAX_LENGTH ], u8 * max_lines );
static void refresh_tag_values (u8 max_lines );
/*** local variables ***/
Expand All
@@ -71,6 +92,8 @@ static u8 com2_available;
static u8 ehci0_toggle ;
static u8 mpcie2_clk_toggle ;
static u8 boost_toggle ;
static u8 sd3_toggle ;
static u16 wdg_timeout ;
#endif
static u8 uartc_toggle ;
Expand Down
Expand Up
@@ -186,6 +209,14 @@ int main(void) {
token = strstr (bootorder_data , "boosten" );
token += strlen ("boosten" );
boost_toggle = token ? strtoul (token , NULL , 10 ) : 0 ;
token = strstr (bootorder_data , "sd3mode" );
token += strlen ("sd3mode" );
sd3_toggle = token ? strtoul (token , NULL , 10 ) : 0 ;
token = strstr (bootorder_data , "watchdog" );
token += strlen ("watchdog" );
wdg_timeout = token ? (u16 ) strtoul (token , NULL , 16 ) : 0 ;
#endif
token = strstr (bootorder_data , "uartc" );
Expand Down
Expand Up
@@ -255,24 +286,28 @@ int main(void) {
case 'L' :
boost_toggle ^= 0x1 ;
break ;
case 'i' :
case 'I' :
; // empty statement to avoid compilation error
char * prompt = readline ("Specify the watchdog"
" timeout in seconds (0 to disable): " );
wdg_timeout = (u16 ) strtoul (prompt , NULL , 10 );
prompt [0 ] = '\0' ;
break ;
case 'j' :
case 'J' :
sd3_toggle ^= 0x1 ;
break ;
case 'Q' :
handle_spi_lock_menu ();
break ;
case 'Z' :
handle_reg_sec_menu ();
break ;
#endif
case 's' :
case 'S' :
update_tag_value (bootlist , & max_lines , "pxen" , ipxe_toggle + '0' );
update_tag_value (bootlist , & max_lines , "usben" , usb_toggle + '0' );
update_tag_value (bootlist , & max_lines , "scon" , console_toggle + '0' );
if (com2_available )
update_tag_value (bootlist , & max_lines , "com2en" , com2_toggle + '0' );
update_tag_value (bootlist , & max_lines , "uartc" , uartc_toggle + '0' );
update_tag_value (bootlist , & max_lines , "uartd" , uartd_toggle + '0' );
#ifndef TARGET_APU1
update_tag_value (bootlist , & max_lines , "mpcie2_clk" , mpcie2_clk_toggle + '0' );
update_tag_value (bootlist , & max_lines , "ehcien" , ehci0_toggle + '0' );
update_tag_value (bootlist , & max_lines , "boosten" , boost_toggle + '0' );
#endif
update_tags (bootlist , & max_lines );
save_flash (flash_address , bootlist , max_lines , spi_wp_toggle );
// fall through to exit ...
case 'x' :
Expand Down
Expand Up
@@ -311,7 +346,8 @@ static int strcmp_printable_char(const char *s1, const char *s2)
}
/*******************************************************************************/
static int get_line_number ( u8 line_start , u8 line_end , char key ) {
static int get_line_number (u8 line_start , u8 line_end , char key )
{
int i ;
for (i = line_end - 1 ; i >= line_start ; i -- ) {
if (id [i ] == key )
Expand All
@@ -321,8 +357,9 @@ static int get_line_number( u8 line_start, u8 line_end, char key ) {
}
/*******************************************************************************/
static void copy_list_line ( char * src , char * dest ) {
u8 i = 0 ;
static void copy_list_line (char * src , char * dest )
{
u8 i = 0 ;
do {
dest [i ] = src [i ];
Expand All
@@ -331,15 +368,25 @@ u8 i=0;
}
/*******************************************************************************/
static void show_boot_device_list ( char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line_cnt , u8 lineDef_cnt ) {
static void show_boot_device_list (char buffer [MAX_DEVICES ][MAX_LENGTH ],
u8 line_cnt , u8 lineDef_cnt )
{
int i ,j ,y ,unique ;
char print_device [MAX_LENGTH ];
device_toggle [USB_1_SS ] = usb_toggle ;
device_toggle [USB_2_SS ] = usb_toggle ;
device_toggle [USB_1_HS ] = usb_toggle ;
device_toggle [USB_2_HS ] = usb_toggle ;
device_toggle [IPXE ] = ipxe_toggle ;
device_toggle [USB_1 ] = usb_toggle ;
device_toggle [USB_2 ] = usb_toggle ;
device_toggle [USB_3 ] = usb_toggle ;
device_toggle [USB_4 ] = usb_toggle ;
device_toggle [USB_5 ] = usb_toggle ;
device_toggle [USB_6 ] = usb_toggle ;
device_toggle [USB_7 ] = usb_toggle ;
device_toggle [USB_8 ] = usb_toggle ;
device_toggle [USB_9 ] = usb_toggle ;
device_toggle [USB_10 ] = usb_toggle ;
device_toggle [USB_11 ] = usb_toggle ;
device_toggle [USB_12 ] = usb_toggle ;
device_toggle [IPXE ] = ipxe_toggle ;
printf ("Boot order - type letter to move device to top.\n\n" );
for (i = 0 ; i < line_cnt ; i ++ ) {
Expand All
@@ -363,26 +410,42 @@ static void show_boot_device_list( char buffer[MAX_DEVICES][MAX_LENGTH], u8 line
}
printf ("\n\n" );
printf (" r Restore boot order defaults\n" );
printf (" n Network/PXE boot - Currently %s\n" , (ipxe_toggle ) ? "Enabled" : "Disabled" );
printf (" u USB boot - Currently %s\n" , (usb_toggle ) ? "Enabled" : "Disabled" );
printf (" t Serial console - Currently %s\n" , (console_toggle ) ? "Enabled" : "Disabled" );
printf (" n Network/PXE boot - Currently %s\n" ,
(ipxe_toggle ) ? "Enabled" : "Disabled" );
printf (" u USB boot - Currently %s\n" ,
(usb_toggle ) ? "Enabled" : "Disabled" );
printf (" t Serial console - Currently %s\n" ,
(console_toggle ) ? "Enabled" : "Disabled" );
if (com2_available )
printf (" k Redirect console output to COM2 - Currently %s\n" , (com2_toggle ) ? "Enabled" : "Disabled" );
printf (" o UART C - Currently %s\n" , (uartc_toggle ) ? "Enabled" : "Disabled" );
printf (" p UART D - Currently %s\n" , (uartd_toggle ) ? "Enabled" : "Disabled" );
printf (" k Redirect console output to COM2 - Currently %s\n" ,
(com2_toggle ) ? "Enabled" : "Disabled" );
printf (" o UART C - Currently %s\n" ,
(uartc_toggle ) ? "Enabled" : "Disabled" );
printf (" p UART D - Currently %s\n" ,
(uartd_toggle ) ? "Enabled" : "Disabled" );
#ifndef TARGET_APU1
printf (" m Force mPCIe2 slot CLK (GPP3 PCIe) - Currently %s\n" , (mpcie2_clk_toggle ) ? "Enabled" : "Disabled" );
printf (" h EHCI0 controller - Currently %s\n" , (ehci0_toggle ) ? "Enabled" : "Disabled" );
printf (" l Core Performance Boost - Currently %s\n" , (boost_toggle ) ? "Enabled" : "Disabled" );
printf (" m Force mPCIe2 slot CLK (GPP3 PCIe) - Currently %s\n" ,
(mpcie2_clk_toggle ) ? "Enabled" : "Disabled" );
printf (" h EHCI0 controller - Currently %s\n" ,
(ehci0_toggle ) ? "Enabled" : "Disabled" );
printf (" l Core Performance Boost - Currently %s\n" ,
(boost_toggle ) ? "Enabled" : "Disabled" );
printf (" i Watchdog - Currently %s\n" ,
(wdg_timeout ) ? "Enabled" : "Disabled" );
printf (" j SD 3.0 mode - Currently %s\n" ,
(sd3_toggle ) ? "Enabled" : "Disabled" );
#endif
printf (" w Enable BIOS write protect - Currently %s\n" , (spi_wp_toggle ) ? "Enabled" : "Disabled" );
printf (" w Enable BIOS write protect - Currently %s\n" ,
(spi_wp_toggle ) ? "Enabled" : "Disabled" );
printf (" x Exit setup without save\n" );
printf (" s Save configuration and exit\n" );
}
/*******************************************************************************/
static void int_ids ( char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line_cnt , u8 lineDef_cnt ) {
int i ,y ;
static void int_ids (char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line_cnt ,
u8 lineDef_cnt )
{
int i ,y ;
for (i = 0 ; i < line_cnt ; i ++ ) {
if (buffer [i ][0 ] == '/' ) {
for (y = 0 ; y < lineDef_cnt ; y ++ ) {
Expand All
@@ -396,7 +459,10 @@ int i,y;
}
/*******************************************************************************/
static int fetch_file_from_cbfs ( char * filename , char destination [MAX_DEVICES ][MAX_LENGTH ], u8 * line_count ) {
static int fetch_file_from_cbfs (char * filename ,
char destination [MAX_DEVICES ][MAX_LENGTH ],
u8 * line_count )
{
char * cbfs_dat , tmp ;
int cbfs_offset = 0 , char_cnt = 0 ;
size_t cbfs_length ;
Expand Down
Expand Up
@@ -438,7 +504,9 @@ static int fetch_file_from_cbfs( char *filename, char destination[MAX_DEVICES][M
}
/*******************************************************************************/
static void move_boot_list ( char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line , u8 max_lines ) {
static void move_boot_list (char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 line ,
u8 max_lines )
{
char temp_line [MAX_LENGTH ];
char ln ;
u8 x ;
Expand All
@@ -463,7 +531,8 @@ static void move_boot_list( char buffer[MAX_DEVICES][MAX_LENGTH], u8 line, u8 ma
}
/*******************************************************************************/
static void update_tag_value (char buffer [MAX_DEVICES ][MAX_LENGTH ], u8 * max_lines , const char * tag , char value )
static void update_tag_value (char buffer [MAX_DEVICES ][MAX_LENGTH ],
u8 * max_lines , const char * tag , char value )
{
int i ;
bool found = FALSE;
Expand All
@@ -488,7 +557,58 @@ static void update_tag_value(char buffer[MAX_DEVICES][MAX_LENGTH], u8 *max_lines
(* max_lines )++ ;
}
}
#ifndef TARGET_APU1
static void update_wdg_timeout (char buffer [MAX_DEVICES ][MAX_LENGTH ],
u8 * max_lines , u16 value )
{
int i ;
bool found = FALSE;
char * tag = "watchdog" ;
for (i = 0 ; i < * max_lines ; i ++ ) {
if (!strncmp (tag , & buffer [i ][0 ], strlen (tag ))) {
found = TRUE;
snprintf (& buffer [i ][strlen (tag )], 5 , "%04x" , value );
buffer [* max_lines ][strlen (tag )+ 4 ] = '\r' ;
buffer [* max_lines ][strlen (tag )+ 5 ] = '\n' ;
break ;
}
}
if (!found ) {
if ((* max_lines + 1 ) > MAX_DEVICES ) {
return ;
}
strcpy (& buffer [* max_lines ][0 ], tag );
snprintf (& buffer [* max_lines ][strlen (tag )], 5 , "%04x" , value );
buffer [* max_lines ][strlen (tag )+ 4 ] = '\r' ;
buffer [* max_lines ][strlen (tag )+ 5 ] = '\n' ;
buffer [* max_lines ][strlen (tag )+ 6 ] = '0' ;
(* max_lines )++ ;
}
}
#endif
static void update_tags (char bootlist [MAX_DEVICES ][MAX_LENGTH ], u8 * max_lines )
{
update_tag_value (bootlist , max_lines , "pxen" , ipxe_toggle + '0' );
update_tag_value (bootlist , max_lines , "usben" , usb_toggle + '0' );
update_tag_value (bootlist , max_lines , "scon" , console_toggle + '0' );
if (com2_available ) {
update_tag_value (bootlist , max_lines , "com2en" ,
com2_toggle + '0' );
}
update_tag_value (bootlist , max_lines , "uartc" , uartc_toggle + '0' );
update_tag_value (bootlist , max_lines , "uartd" , uartd_toggle + '0' );
#ifndef TARGET_APU1
update_tag_value (bootlist , max_lines , "mpcie2_clk" ,
mpcie2_clk_toggle + '0' );
update_tag_value (bootlist , max_lines , "ehcien" , ehci0_toggle + '0' );
update_tag_value (bootlist , max_lines , "boosten" , boost_toggle + '0' );
update_tag_value (bootlist , max_lines , "sd3mode" , sd3_toggle + '0' );
update_wdg_timeout (bootlist , max_lines , wdg_timeout );
#endif
}
/*******************************************************************************/
static void refresh_tag_values (u8 max_lines )
{
Expand Down
Expand Up
@@ -547,6 +667,17 @@ static void refresh_tag_values(u8 max_lines)
token += strlen ("boosten" );
boost_toggle = strtoul (token , NULL , 10 );
}
token = strstr (& (bootlist_def [i ][0 ]), "sd3mode" );
if (token ) {
token += strlen ("sd3mode" );
sd3_toggle = strtoul (token , NULL , 10 );
}
token = strstr (& (bootlist_def [i ][0 ]), "watchdog" );
if (token ) {
token += strlen ("watchdog" );
wdg_timeout = (u16 ) strtoul (token , NULL , 16 );
}
#endif
}
}