1 /* Adapted from Etherboot 5.1.8 */
4 #include "sysinclude.h"
8 #include "libopenbios/ipchecksum.h"
9 #include "libopenbios/sys_info.h"
11 #ifdef CONFIG_DEBUG_BOOT
17 #define for_each_lbrec(head, rec) \
18 for(rec = (struct lb_record *)(((char *)head) + sizeof(*head)); \
19 (((char *)rec) < (((char *)head) + sizeof(*head) + head->table_bytes)) && \
21 ((((char *)rec) + rec->size) <= (((char *)head) + sizeof(*head) + head->table_bytes)); \
22 rec = (struct lb_record *)(((char *)rec) + rec->size))
24 static void convert_memmap(struct lb_memory
*lbmem
, struct sys_info
*info
)
29 lbcount
= lbmem
->size
/ sizeof(struct lb_memory_range
);
30 info
->memrange
= malloc(lbcount
* sizeof(struct memrange
));
31 info
->n_memranges
= 0;
32 for (i
= 0; i
< lbcount
; i
++) {
33 debug("%#016llx %#016llx %d\n",
34 (long long)lbmem
->map
[i
].start
, (long long)lbmem
->map
[i
].size
,
35 (int) lbmem
->map
[i
].type
);
36 if (lbmem
->map
[i
].type
!= LB_MEM_RAM
)
38 info
->memrange
[info
->n_memranges
].base
= lbmem
->map
[i
].start
;
39 info
->memrange
[info
->n_memranges
].size
= lbmem
->map
[i
].size
;
44 static int read_lbtable(struct lb_header
*head
, struct sys_info
*info
)
48 /* Read linuxbios tables... */
49 struct lb_record
*rec
;
51 for_each_lbrec(head
, rec
) {
54 convert_memmap((struct lb_memory
*) rec
, info
);
62 static unsigned long count_lb_records(void *start
, unsigned long length
)
64 struct lb_record
*rec
;
68 end
= ((char *)start
) + length
;
69 for(rec
= start
; ((void *)rec
< end
) &&
70 ((signed long)rec
->size
<=
71 ((signed long)end
- (signed long)rec
));
72 rec
= (void *)(((char *)rec
) + rec
->size
)) {
78 static int find_lb_table(void *start
, void *end
, struct lb_header
**result
)
81 /* For now be stupid.... */
82 for(ptr
= start
; (void *)ptr
< end
; ptr
+= 16) {
83 struct lb_header
*head
= (struct lb_header
*)ptr
;
84 if ( (head
->signature
[0] != 'L') ||
85 (head
->signature
[1] != 'B') ||
86 (head
->signature
[2] != 'I') ||
87 (head
->signature
[3] != 'O')) {
90 if (head
->header_bytes
!= sizeof(*head
))
92 debug("Found canidate at: %p\n", head
);
93 if (ipchksum((uint16_t *)head
, sizeof(*head
)) != 0)
95 debug("header checksum o.k.\n");
96 if (ipchksum((uint16_t *)(ptr
+ sizeof(*head
)), head
->table_bytes
) !=
97 head
->table_checksum
) {
100 debug("table checksum o.k.\n");
101 if (count_lb_records(ptr
+ sizeof(*head
), head
->table_bytes
) !=
102 head
->table_entries
) {
105 debug("record count o.k.\n");
112 void collect_linuxbios_info(struct sys_info
*info
)
114 struct lb_header
*lb_table
;
116 debug("Searching for LinuxBIOS tables...\n");
119 found
= find_lb_table(phys_to_virt(0x00000), phys_to_virt(0x01000), &lb_table
);
122 found
= find_lb_table(phys_to_virt(0xf0000), phys_to_virt(0x100000), &lb_table
);
127 debug("Found LinuxBIOS table at: %p\n", lb_table
);
128 info
->firmware
= "LinuxBIOS";
129 read_lbtable(lb_table
, info
);