1*c6363baeSThomas Huth #ifndef SUN_NVRAM_H
2*c6363baeSThomas Huth #define SUN_NVRAM_H
3*c6363baeSThomas Huth
4*c6363baeSThomas Huth /* Sun IDPROM structure at the end of NVRAM */
5*c6363baeSThomas Huth /* from http://www.squirrel.com/squirrel/sun-nvram-hostid.faq.html */
6*c6363baeSThomas Huth struct Sun_nvram {
7*c6363baeSThomas Huth uint8_t type; /* always 01 */
8*c6363baeSThomas Huth uint8_t machine_id; /* first byte of host id (machine type) */
9*c6363baeSThomas Huth uint8_t macaddr[6]; /* 6 byte ethernet address (first 3 bytes 08, 00, 20) */
10*c6363baeSThomas Huth uint8_t date[4]; /* date of manufacture */
11*c6363baeSThomas Huth uint8_t hostid[3]; /* remaining 3 bytes of host id (serial number) */
12*c6363baeSThomas Huth uint8_t checksum; /* bitwise xor of previous bytes */
13*c6363baeSThomas Huth };
14*c6363baeSThomas Huth
15*c6363baeSThomas Huth static inline void
Sun_init_header(struct Sun_nvram * header,const uint8_t * macaddr,int machine_id)16*c6363baeSThomas Huth Sun_init_header(struct Sun_nvram *header, const uint8_t *macaddr, int machine_id)
17*c6363baeSThomas Huth {
18*c6363baeSThomas Huth uint8_t tmp, *tmpptr;
19*c6363baeSThomas Huth unsigned int i;
20*c6363baeSThomas Huth
21*c6363baeSThomas Huth header->type = 1;
22*c6363baeSThomas Huth header->machine_id = machine_id & 0xff;
23*c6363baeSThomas Huth memcpy(&header->macaddr, macaddr, 6);
24*c6363baeSThomas Huth memcpy(&header->hostid , &macaddr[3], 3);
25*c6363baeSThomas Huth
26*c6363baeSThomas Huth /* Calculate checksum */
27*c6363baeSThomas Huth tmp = 0;
28*c6363baeSThomas Huth tmpptr = (uint8_t *)header;
29*c6363baeSThomas Huth for (i = 0; i < 15; i++)
30*c6363baeSThomas Huth tmp ^= tmpptr[i];
31*c6363baeSThomas Huth
32*c6363baeSThomas Huth header->checksum = tmp;
33*c6363baeSThomas Huth }
34*c6363baeSThomas Huth #endif /* SUN_NVRAM_H */
35