From markh@vanbc.wimsey.com Fri Jul  1 22:10:13 EDT 1994
Article: 17069 of comp.sys.sun.misc
Path: babbage.ece.uc.edu!news.kei.com!MathWorks.Com!europa.eng.gtefsd.com!newsxfer.itd.umich.edu!nntp.cs.ubc.ca!torn!uunet.ca!uunet.ca!scipio.cyberstore.ca!vanbc.wimsey.com!vanbc.wimsey.com!not-for-mail
From: markh@vanbc.wimsey.com (Mark C. Henderson)
Newsgroups: alt.sys.sun,alt.sources
Subject: change hostid
Date: 1 Jul 1994 17:32:48 -0700
Organization: Wimsey Information Services
Lines: 1015
Message-ID: <2v2cjg$4rc@vanbc.wimsey.com>
NNTP-Posting-Host: vanbc.wimsey.com
Xref: babbage.ece.uc.edu comp.sys.sun.misc:17069 alt.sources:7557

Here's my latest version (yet another - you cry!). Anyway, I've included
some more detailed information on the NVRAM and how to get at it from
the Openprom monitor as well as from Sun OS 4.1.x. As before this
also includes the "safer" programs to just change the hostid reported
by gethostid/sysinfo by patching the in-core kernel image on 
Sun OS 4.1.x and 5.3.

Thanks to all those who sent suggestions/comments &c and have helped 
me smooth out the rough edges. This will be the last version for a 
while.

USE AT YOUR OWN RISK.

Mark

