root / hw / firmware_abi.h @ b4b784fe
History | View | Annotate | Download (1.8 kB)
1 | d2c63fc1 | blueswir1 | #ifndef FIRMWARE_ABI_H
|
---|---|---|---|
2 | d2c63fc1 | blueswir1 | #define FIRMWARE_ABI_H
|
3 | d2c63fc1 | blueswir1 | |
4 | d2c63fc1 | blueswir1 | /* OpenBIOS NVRAM partition */
|
5 | d2c63fc1 | blueswir1 | struct OpenBIOS_nvpart_v1 {
|
6 | d2c63fc1 | blueswir1 | uint8_t signature; |
7 | d2c63fc1 | blueswir1 | uint8_t checksum; |
8 | d2c63fc1 | blueswir1 | uint16_t len; // BE, length divided by 16
|
9 | d2c63fc1 | blueswir1 | char name[12]; |
10 | d2c63fc1 | blueswir1 | }; |
11 | d2c63fc1 | blueswir1 | |
12 | d2c63fc1 | blueswir1 | #define OPENBIOS_PART_SYSTEM 0x70 |
13 | d2c63fc1 | blueswir1 | #define OPENBIOS_PART_FREE 0x7f |
14 | d2c63fc1 | blueswir1 | |
15 | d2c63fc1 | blueswir1 | static inline void |
16 | d2c63fc1 | blueswir1 | OpenBIOS_finish_partition(struct OpenBIOS_nvpart_v1 *header, uint32_t size)
|
17 | d2c63fc1 | blueswir1 | { |
18 | d2c63fc1 | blueswir1 | unsigned int i, sum; |
19 | d2c63fc1 | blueswir1 | uint8_t *tmpptr; |
20 | d2c63fc1 | blueswir1 | |
21 | d2c63fc1 | blueswir1 | // Length divided by 16
|
22 | d2c63fc1 | blueswir1 | header->len = cpu_to_be16(size >> 4);
|
23 | d2c63fc1 | blueswir1 | |
24 | d2c63fc1 | blueswir1 | // Checksum
|
25 | d2c63fc1 | blueswir1 | tmpptr = (uint8_t *)header; |
26 | d2c63fc1 | blueswir1 | sum = *tmpptr; |
27 | d2c63fc1 | blueswir1 | for (i = 0; i < 14; i++) { |
28 | d2c63fc1 | blueswir1 | sum += tmpptr[2 + i];
|
29 | d2c63fc1 | blueswir1 | sum = (sum + ((sum & 0xff00) >> 8)) & 0xff; |
30 | d2c63fc1 | blueswir1 | } |
31 | d2c63fc1 | blueswir1 | header->checksum = sum & 0xff;
|
32 | d2c63fc1 | blueswir1 | } |
33 | d2c63fc1 | blueswir1 | |
34 | d2c63fc1 | blueswir1 | static inline uint32_t |
35 | e7fb1406 | blueswir1 | OpenBIOS_set_var(uint8_t *nvram, uint32_t addr, const char *str) |
36 | d2c63fc1 | blueswir1 | { |
37 | d2c63fc1 | blueswir1 | uint32_t len; |
38 | d2c63fc1 | blueswir1 | |
39 | d2c63fc1 | blueswir1 | len = strlen(str) + 1;
|
40 | d2c63fc1 | blueswir1 | memcpy(&nvram[addr], str, len); |
41 | d2c63fc1 | blueswir1 | |
42 | d2c63fc1 | blueswir1 | return addr + len;
|
43 | d2c63fc1 | blueswir1 | } |
44 | d2c63fc1 | blueswir1 | |
45 | d2c63fc1 | blueswir1 | /* Sun IDPROM structure at the end of NVRAM */
|
46 | 64a7fde8 | blueswir1 | /* from http://www.squirrel.com/squirrel/sun-nvram-hostid.faq.html */
|
47 | d2c63fc1 | blueswir1 | struct Sun_nvram {
|
48 | 64a7fde8 | blueswir1 | uint8_t type; /* always 01 */
|
49 | 64a7fde8 | blueswir1 | uint8_t machine_id; /* first byte of host id (machine type) */
|
50 | 64a7fde8 | blueswir1 | uint8_t macaddr[6]; /* 6 byte ethernet address (first 3 bytes 08, 00, 20) */ |
51 | 64a7fde8 | blueswir1 | uint8_t date[4]; /* date of manufacture */ |
52 | 64a7fde8 | blueswir1 | uint8_t hostid[3]; /* remaining 3 bytes of host id (serial number) */ |
53 | 64a7fde8 | blueswir1 | uint8_t checksum; /* bitwise xor of previous bytes */
|
54 | d2c63fc1 | blueswir1 | }; |
55 | d2c63fc1 | blueswir1 | |
56 | d2c63fc1 | blueswir1 | static inline void |
57 | d2c63fc1 | blueswir1 | Sun_init_header(struct Sun_nvram *header, const uint8_t *macaddr, int machine_id) |
58 | d2c63fc1 | blueswir1 | { |
59 | d2c63fc1 | blueswir1 | uint8_t tmp, *tmpptr; |
60 | d2c63fc1 | blueswir1 | unsigned int i; |
61 | d2c63fc1 | blueswir1 | |
62 | d2c63fc1 | blueswir1 | header->type = 1;
|
63 | d2c63fc1 | blueswir1 | header->machine_id = machine_id & 0xff;
|
64 | d2c63fc1 | blueswir1 | memcpy(&header->macaddr, macaddr, 6);
|
65 | d2c63fc1 | blueswir1 | /* Calculate checksum */
|
66 | d2c63fc1 | blueswir1 | tmp = 0;
|
67 | d2c63fc1 | blueswir1 | tmpptr = (uint8_t *)header; |
68 | d2c63fc1 | blueswir1 | for (i = 0; i < 15; i++) |
69 | d2c63fc1 | blueswir1 | tmp ^= tmpptr[i]; |
70 | d2c63fc1 | blueswir1 | |
71 | d2c63fc1 | blueswir1 | header->checksum = tmp; |
72 | d2c63fc1 | blueswir1 | } |
73 | d2c63fc1 | blueswir1 | #endif /* FIRMWARE_ABI_H */ |