Subject: HPCBoot "Can't Boot Kernel Image"
To: None <port-hpcmips@netbsd.org>
From: Sabahattin Gucukoglu <mail@sabahattin-gucukoglu.com>
List: port-hpcmips
Date: 10/19/2004 21:41:48
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

I am trying to boot a NetBSD 2.0 sysinst kernel image on my BrailleNote 
(Casio E105 with VR4121 chip) with hpcboot but without the help of a 
display (there isn't one) or its graphical interface (shell on the device 
makes it impossible).  I therefore wrote a small program derived from 
hpcboot for execution on the device for dumping a config file out that 
hpcboot should read and then consequently automagically boot the specified 
(for now) hardcoded image with parameters.  Procedures were basically 
snagged from the hpcboot source and the preferences structure filled in 
appropriately so that the save routine would work as it does with hpcboot. 
 My program runs and generates a file without error, but when hpcboot 
runs, finds and examines the file, and begins the boot, it displays a 
message box with "BOOT FAILED" as the title and "Can't open kernel image." 
as the text.  (I happen to know this because one thing the BrailleNote 
shell *does* do is to capture message boxes.)

Here is the source of my short program:

#include <stdio.h>
#include <winuser.h>
#include <winbase.h>
#include <winnt.h>

BOOL save(void);
BOOL _find_pref_dir(TCHAR *path);

struct prefs {
int _magic; /*Magic sequence is 0x177d5753*/
int _version; /*Version number is 0x0102*/
size_t _size; /*Size of prefs struct*/
int dir; /*0*/
BOOL dir_user; /*TRUE if dir_user_path set, else FALSE.*/
TCHAR dir_user_path[MAX_PATH];
BOOL kernel_user; /*True if kernel_user_file set, else false.*/
TCHAR kernel_user_file[MAX_PATH]; /*Kernel image filename.*/
unsigned platid_hi; /*(3<<8)|((1<<14)|((1<<20)|(1<<26)))*/
unsigned platid_lo; /*2|((2<<8)|((1<<16)|(3<<22)))*/
int rootfs; /*Leave at 0 (WD0 or no parm), use bootparams to set it, 
below.*/
TCHAR rootfs_file[MAX_PATH]; /*Only applicable when rootfs is 2 for 
memdisk.*/
BOOL boot_serial; /*TRUE*/
BOOL boot_verbose; /*Why not: TRUE ?*/
BOOL boot_single_user; /*FALSE*/
BOOL boot_ask_for_name; /*FALSE*/
BOOL boot_debugger; /*Not just yet :-) - FALSE */
int auto_boot; /*1!*/
BOOL reverse_video; /*FALSE*/
BOOL pause_before_boot; /*FALSE*/
BOOL load_debug_info; /*FALSE*/
BOOL safety_message; /*FALSE*/
int serial_speed; /*9600 is safe on MIPS.*/
TCHAR boot_extra[256]; /*Parameters to the kernel.*/
} pref;

BOOL save(void) {
TCHAR path[MAX_PATH];
TCHAR filename[MAX_PATH];
wchar_t message[MAX_PATH];
HANDLE file;
DWORD cnt;

if (_find_pref_dir(path)) {
wsprintf(filename, TEXT("\\%s\\hpcboot.cnf"), path);
swprintf(message,L"The saved configuration file's location is: 
%s",filename);
MessageBox(NULL,message,L"Information",MB_ICONINFORMATION);
file = CreateFile(filename, GENERIC_WRITE, 0, 0,CREATE_ALWAYS, 
FILE_ATTRIBUTE_NORMAL, 0);
WriteFile(file, &pref, pref._size, &cnt, 0);
CloseHandle(file);
return cnt == pref._size;
}
return FALSE;
}

BOOL _find_pref_dir(TCHAR *path) {
WIN32_FIND_DATA fd;
HANDLE find;
int attr;

lstrcpy(path, TEXT("\\*.*"));
find = FindFirstFile(path, &fd);

if (find != INVALID_HANDLE_VALUE) {
do {
attr = fd.dwFileAttributes;
if ((attr & FILE_ATTRIBUTE_DIRECTORY) &&
    (attr & FILE_ATTRIBUTE_TEMPORARY)) {
wcscpy(path, fd.cFileName);
FindClose(find);
return TRUE;
}
} while (FindNextFile(find, &fd));
}
FindClose(find);

return FALSE;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,wchar_t 
*lpCmdLine,short nShowCmd) {
pref._magic=0x177d5753;
pref._version=0x0102;
pref._size=sizeof(struct prefs);
pref.dir=0;
pref.dir_user=TRUE;
*pref.dir_user_path=L"\\Storage Card\\";
pref.kernel_user=TRUE;
*pref.kernel_user_file=L"freesoft.gz"; /*Sorry, just couldn't resist.*/
pref.platid_hi=(3<<8)|((1<<14)|((1<<20)|(1<<26)));
pref.platid_lo=2|((2<<8)|((1<<16)|(3<<22)));
pref.rootfs=0;
*pref.rootfs_file=L'\0';
pref.boot_serial=TRUE;
pref.boot_verbose=TRUE;
pref.boot_single_user=FALSE;
pref.boot_ask_for_name=FALSE;
pref.boot_debugger=FALSE;
pref.auto_boot=1;
pref.reverse_video=FALSE;
pref.pause_before_boot=FALSE;
pref.load_debug_info=FALSE;
pref.safety_message=FALSE;
pref.serial_speed=9600;
*pref.boot_extra=L'\0';

if(save()==FALSE) {
MessageBox(NULL,L"Save failed - not all bytes 
written.",L"Fatal",MB_ICONSTOP);
exit(1);
}
exit(0);
}

I have also written a small program called memdiv which you can get at 
ftp://ftp.romuald.net.eu.org/pub/freesoft/ that will let you change and 
view a Windows CE device's memory division parameters using command-line 
and message box (my device won't let me do it with its interface).  See 
the readme included for details about it and my device.

Can anyone help me out here?  I've tried variations of pathnames and 
filenames in both unicode and plain ASCII (char vs wchar_t) to no avail.  
We're obviously getting *somewhere* since the bootloader is trying to boot 
*something*.

Help much appreciated!

Cheers,
Sabahattin

- -- 
Thought for the day:
    Dictatorship (n): a form of government under which everything 
    which is not prohibited is compulsory.


Sabahattin Gucukoglu
Phone: +44 20 88008915
Mobile: +44 7986 053399
http://www.sabahattin-gucukoglu.com/
Email/MSN: <mail@Sabahattin-Gucukoglu.com>


-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0 -- QDPGP 2.70 

iQA/AwUBQXV8DCNEOmEWtR2TEQJ32wCcDFXYDwEqF+zW8hlWkamkWbQJeUkAnAxk
iHXJgprRN+q9SiS7p1yP+rAN
=aZbD
-----END PGP SIGNATURE-----