ts-7000
[Top] [All Lists]

RE: [ts-7000] Re: Jesse's new bootloader...

To: <>
Subject: RE: [ts-7000] Re: Jesse's new bootloader...
From: "William C. Landolina" <>
Date: Tue, 2 Jan 2007 21:42:06 -0500
> Hi Bill,
>
> ...
> Then, in /etc/rc, I put a little program that looks at the kernel and
if
> it is the stripped down boot kernel, loads a new, full featured kernel
> from the compact flash.
>
> This is a great idea.  Would you share how you check for the
> stripped-down kernel?
>
> I've built a stripped-down kernel that fits in flash and boots from
> wd0, but I'm not sure how to do the check in /etc/rc.
>
> Thanks,
> Joe

The code I use to figure out which kernel I have and (optionally) boot a
more full featured kernel is below.

All my bootstrap kernels are named something-BOOT.  This little program
is called very early in my /etc/rc.

Another possibility is to attempt to open a device that is not in the
bootstrap kernel and check the error code for "Device not configured".

This program is a quickie I whipped up to get product out the door.
There is plenty of room here for more intelligence and subtlety.

Enjoy,
Bill

------ bootstrap.cxx --------

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include <sys/param.h>
#include <sys/sysctl.h>

#define DEFAULT_KERNEL "/kernel/netbsd-wd0.bin"
#define DEFAULT_BASE (0x200000)

char kernelName[1000] = DEFAULT_KERNEL;
long baseAddress = DEFAULT_BASE;

void usage()
{
        fprintf(stderr, "Usage: bootstrap {-dr} {-k kernel-name} {-b
base-address}\n");
        fprintf(stderr, "  -d Enable diagnostic output\n");
        fprintf(stderr, "  -r Boot new kernel if 'BOOT' kernel is
detected\n");
        fprintf(stderr, "  -k Specfiy kernel to boot (if -r), default:
%s\n", DEFAULT_KERNEL);
        fprintf(stderr, "  -b Specifiy alternate base address, default:
0x%X\n", DEFAULT_BASE);
        exit(1);
}

int main(int argc, char *argv[])
{
        int rc;
        int ch;
        char sysname[2000];
        size_t namlen = sizeof(sysname);

        bool debug = false;
        bool reboot = false;
        while ((ch = getopt(argc, argv, "drk:b:")) != -1) {
                switch (ch) {
                        case 'd': debug = true;         break;
                        case 'r': reboot = true;        break;
                        case 'k': strncpy(kernelName, optarg,
sizeof(kernelName)); break;
                        case 'b': baseAddress = strtoul(optarg, 0, 0);
break;
                        default: usage(); break;
                }
        }
        argc -= optind;
        argv += optind;

        rc = sysctlbyname("kern.version", sysname, &namlen, NULL,
(size_t) 0);
        if (rc != 0) {
                strerror(errno);
                return (1);
        } else {
                if (namlen >= sizeof(sysname))
                        namlen = sizeof(sysname) - 1;
                sysname[namlen] = '\0';
        }

        if (debug) {
                printf("Kernel name: %s\n", kernelName);
                printf("Base Address: 0x%X\n", baseAddress);
                printf("kern.version: %s", sysname);
        }

        if (strstr(sysname, "BOOT")) {
                char syscmd[2000];
                if (debug)
                        printf("Bootstrap kernel detected.\n");
                if (reboot) {
                        printf("Booting operating kernel: %s\n",
kernelName);
                        snprintf(syscmd, sizeof(syscmd),
"/usr/local/bin/bsdbootloader -b 0x%x %s",
                                baseAddress, kernelName);
                        system(syscmd);
                }
        } else {
                if (debug)
                        printf("Operating kernel detected.\n");
        }

        return (0);
}





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU