2
* autoboot.c - set/clear Server Mode boot on the VIA-CUDA
5
* Copyright (C) 2005 Rich Johnson. All rights rserved.
7
* This code is modeled on pmacpow, written by Takashi Oe
8
* and modified by Keith Keller.
10
* To make: save file to autoboot.c
11
* gcc -o autoboot autoboot.c
14
* This program is free software; you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License
16
* as published by the Free Software Foundation; either version
17
* 2 of the License, or (at your option) any later version.
19
* Setting Server Mode causes the machine to boot automatically
20
* upon restoration of power after an outage.
21
* Clearing Server Mode will requires a manual boot.
22
* Normal shutdown and sheduling a boot (see bootsched) clear
25
* The server mode setting is good for the current OS session only
26
* and is cleared when the machine boots. For continuous
27
* unattended operation autoboot should be invoked during the boot
30
* see also: bootsched.
33
#include "autoboot-conf.h"
45
# ifdef HAVE_LINUX_ADB_H
46
# include <linux/adb.h>
50
#ifdef HAVE_ASM_CUDA_H
51
# include <asm/cuda.h>
53
# ifdef HAVE_LINUX_CUDA_H
54
# include <linux/cuda.h>
58
unsigned char reqt[2] =
59
{ CUDA_PACKET, CUDA_GET_TIME};
60
unsigned char reqp[6] =
61
{ CUDA_PACKET, CUDA_POWERUP_TIME, 0, 0, 0, 0};
62
unsigned char server[3] =
63
{ CUDA_PACKET, 0x13, 0 };
65
unsigned char reply[16];
68
static int verbose = 0;
69
static int version = 0;
70
static int synopsis = 0;
71
static int servermode = 0;
72
static char *program_name;
74
void dump(unsigned char *buf, int n)
78
for (i = 0; i < n; ++i)
79
fprintf(stderr, " %.2x", buf[i]);
80
fprintf(stderr, "\n");
89
"\t-v: verbose operation\n"
90
"\t-V: print version number and exit \n"
91
"\t-?: print this synopsis\n"
92
"\ton: enable server mode, boot whenever power restored\n"
93
"\toff: disable server mode, boot manually\n",
94
program_name, program_name, program_name, program_name );
99
void print_version( void ){
100
fprintf( stderr, "%s: v1.0\n", program_name );
104
int set_servermode( int fd, long is_server, int is_verbose )
111
n = write(fd, server, sizeof(server));
112
if (n != sizeof(server)) {
113
fprintf(stderr, "%s: write returned %d\n", program_name, n);
118
fprintf(stderr, "Automatic boot enabled (Server Mode)\n");
121
fprintf(stderr, "Automatic boot disabled \n");
129
int main(int argc, char **argv)
131
int fd, arg, hour, min;
135
program_name = (char *)basename(argv[0]);
137
fprintf(stderr, "Sorry, must be root to set power up time\n");
140
while ((arg = getopt(argc, argv, "vV")) != EOF) {
165
if (optind != argc-1)
168
if( strcmp( argv[optind], "on" ) == 0 ){
171
else if( strcmp( argv[optind], "off" ) == 0 ){
178
if ((fd = open("/dev/adb", O_RDWR)) < 0) {
182
set_servermode( fd, servermode, verbose );