firmware_abi.h 1.8 KB

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