summaryrefslogtreecommitdiff
path: root/target/linux/ps3/petitboot/base-files/sbin/ps3-bl-option
blob: 972c00ae130f72db53b1aa6b97ac438b9a4f520c (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
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
#
#  Copyright (C) 2008 Sony Computer Entertainment Inc.
#  Copyright 2008 Sony Corp.
#
#  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; version 2 of the License.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

usage() {
	echo -n "
SYNOPSIS
     ps3-bl-option [OPTION]
DESCRIPTION
     Get and set PS3 bootloader options in flash.
OPTIONS
     -m, --get-video-mode
             Get the bootloader video mode.
     -M, --set-video-mode value
             Set the bootloader video mode.
     -o, --get-bootloader-timeout
             Get the bootloader timeout in seconds.
     -O, --set-bootloader-timeout value
             Set the bootloader timeout in seconds.
     -p, --get-bootloader-default
             Get the default bootloader menu item.
     -P, --set-bootloader-default value
             Set the default bootloader menu item.
     -t, --get-telnet-enabled
             Get the telnet enabled flag.
     -T, --set-telnet-enabled value
             Set the telnet enabled flag.
     -h, --help
             Print a help message.
SEE ALSO
     ps3-flash-util(8)
"
}

bad_arg() {
	echo "ERROR: bad arg" >&2;
	usage
	exit 1
}

if [ "$#" -eq 0 ] ; then
	bad_arg
fi

get_flag() {
	flags=`ps3-flash-util --db-print $1 $2`
	echo $(( ${flags:-0} & $3 ))
}

set_flag() {
	flags=`ps3-flash-util --db-print $1 $2`

	if [ $4 -eq 0  ]; then
		ps3-flash-util --db-write-half $1 $2 $(( ${flags:-0} & ~$3 ))
	else
		ps3-flash-util --db-write-half $1 $2 $(( ${flags:-0} | $3 ))
	fi
}

# owners
bootloader="3"

# keys
item="1"
video="2"
flags="3"
timeout="4"

# flags
telnet="1"

case "$1" in
	-m | --get-video-mode)
		ps3-flash-util --db-print ${bootloader} ${video}
		;;
	-M | --set-video-mode)
		ps3-flash-util --db-write-half ${bootloader} ${video} $2
		;;
	-o | --get-bootloader-timeout)
		ps3-flash-util --db-print ${bootloader} ${timeout}
		;;
	-O | --set-bootloader-timeout)
		ps3-flash-util --db-write-half ${bootloader} ${timeout} $2
		;;
	-p | --get-bootloader-default)
		ps3-flash-util --db-print ${bootloader} ${item}
		;;
	-P | --set-bootloader-default)
		ps3-flash-util --db-write-word ${bootloader} ${item} $2
		;;
	-t | --get-telnet-enabled)
		get_flag ${bootloader} ${flags} ${telnet}
		;;
	-T | --set-telnet-enabled)
		set_flag ${bootloader} ${flags} ${telnet} $2
		;;
	-h | --help)
		usage
		exit 0
		;;
	*)
		bad_arg
		;;
esac