--------cut here----------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh 'README' <<'END_OF_FILE'
XEver been up at 3am on Monday morning trying to move an essential 
Xapplication from one piece of hardware to another and been unable to 
Xdo it because you'll need a new licence key from your vendor and they 
Xdon't give them out at weird hours? Well, here's a solution that 
Xworks in many cases. Basically it allows you to modify the value 
Xreturned by gethostid/sysinfo for the hostid on Solaris 1.x and 2.3 
X
XPlease don't use these program to steal software. The intended use is 
Xfor emergency situations where an application has to be moved from 
Xone computer to another (e.g. in the event of a hardware malfunction) 
Xand licence keys cannot be obtained quickly from the vendor or when
Xyour NVRAM gets wiped out by some unfortunate accident.
X
XUSE AT YOUR OWN RISK.
X
Xnvram.c is particularly dangerous. Read the comments and proceed with
Xextreme caution. If this program malfunctions or is misused you can get
Xyour NVRAM into a state where you will no longer be able to boot Sun OS.
XUnless you need to modify your NVRAM, I recommend going with the
Xapproach in hid/hid_solaris2.  Reprogramming your NVRAM can be useful
Xwhen it gets wiped out for some reason.
END_OF_FILE
if test 1158 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'hid.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'hid.c'\"
else
echo shar: Extracting \"'hid.c'\" \(3049 characters\)
sed "s/^X//" >'hid.c' <<'END_OF_FILE'
X/* 
X
Xchange hostid reported by Solaris 1.x/SUN OS 4.1.x gethostid
Xrun the script produced by this file 
X 
Xe.g. you could put the following script (produced by hid b0b1fb0b)
X   in /etc/rc.local
X
X#!/bin/sh
X# this script sets the hostid to b0b1bb0b
Xadb -w -k /vmunix /dev/mem <
XPlaced in the public domain by the author - 3 June 1994
X
XThis program is distributed in the hope that it will be useful,
Xbut without any warranty; without even the implied warranty of
Xmerchantability or fitness for a particular purpose. You use
Xthis program at your own risk. The author disclaims responsibility for
Xany damages that might result from the use of this program, even
Xif they result from negligence on the part of the author.
X
XAlso, please don't use this program to steal software. The intended
Xuse is for emergency situations where an application has to be moved from
Xone computer to another (e.g. in the event of a hardware malfunction)
Xand licence keys cannot be obtained quickly from the vendor. Many
Xvendors will not supply licence keys outside of business hours.
X
XBy way of explanation:
X
Xhid produces a script which, when executed on a Solaris 1.x machine
Xwill change the value reported by gethostid to the desired value.  adb
Xis used to alter the in-core kernel image.  No changes are made to the
Xkernel file itself (/vmunix), so rebooting will undo any
Xmodifications.  If you want to permanently change the value returned by
Xgethostid/sysconf, one way to do this is to put the script output
Xby hid in /etc/rc.local
X
XThis overwrites two key instructions in the gethostid routine in the
Xmemory image of the kernel (the kernel itself on disk is NOT modified)
X
Xthe original instructions that are overwritten are
X_gethostid+4:   call    _machineid
X_gethostid+8:   nop
X
XIf you want the hostid
Xb0b1fb0b
Xhid outputs the script
X
Xadb -w -k /vmunix /dev/mem <
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    unsigned int hid;
X    unsigned int hi;
X    unsigned int low;
X
X    if (argc != 2) {
X        fprintf(stderr, "usage: %s hostid\n",argv[0]);
X		fprintf(stderr, "  e.g. %s b0b1fb0b\n", argv[0]);
X        exit(1);
X    }
X    sscanf(argv[1],"%08x",&hid);
X
X    hi = (hid & 0xfffffc00) >> 10;
X
X    printf("#!/bin/sh\n");
X    printf("# this script sets the hostid to %08x\n",hid);
X    printf("adb -w -k /vmunix /dev/mem <'hid_solaris2.c' <<'END_OF_FILE'
X/* change the hostid reported by sysinfo and gethostid on Solaris 2.3
X   - run the script this produces on stdout to actually make the change. Note
X     that you must have adb installed to use this 
X
X	e.g. hid_solaris2 b0b1fb0b | sh -v
X
XMark Henderson 
XPlaced in the public domain by the author - 3 June 1994
X 
XThis program is distributed in the hope that it will be useful,
Xbut without any warranty; without even the implied warranty of
Xmerchantability or fitness for a particular purpose. You use
Xthis program at your own risk. The author disclaims responsibility for
Xany damages that might result from the use of this program, even
Xif they result from negligence on the part of the author.
X
XAlso, please don't use this program to steal software. The intended
Xuse is for emergency situations where an application has to be moved from
Xone computer to another (e.g. in the event of a hardware malfunction)
Xand licence keys cannot be obtained quickly from the vendor. Many
Xvendors will not supply licence keys outside of business hours.
X
XThe hostid is stored in ASCII octal form in the kernel variable
Xhw_serial. We simply change the in-core value of the string pointed
Xto by hw_serial.
X
X*/
X
X#include 
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    unsigned int hid;
X    int i;
X    char obuf[15];
X    for (i=0; i<15; i++)
X        obuf[i] = '\0';
X
X    if (argc != 2) {
X        fprintf(stderr, "usage: %s hostid\n",argv[0]);
X        exit(1);
X    }
X    sscanf(argv[1],"%08x",&hid);
X    sprintf(obuf,"%u", hid);
X
X    printf("#!/bin/sh\n");
X    printf("# this script sets the hostid to %08x\n",hid);
X    printf("adb -w -k /kernel/unix /dev/mem <'nvram.c' <<'END_OF_FILE'
X#include 
X#include 
X#include 
X#include 
X#include 
X#include 
X
X
X/* 
Xget/change hostid in NVRAM --
X
Xonly tested on sun4m architecture and sun4c architecture. The
Xkernel patches will be different for Sun4 and I don't have one
Xto play with. 
X
XIf your particular machine is not supported, you may be able
Xto hack support for the machine into this program.
X
XThis program is still experimental. Dangerous and tricky stuff.
XIf you are unwilling to experiment and clean up after disasters
Xdon't use it.  USE AT YOUR OWN RISK.  If this program malfunctions
Xor it is misused, you can get your Sun into a state where it will
Xnot boot, even from CDROM.
X
XRunning this might invalidate the overall EEPROM checksum. So after it
Xmake some trivial change with the eeprom command (change the baud
Xrate on a serial port or something like that
Xe.g.
X/usr/etc/eeprom diag-switch?=false
X)
X
Xfirst you need to turn off the protection in the OS to keep
Xyou from modifying /dev/eeprom locations after 017730 (or the other offset)
X
Xnvram will try and figure out what your kernel looks like
X
Xon at least some sun4m machines 
Xuse adb
Xadb -k -w /vmunix /dev/mem
X_mmeeprom+8/W 901223ff
X
Xwhich changes
Xor      %o1, 0x3d8, %o1
Xto
Xor      %o1, 0x3ff, %o1
X
X
Xe.g. for some sun4c machines
Xadb -w /vmunix /dev/mem
X_mmeeprom+4/W 80a6a7ff
X_mmeeprom+0x28/W 80a6a7ff
Xwhich changes a couple of compare operations. 
X
XAlso be very careful choosing a new hostid.  The first byte of the
Xhostid identifies the type of system you are running. On modern Suns, OS
Xboot CDs depend on this information to get the correct architecture. If
Xyou change it you may be reduced to poking around in NVRAM from the
Xmonitor next time you have to boot from CD.
X
XHere's a mapping of what gets read into buf (at OFFSET)
Xbuf[0] = always 01?
Xbuf[1] = system id/first byte of hostid.
Xbuf[2] \
Xbuf[3]  \
Xbuf[4]   \  HW ethernet address (6 bytes)
Xbuf[5]    /  
Xbuf[6]  /
Xbuf[7]/
Xbuf[8],...,buf[11] = always 00?
Xbuf[12] = second byte of hostid
Xbuf[13] = third byte of hostid
Xbuf[14] = fourth byte of hostid
Xbuf[15] = checksum
X
Xthe checksum is buf[0] ^ buf[1] ^ ... ^ buf[14]
Xi.e. it must be the case that the  xor of buf[0] through buf[15] is 0
X
XInstructions:
X
X1. First run nvram without any parameters:
XIf it fails with some bizarre error message, then your architecture
Xis not supported. If you don't mind hacking the kernel you can probably
Xhack in support for your architecture.  If you send me mods I'll fold
Xthem in to the distribution.
X
X2. Run nvram again without any parameters.  It just prints out the
Xhostid and hw ethernet address.  Check this against the arp tables on
Xanother machine or against to information displayed on boot. If it is
Xnot correct, do not proceed with the next step.
X
X3. now you can try and modify the hostid by running
Xnvram with the desired hostid as the second parameter (without 0x)
Xe.g.
Xnvram b0b1fb0b
X
X4. Run the eeprom command suggested by the program
X
XMark Henderson 
XPlaced in the public domain by the author - 23 June 1994
X
XThis program is distributed in the hope that it will be useful,
Xbut without any warranty; without even the implied warranty of
Xmerchantability or fitness for a particular purpose. You use
Xthis program at your own risk. The author disclaims responsibility for
Xany damages that might result from the use of this program, even
Xif they result from negligence on the part of the author.
X
XAlso, please don't use this program to steal software. The intended
Xuse is for emergency situations where an application has to be moved from
Xone computer to another (e.g. in the event of a hardware malfunction)
Xand licence keys cannot be obtained quickly from the vendor. Many
Xvendors will not supply licence keys outside of business hours.
X
XSorry about all the legal BS, but given that use of this program is
Xdangerous and inexperienced people will use it, I don't have much choice
Xfrom both an ethical and legal point of view.
X
X*/
X
X
X#define OFFSET1 017730       /* for Sun 4m, Sun OS 4.1.3 */
X#define OFFSET2 03730     /* for Sun 4c, SUN OS 4.1.1 */
X
X#define SANITY_CHECK        /* don't turn this off unless you need to. If this
X                               fails it generally means that the program won't
X                               work and very well may be destructive */
X
X/* #define TEST        /* doesn't actually do mods if TEST is defined */
Xunsigned char buf[17];  /* larger than it needs to be */ 
X
X/* offset table -- in ascending order of magnitude */
Xoff_t offtab[2] = { OFFSET2, OFFSET1 };
X#define nofftab  (sizeof(offtab) / sizeof(off_t))
Xoff_t offset;
X
Xstruct nlist nl[] = { "_mmeeprom" };
Xvoid check_eeprom_driver()
X{
X    int kmem;
X    off_t where;
X    unsigned int kbuf[12];
X    if ((kmem = open("/dev/kmem", O_RDONLY)) < 0) {
X        fprintf(stderr, "cannot open /dev/kmem\n");
X        exit(1);
X    }
X    fprintf(stderr,"nvram - Mark Henderson \n");
X    fprintf(stderr,
X        "Placed in the public domain by the author - 23 June 1994\n\n");
X    fprintf(stderr,
X        "This program is distributed in the hope that it will be useful,\n");
X    fprintf(stderr,
X        "but without any warranty; without even the implied warranty of\n");
X    fprintf(stderr,
X        "merchantability or fitness for a particular purpose. You use\n");
X    fprintf(stderr,
X    "this program at your own risk. The author disclaims responsibility for\n");
X    fprintf(stderr,
X        "any damages that might result from the use of this program, even\n");
X    fprintf(stderr,
X        "if they result from negligence on the part of the author.\n");
X    fprintf(stderr, 
X        "Malfunction or misuse of this program can damage your computer.\n\n");
X    if (nlist("/vmunix", nl) < 0) {
X        fprintf(stderr, "cannot read namelist out of /vmunix\n");
X        exit(1);
X    }
X    if ((where = nl[0].n_value) == 0) {
X        fprintf(stderr, "unknown kernel variable _mmeeprom\n");
X        fprintf(stderr, 
X            "your kernel is strange - nvram modifier won't operate\n");
X        exit(1);
X    }
X    if (lseek(kmem, where, SEEK_SET) == (-1)) {
X        fprintf(stderr, "lseek on /dev/kmem failed\n");
X        fprintf(stderr, 
X            "your kernel is strange - nvram modifier won't operate\n");
X        exit(1);
X    }
X    if (read(kmem, (char *)&kbuf[0], 48) < 48) {
X        fprintf(stderr, "read from /dev/kmem failed\n");
X        fprintf(stderr, 
X            "your kernel is strange - nvram modifier won't operate\n");
X        exit(1);
X    }
X    close(kmem);
X    if (kbuf[1] == 0x80a6a7d8 && kbuf[10] == 0x80a6a7d8) {
X        fprintf(stderr, "please execute the following:\n");
X        fprintf(stderr, 
X            "adb -w -k /vmunix /dev/mem <> 24) )
X            || (buf[12] != ((hid_reported_by_gethostid >> 16) &0xff))
X            || (buf[13] != ((hid_reported_by_gethostid >> 8) &0xff))
X            || (buf[14] != (hid_reported_by_gethostid &0xff))) {
X            continue;
X        }
X        offset = offtab[j];
X        break;
X    }
X    if (offset == 0xffffffff) {
X        fprintf(stderr, "perhaps you have a weird kernel -- failed\n");
X        exit(1);
X    }
X    printf("current hostid = %02x%02x%02x%02x\n", 
X    buf[1], buf[12], buf[13], buf[14]);
X
X    /* may as well print this out */
X    printf("enetaddr       = %02x:%02x:%02x:%02x:%02x:%02x\n", 
X    buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
X    if (!read_hostid) {
X        if (lseek(fd,offset,SEEK_SET) < 0) { 
X            fprintf(stderr, "lseek failed\n");
X            exit(1);
X        }
X
X        buf[1] = hid >> 24;
X        buf[12] = (hid >> 16) &0xff;
X        buf[13] = (hid >> 8) &0xff;
X        buf[14] = hid &0xff;
X        for (acc = 0 , i=0; i<15; i++) acc^=buf[i];
X        buf[15] = acc & 0xff;
X#ifndef TEST
X        if (write(fd,buf,16) < 16) {
X            fprintf(stderr, "write failed\n");
X        }
X#else
X    for (i=0; i<16; i++)
X        printf("%02x ", buf[i]);
X    printf("\n");
X#endif
X    fprintf(stderr, "now please execute the following command\n");
X    fprintf(stderr, "/usr/etc/eeprom 'diag-switch?=false'\n");
X    }
X    close(fd);
X}
X
END_OF_FILE
if test 10987 -ne `wc -c <'nvram.c'`; then
    echo shar: \"'nvram.c'\" unpacked with wrong size!
fi
# end of 'nvram.c'
fi
if test -f 'nvram.info' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nvram.info'\"
else
echo shar: Extracting \"'nvram.info'\" \(6029 characters\)
sed "s/^X//" >'nvram.info' <<'END_OF_FILE'
XUSE THIS AT YOUR OWN RISK. IF THIS INFORMATION IS ABUSED OR INCORRECT
XYOU CAN RENDER YOUR COMPUTER UNBOOTABLE AND MY BET IS THAT SUN WILL
XCHARGE A LOT OF MONEY TO FIX THE DAMAGE.
X
XBe careful, mistakes can cost a lot.
X
XThe information in this document is distributed in the hope that 
Xit will be useful, but without any warranty; without even the 
Ximplied warranty of merchantability or fitness for a particular 
Xpurpose. You use this document at your own risk. The author 
Xdisclaims responsibility for any damages that might result from the 
Xuse of this document, even if they result from negligence or errors 
Xon the part of the author.
X
XPlaced in the public domain by the author - 1 July 1994
X- Mark Henderson 
X
X
XAll numbers in here are in hex.
X
XHere's some information on changing the NVRAM from the Forth based Sun 
XOpenprom monitor. Consider this a beta release. Eventually I'll probably
Xsubmit it to the folks who put out the nvram faq, but for now this
Xis a seperate document. Also, there is the really nice nvram FAQ which
Xis posted to comp.sys.sun.hardware routinely.
X
XAs far as I know, this is only applicable to Sun4m and Sun4c class
Xmachines.  If you have a copy of the Sun Openprom manual (you can get it
Xoff the Solaris 2.3 answerbook), it might be handy to have that on hand
Xas a reference.
X
XThese steps are not the shorted path to getting this changed.  Take a
Xlook at nvram.c if you are just interested in modifying your NVRAM
Xhostid, are running Sun OS 4.1.x and don't care about the details. This
Xinformation might also be useful in putting things back together if
Xnvram.c malfunctions.
X
XBefore doing anything else, write down a copy of the nvram "idprom" 
Xinformation. You can get it under Sun OS 4.1.x by running 
X/usr/etc/devinfo -vp  or at the Openprom monitor prompt by typing
Xthe command
X.idprom
X
XStep 1.
XDetermine the physical address of the NVRAM (in the case of Sun4m machines
XI'm interested in the second page). If you're system is on this table you 
Xcan probably just read it off the table and skip to step 2.
X
X                addr        space       arch
XSun ELC         02000000    obio        sun4c
XSun Classic     71201000    0           sun4m
XSun SS20        f1201000    f           sun4m
X
XHopefully this table will get larger as people send me info.
X
XIf not, proceed as follows (you must be running Sun OS 4.1.x for this):
X
XWhile Sun OS 4.1.x is running (and while the system is idle!!) do the 
Xfollowing. Modify the instructions accordingly if you have some of 
Xthe security features installed.
X
Xhold down the L1/Stop key and type a 
Xyou will get a prompt which says
Xok
X
XFor Sun4m machines:
Xtype the command
Xfefff000 pgmap?
X
Xthe output will list a physical address which might look like
Xf.f120.1000
X
Xthe part before the first dot is the address space and the rest is
Xthe actual address. This is the SS20 case from the above table.
X
XNow type 
Xgo
Xto resume Sun OS operation.
X
XFor Sun4c machines:
Xtype the command
Xffff8000 pgmap?
X
Xthe physical address will probably list a space (in the ELC case the
Xaddress space is given as I/O) and an address (again for the ELC
X02000000).
X
Xthe monitor will want you to type in this address space as obio
Xlater. The Sun Openprom manual also gives sbus and obmem as possible
Xaddress spaces.
X
XNow type
Xgo
Xto resume Sun OS operation.
X
XAt this point if you're really nice, you'll send me an Email message
Xwith your Sun model and physical address/address space so I can add it 
Xto my table. (Indicate whether or not you want me to give credit in
Xthe table.)
X
X
X2. From this point on it doesn't matter what version of Solaris you
Xare running.
X
XShut down  your system (e.g. with /etc/halt)
X
X3. Make sure you wrote down your original idprom info. You can 
Xget it by typing .idprom now. 
X
XFigure out what your desired hostid and ethernet address are. Note that
Xyou shouldn't change either the first hex byte of the hostid or the
Xfirst three bytes of the ethernet address. Doing so can cause problems.
X
X4. Map the physical address determined above to address 0 using
Xthe map-page command. The format of the command is:
X
X  
map-page X Xe.g. ELC 71201000 obio 0 map-page X SS20 f1201000 f 0 map-page X Classic 71201000 0 0 map-page X X5. XIf you are on a Sun4c the virtual address of the idprom information is now 7d8 XIf you are on a Sun4m the virtual address of the idprom information is now fd8 X Xtype either X7d8 20 dump Xfor sun4c Xor Xfd8 20 dump Xfor sun4m X Xas appropriate. X X6. The information which starts at f/7d8 is as follows: Xbyte contents Xd8 01 Xd9 first byte of hostid (system type) Xda-df 6 byte ethernet address (first three bytes are 08,00,20) Xe0-e3 date of manufacture. Often all 0s Xe4 second byte of hostid Xe5 third byte of hostid Xe6 fourth byte of hostid Xe7 idprom checksum - xor of contents of bytes d8-e6 X XVerify that the information the dump command spits out is consistent Xwith the above. If not, DO NOT PROCEED. X X7. Now you can make changes. Be very careful and be sure to recompute Xthe checksum after making changes. If you don't, you'll get nasty Xwarnings about an incorrect idprom checksum on boot. I'm know repeating Xmyself, but don't change the first byte of the hostid or the first three Xbytes of the ethernet address. I'm told that the first byte of the Xhostid is used to determine the architecture when booting from CDROM on Xmost current Sun models. If you alter the first three bytes of the Xethernet address you might get message which say that you have a Xdefective motherboard (but then I don't know of any other consequences Xof changing this to some _reasonable_ value, especially avoid Xff:ff:ff:ff:ff:ff !) X XThe openprom command to change a single byte is X X c! Xe.g. X44 7dd c! Xwill change byte 7dd (virtual address) to 44. X X7d8 20 dump Xor Xfd8 20 dump Xwill give you a listing of this area of NVRAM. X X X8. Type reset at the ok prompt. You should then reboot with your new Xhostid/enet addr. X END_OF_FILE if test 6029 -ne `wc -c <'nvram.info'`; then echo shar: \"'nvram.info'\" unpacked with wrong size! fi # end of 'nvram.info' fi if test -f 'nvram_old.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'nvram_old.c'\" else echo shar: Extracting \"'nvram_old.c'\" \(6784 characters\) sed "s/^X//" >'nvram_old.c' <<'END_OF_FILE' X#include X#include X#include X X/* Xget/change hostid in NVRAM -- X Xold version -- I should throw this away. Less friendly but perhaps X easier to modify for other types of machines. X Xonly tested on sun4m architecture and sun4c architecture. The Xkernel patches will be different for Sun4 and I don't have one Xto play with. X XThis program is still experimental. Dangerous and tricky stuff. XIf you are unwilling to experiment and clean up after disasters Xdon't use it. hid is probably safer. USE AT YOUR OWN RISK. X XNote the define OFFSET below! X Xrunning this will invalidate the overall NVRAM checksum. So after it Xmake some trivial change with the eeprom command (change the baud Xrate on a serial port or something like that Xe.g. X/usr/etc/eeprom diag-switch?=false X) X Xfirst you need to turn off the protection in the OS to keep Xyou from modifying /dev/eeprom locations after 017730 Xuse adb Xadb -k -w /vmunix /dev/mem X_mmeeprom+8/W 901223ff X Xwhich changes Xor %o1, 0x3d8, %o1 Xto Xor %o1, 0x3ff, %o1 X X XUnfortunately this change with adb to the eeprom device seems to depend Xon the exact version of Sun OS you are running. Don't assume it will Xwork without looking around intelligently. X Xe.g. For SUN OS 4.1.1 on a Sun 4c you need to: Xadb -w /vmunix /dev/mem X_mmeeprom+4/W 80a6a7ff X_mmeeprom+0x28/W 80a6a7ff Xwhich changes a couple of compare operations. X XAlso be very careful. The first byte of the hostid identifies the type Xof system you are running. On modern Suns OS boot CDs depend on this Xinformation to get the correct architecture. If you change it you may Xbe reduced to poking around in NVRAM from the monitor next time you have Xto boot from CD. X XHere's a mapping of what gets read into buf (at OFFSET) Xbuf[0] = always 01? Xbuf[1] = system id/first byte of hostid. Xbuf[2] \ Xbuf[3] \ Xbuf[4] \ HW ethernet address (6 bytes) Xbuf[5] / Xbuf[6] / Xbuf[7]/ Xbuf[8],...,buf[11] = always 00? Xbuf[12] = second byte of hostid Xbuf[13] = third byte of hostid Xbuf[14] = fourth byte of hostid Xbuf[15] = checksum X Xthe checksum is buf[0] ^ buf[1] ^ ... ^ buf[14] Xi.e. it must be the case that the xor of buf[0] through buf[15] is 0 X XWithout any parameters, it reports the hostid from NVRAM. Otherwise it Xchanges it. X XMark Henderson XPlaced in the public domain by the author - 23 June 1994 X XThis program is distributed in the hope that it will be useful, Xbut without any warranty; without even the implied warranty of Xmerchantability or fitness for a particular purpose. You use Xthis program at your own risk. The author disclaims responsibility for Xany damages that might result from the use of this program, even Xif they result from negligence on the part of the author. X XAlso, please don't use this program to steal software. The intended Xuse is for emergency situations where an application has to be moved from Xone computer to another (e.g. in the event of a hardware malfunction) Xand licence keys cannot be obtained quickly from the vendor. Many Xvendors will not supply licence keys outside of business hours. X X*/ X X X#define OFFSET 017730 /* for Sun 4m, Sun OS 4.1.3 */ X/* #define OFFSET 03730 /* for Sun 4c, SUN OS 4.1.1 */ X X#define SANITY_CHECK /* don't turn this off unless you need to. If this X fails it generally means that the program won't X work and very well may be destructive */ X X#undef TEST /* doesn't actually do mods if TEST is defined */ Xunsigned char buf[17]; X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X unsigned int hid; X int fd; X int i; X unsigned int acc; X int read_hostid; X unsigned int hid_reported_by_gethostid = gethostid(); X X if (argc == 1) { X /* no args - just get hostid from prom */ X read_hostid = 1; X } X else if (argc == 2) { X read_hostid = 0; X sscanf(argv[1],"%08x",&hid); X } X else { X fprintf(stderr, "usage: %s [hostid]\n",argv[0]); X fprintf(stderr, " e.g. %s b0b1fb0b\n", argv[0]); X exit(1); X } X if (read_hostid) { X if ((fd = open("/dev/eeprom", O_RDONLY)) < 0) { X fprintf(stderr, "cannot open /dev/eeprom for read\n"); X exit(1); X } X } X else { X#ifdef TEST X if ((fd = open("/dev/eeprom", O_RDONLY)) < 0) { X fprintf(stderr, "cannot open /dev/eeprom for read\n"); X exit(1); X } X#else X if ((fd = open("/dev/eeprom", O_RDWR)) < 0) { X fprintf(stderr, "cannot open /dev/eeprom for read\n"); X exit(1); X } X#endif X } X X if (lseek(fd,OFFSET,SEEK_SET) < 0) { X fprintf(stderr, "lseek failed\n"); X exit(1); X } X X if (read_hostid) { X if (read(fd,buf,16) < 16) { X fprintf(stderr, "read of /dev/eeprom failed\n"); X exit(1); X } X printf("%02x%02x%02x%02x\n", buf[1], buf[12], buf[13], buf[14]); X for (acc = 0 , i=0; i<15; i++) acc^=buf[i]; X if (acc != buf[15]) { X fprintf(stderr, "warning: ID CHKSUM INVALID\n"); X fprintf(stderr,"^buf = %02x\n", acc & 0xff); X fprintf(stderr,"buf[15] = %02x\n", buf[15] & 0xff); X } X } X else { X#ifdef SANITY_CHECK X/* this will fail if you have modified the value returned by X gethostid by using one of the other programs in this package. X In that case I wouldn't turn this off but restore your old X gethostid behaviour or replace the gethostid call above with X a reference to your "real" hostid, if your architecture X is weird this should detect the problem and not try and X write into places we shouldn't. */ X X if (read(fd,buf,16) < 16) { X fprintf(stderr, "read of /dev/eeprom failed\n"); X exit(1); X } X#ifdef TEST X for (i=0; i<16; i++) X printf("%02x ", buf[i]); X printf("\n"); X#endif X for (acc = 0 , i=0; i<15; i++) acc^=buf[i]; X if ((acc != buf[15]) X || (buf[1] != (hid_reported_by_gethostid >> 24) ) X || (buf[12] != ((hid_reported_by_gethostid >> 16) &0xff)) X || (buf[13] != ((hid_reported_by_gethostid >> 8) &0xff)) X || (buf[14] != (hid_reported_by_gethostid &0xff))) { X X fprintf(stderr, "SANITY CHECK FAILED -- aborting\n"); X fprintf(stderr, X "perhaps the value of the define OFFSET is wrong\n"); X exit(1); X } X X if (lseek(fd,OFFSET,SEEK_SET) < 0) { X fprintf(stderr, "lseek failed\n"); X exit(1); X } X X#endif X buf[1] = hid >> 24; X buf[12] = (hid >> 16) &0xff; X buf[13] = (hid >> 8) &0xff; X buf[14] = hid &0xff; X for (acc = 0 , i=0; i<15; i++) acc^=buf[i]; X buf[15] = acc & 0xff; X#ifndef TEST X if (write(fd,buf,16) < 16) { X fprintf(stderr, "write failed\n"); X } X#else X for (i=0; i<16; i++) X printf("%02x ", buf[i]); X printf("\n"); X X#endif X } X close(fd); X} X END_OF_FILE if test 6784 -ne `wc -c <'nvram_old.c'`; then echo shar: \"'nvram_old.c'\" unpacked with wrong size! fi # end of 'nvram_old.c' fi echo shar: End of shell archive. exit 0 --------cut here---------- -- Mark Henderson markh@wimsey.bc.ca - RIPEM MD5: F1F5F0C3984CBEAF3889ADAFA2437433 ViaCrypt PGP key fingerprint: 21 F6 AF 2B 6A 8A 0B E1 A1 2A 2A 06 4A D5 92 46 low security key fingerprint: EC E7 C3 A9 2C 30 25 C6 F9 E1 25 F3 F5 AF 92 E3 cryptography archive maintainer -- anon ftp to ftp.wimsey.bc.ca:/pub/crypto