1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Erwan Velu - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
33 #include "syslinux/config.h"
34 #include "../lib/sys/vesa/vesa.h"
35 #include "hdt-common.h"
36 #include <disk/util.h>
37 #include <disk/mbrs.h>
40 /* ISOlinux requires a 8.3 format */
41 void convert_isolinux_filename(char *filename
, struct s_hardware
*hardware
)
43 /* Exit if we are not running ISOLINUX */
44 if (hardware
->sv
->filesystem
!= SYSLINUX_FS_ISOLINUX
)
46 /* Searching the dot */
47 char *dot
= strchr(filename
, '.');
48 /* Exiting if no dot exists in that string */
51 /* Exiting if the extension is 3 char or less */
55 /* We have an extension bigger than .blah
56 * so we have to shorten it to 3*/
60 void detect_parameters(const int argc
, const char *argv
[],
61 struct s_hardware
*hardware
)
63 /* Quiet mode - make the output more quiet */
66 /* Silent mode - make not output at all */
69 /* Vesa mode isn't set until we explictly call it */
72 /* Automode isn't the default*/
75 /* Menu mode is the default*/
78 for (int i
= 1; i
< argc
; i
++) {
79 if (!strncmp(argv
[i
], "quiet", 5)) {
81 } else if (!strncmp(argv
[i
], "silent", 6)) {
83 } else if (!strncmp(argv
[i
], "verbose", 7)) {
85 } else if (!strncmp(argv
[i
], "modules_pcimap=", 15)) {
86 strlcpy(hardware
->modules_pcimap_path
, argv
[i
] + 15,
87 sizeof(hardware
->modules_pcimap_path
));
88 convert_isolinux_filename(hardware
->modules_pcimap_path
, hardware
);
89 } else if (!strncmp(argv
[i
], "pciids=", 7)) {
90 strlcpy(hardware
->pciids_path
, argv
[i
] + 7,
91 sizeof(hardware
->pciids_path
));
92 convert_isolinux_filename(hardware
->pciids_path
, hardware
);
93 } else if (!strncmp(argv
[i
], "modules_alias=", 14)) {
94 strlcpy(hardware
->modules_alias_path
, argv
[i
] + 14,
95 sizeof(hardware
->modules_alias_path
));
96 convert_isolinux_filename(hardware
->modules_alias_path
, hardware
);
97 } else if (!strncmp(argv
[i
], "memtest=", 8)) {
98 strlcpy(hardware
->memtest_label
, argv
[i
] + 8,
99 sizeof(hardware
->memtest_label
));
100 convert_isolinux_filename(hardware
->memtest_label
, hardware
);
101 } else if (!strncmp(argv
[i
], "vesa", 4)) {
103 max_console_lines
= MAX_VESA_CLI_LINES
;
104 /* If the user defines a background image */
105 if (!strncmp(argv
[i
], "vesa=", 5)) {
106 strlcpy(hardware
->vesa_background
, argv
[i
] + 5,
107 sizeof(hardware
->vesa_background
));
109 } else if (!strncmp(argv
[i
], "novesa", 6)) {
111 max_console_lines
= MAX_CLI_LINES
;
112 } else if (!strncmp(argv
[i
], "nomenu", 6)) {
114 } else if (!strncmp(argv
[i
], "dump_filename=", 14)) {
115 strlcpy(hardware
->dump_filename
, argv
[i
] + 14,
116 sizeof(hardware
->dump_filename
));
117 } else if (!strncmp(argv
[i
], "dump_path=", 10)) {
118 strlcpy(hardware
->dump_path
, argv
[i
] + 10,
119 sizeof(hardware
->dump_path
));
120 } else if (!strncmp(argv
[i
], "tftp_ip=", 8)) {
121 strlcpy(hardware
->tftp_ip
, argv
[i
] + 8,
122 sizeof(hardware
->tftp_ip
));
123 } else if (!strncmp(argv
[i
], "postexec=", 9)) {
124 /* The postexec= parameter is separated in several argv[]
125 * as it can contains spaces.
126 * We use the AUTO_DELIMITER char to define the limits
128 * i.e postexec='linux memtest.bin'
131 char *argument
= (char*)argv
[i
]+10;
132 /* Extracting the first parameter */
133 strcpy(hardware
->postexec
, argument
);
135 /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */
136 while ((strchr(argument
, AUTO_DELIMITER
) == NULL
) && (i
+1<argc
)) {
138 argument
= (char *)argv
[i
];
139 strcat(hardware
->postexec
, " ");
140 strcat(hardware
->postexec
, argument
);
143 hardware
->postexec
[strlen(hardware
->postexec
) - 1] = 0;
144 } else if (!strncmp(argv
[i
], "auto=", 5)) {
145 /* The auto= parameter is separated in several argv[]
146 * as it can contains spaces.
147 * We use the AUTO_DELIMITER char to define the limits
149 * i.e auto='show dmi; show pci'
153 char *argument
= (char*)argv
[i
]+6;
154 /* Extracting the first parameter */
155 strcpy(hardware
->auto_label
, argument
);
157 /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */
158 while ((strchr(argument
, AUTO_DELIMITER
) == NULL
) && (i
+1<argc
)) {
160 argument
= (char *)argv
[i
];
161 strcat(hardware
->auto_label
, " ");
162 strcat(hardware
->auto_label
, argument
);
165 hardware
->auto_label
[strlen(hardware
->auto_label
) - 1] = 0;
170 void detect_syslinux(struct s_hardware
*hardware
)
172 hardware
->sv
= syslinux_version();
173 switch (hardware
->sv
->filesystem
) {
174 case SYSLINUX_FS_SYSLINUX
:
175 strlcpy(hardware
->syslinux_fs
, "SYSlinux", 9);
177 case SYSLINUX_FS_PXELINUX
:
178 strlcpy(hardware
->syslinux_fs
, "PXElinux", 9);
180 case SYSLINUX_FS_ISOLINUX
:
181 strlcpy(hardware
->syslinux_fs
, "ISOlinux", 9);
183 case SYSLINUX_FS_EXTLINUX
:
184 strlcpy(hardware
->syslinux_fs
, "EXTlinux", 9);
186 case SYSLINUX_FS_UNKNOWN
:
188 strlcpy(hardware
->syslinux_fs
, "Unknown Bootloader",
189 sizeof hardware
->syslinux_fs
);
194 void init_hardware(struct s_hardware
*hardware
)
196 hardware
->pci_ids_return_code
= 0;
197 hardware
->modules_pcimap_return_code
= 0;
198 hardware
->modules_alias_return_code
= 0;
199 hardware
->cpu_detection
= false;
200 hardware
->pci_detection
= false;
201 hardware
->disk_detection
= false;
202 hardware
->disks_count
= 0;
203 hardware
->dmi_detection
= false;
204 hardware
->pxe_detection
= false;
205 hardware
->vesa_detection
= false;
206 hardware
->vpd_detection
= false;
207 hardware
->memory_detection
= false;
208 hardware
->acpi_detection
= false;
209 hardware
->nb_pci_devices
= 0;
210 hardware
->is_dmi_valid
= false;
211 hardware
->is_pxe_valid
= false;
212 hardware
->is_vpd_valid
= false;
213 hardware
->is_acpi_valid
= false;
214 hardware
->pci_domain
= NULL
;
215 hardware
->detected_memory_size
= 0;
216 hardware
->physical_cpu_count
=1; /* we have at least one cpu */
218 /* Cleaning structures */
219 memset(hardware
->disk_info
, 0, sizeof(hardware
->disk_info
));
220 memset(hardware
->mbr_ids
, 0, sizeof(hardware
->mbr_ids
));
221 memset(&hardware
->dmi
, 0, sizeof(s_dmi
));
222 memset(&hardware
->cpu
, 0, sizeof(s_cpu
));
223 memset(&hardware
->pxe
, 0, sizeof(struct s_pxe
));
224 memset(&hardware
->vesa
, 0, sizeof(struct s_vesa
));
225 memset(&hardware
->vpd
, 0, sizeof(s_vpd
));
226 memset(&hardware
->acpi
, 0, sizeof(s_acpi
));
227 memset(hardware
->syslinux_fs
, 0, sizeof hardware
->syslinux_fs
);
228 memset(hardware
->pciids_path
, 0, sizeof hardware
->pciids_path
);
229 memset(hardware
->modules_pcimap_path
, 0,
230 sizeof hardware
->modules_pcimap_path
);
231 memset(hardware
->modules_alias_path
, 0,
232 sizeof hardware
->modules_alias_path
);
233 memset(hardware
->memtest_label
, 0, sizeof hardware
->memtest_label
);
234 memset(hardware
->auto_label
, 0, sizeof hardware
->auto_label
);
235 memset(hardware
->dump_path
, 0, sizeof hardware
->dump_path
);
236 memset(hardware
->dump_filename
, 0, sizeof hardware
->dump_filename
);
237 memset(hardware
->vesa_background
, 0, sizeof hardware
->vesa_background
);
238 memset(hardware
->tftp_ip
, 0, sizeof hardware
->tftp_ip
);
239 memset(hardware
->postexec
, 0, sizeof hardware
->postexec
);
240 strcat(hardware
->dump_path
, "hdt");
241 strcat(hardware
->dump_filename
, "%{m}+%{p}+%{v}");
242 strcat(hardware
->pciids_path
, "pci.ids");
243 strcat(hardware
->modules_pcimap_path
, "modules.pcimap");
244 strcat(hardware
->modules_alias_path
, "modules.alias");
245 strcat(hardware
->memtest_label
, "memtest");
246 strlcpy(hardware
->vesa_background
, CLI_DEFAULT_BACKGROUND
,
247 sizeof(hardware
->vesa_background
));
251 * Detecting if a DMI table exist
252 * if yes, let's parse it
254 int detect_dmi(struct s_hardware
*hardware
)
256 if (hardware
->dmi_detection
== true)
258 hardware
->dmi_detection
= true;
259 if (dmi_iterate(&hardware
->dmi
) == -ENODMITABLE
) {
260 hardware
->is_dmi_valid
= false;
264 parse_dmitable(&hardware
->dmi
);
265 hardware
->is_dmi_valid
= true;
271 * if yes, let's parse it
273 int detect_acpi(struct s_hardware
*hardware
)
276 if (hardware
->acpi_detection
== true)
278 hardware
->acpi_detection
= true;
279 if ((retval
=parse_acpi(&hardware
->acpi
)) != ACPI_FOUND
) {
280 hardware
->is_acpi_valid
= false;
284 hardware
->is_acpi_valid
= true;
289 * vpd_detection - populate the VPD structure
291 * VPD is a structure available on IBM machines.
292 * It is documented at:
293 * http://www.pc.ibm.com/qtechinfo/MIGR-45120.html
294 * (XXX the page seems to be gone)
296 int detect_vpd(struct s_hardware
*hardware
)
298 if (hardware
->vpd_detection
)
301 hardware
->vpd_detection
= true;
303 if (vpd_decode(&hardware
->vpd
) == -ENOVPDTABLE
) {
304 hardware
->is_vpd_valid
= false;
307 hardware
->is_vpd_valid
= true;
312 /* Detection vesa stuff*/
313 int detect_vesa(struct s_hardware
*hardware
)
315 static com32sys_t rm
;
316 struct vesa_general_info
*gi
;
317 struct vesa_mode_info
*mi
;
318 uint16_t mode
, *mode_ptr
;
322 if (hardware
->vesa_detection
== true)
325 hardware
->vesa_detection
= true;
326 hardware
->is_vesa_valid
= false;
328 gi
= lmalloc(sizeof(*gi
));
332 mi
= lmalloc(sizeof(*mi
));
336 gi
->signature
= VBE2_MAGIC
; /* Get VBE2 extended data */
337 rm
.eax
.w
[0] = 0x4F00; /* Get SVGA general information */
338 rm
.edi
.w
[0] = OFFS(gi
);
340 __intcall(0x10, &rm
, &rm
);
342 if (rm
.eax
.w
[0] != 0x004F) {
346 mode_ptr
= GET_PTR(gi
->video_mode_ptr
);
347 oem_ptr
= GET_PTR(gi
->oem_vendor_name_ptr
);
348 strlcpy(hardware
->vesa
.vendor
, oem_ptr
, sizeof(hardware
->vesa
.vendor
));
349 oem_ptr
= GET_PTR(gi
->oem_product_name_ptr
);
350 strlcpy(hardware
->vesa
.product
, oem_ptr
, sizeof(hardware
->vesa
.product
));
351 oem_ptr
= GET_PTR(gi
->oem_product_rev_ptr
);
352 strlcpy(hardware
->vesa
.product_revision
, oem_ptr
,
353 sizeof(hardware
->vesa
.product_revision
));
355 hardware
->vesa
.major_version
= (gi
->version
>> 8) & 0xff;
356 hardware
->vesa
.minor_version
= gi
->version
& 0xff;
357 hardware
->vesa
.total_memory
= gi
->total_memory
;
358 hardware
->vesa
.software_rev
= gi
->oem_software_rev
;
360 hardware
->vesa
.vmi_count
= 0;
362 while ((mode
= *mode_ptr
++) != 0xFFFF) {
364 rm
.eax
.w
[0] = 0x4F01; /* Get SVGA mode information */
366 rm
.edi
.w
[0] = OFFS(mi
);
368 __intcall(0x10, &rm
, &rm
);
370 /* Must be a supported mode */
371 if (rm
.eax
.w
[0] != 0x004f)
374 /* Saving detected values */
375 memcpy(&hardware
->vesa
.vmi
[hardware
->vesa
.vmi_count
].mi
, mi
,
376 sizeof(struct vesa_mode_info
));
377 hardware
->vesa
.vmi
[hardware
->vesa
.vmi_count
].mode
= mode
;
379 hardware
->vesa
.vmi_count
++;
381 hardware
->is_vesa_valid
= true;
390 /* Try to detect disks from port 0x80 to 0xff */
391 void detect_disks(struct s_hardware
*hardware
)
396 if (hardware
->disk_detection
)
399 hardware
->disk_detection
= true;
400 for (int drive
= 0x80; drive
< 0xff; drive
++) {
402 hardware
->disk_info
[i
].disk
= drive
;
403 err
= get_drive_parameters(&hardware
->disk_info
[i
]);
406 * Do not print output when drive does not exist or
407 * doesn't support int13 (cdrom, ...)
409 if (err
== -1 || !hardware
->disk_info
[i
].cbios
)
413 hardware
->mbr_ids
[i
] = get_mbr_id(&hardware
->disk_info
[i
]);
415 hardware
->disks_count
++;
419 int detect_pxe(struct s_hardware
*hardware
)
424 t_PXENV_UNDI_GET_NIC_TYPE gnt
;
426 if (hardware
->pxe_detection
== true)
428 hardware
->pxe_detection
= true;
429 hardware
->is_pxe_valid
= false;
430 memset(&gnt
, 0, sizeof(t_PXENV_UNDI_GET_NIC_TYPE
));
431 memset(&hardware
->pxe
, 0, sizeof(struct s_pxe
));
433 /* This code can only work if pxelinux is loaded */
434 if (hardware
->sv
->filesystem
!= SYSLINUX_FS_PXELINUX
) {
437 // printf("PXE: PXElinux detected\n");
438 if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK
, &dhcpdata
, &dhcplen
)) {
439 pxe_bootp_t
*dhcp
= &hardware
->pxe
.dhcpdata
;
440 memcpy(&hardware
->pxe
.dhcpdata
, dhcpdata
,
441 sizeof(hardware
->pxe
.dhcpdata
));
442 snprintf(hardware
->pxe
.mac_addr
, sizeof(hardware
->pxe
.mac_addr
),
443 "%02x:%02x:%02x:%02x:%02x:%02x", dhcp
->CAddr
[0],
444 dhcp
->CAddr
[1], dhcp
->CAddr
[2], dhcp
->CAddr
[3],
445 dhcp
->CAddr
[4], dhcp
->CAddr
[5]);
447 /* Saving our IP address in a easy format */
448 hardware
->pxe
.ip_addr
[0] = hardware
->pxe
.dhcpdata
.yip
& 0xff;
449 hardware
->pxe
.ip_addr
[1] = hardware
->pxe
.dhcpdata
.yip
>> 8 & 0xff;
450 hardware
->pxe
.ip_addr
[2] = hardware
->pxe
.dhcpdata
.yip
>> 16 & 0xff;
451 hardware
->pxe
.ip_addr
[3] = hardware
->pxe
.dhcpdata
.yip
>> 24 & 0xff;
453 if (!pxe_get_nic_type(&gnt
)) {
454 switch (gnt
.NicType
) {
456 hardware
->is_pxe_valid
= true;
457 hardware
->pxe
.vendor_id
= gnt
.info
.pci
.Vendor_ID
;
458 hardware
->pxe
.product_id
= gnt
.info
.pci
.Dev_ID
;
459 hardware
->pxe
.subvendor_id
= gnt
.info
.pci
.SubVendor_ID
;
460 hardware
->pxe
.subproduct_id
=
461 gnt
.info
.pci
.SubDevice_ID
,
462 hardware
->pxe
.rev
= gnt
.info
.pci
.Rev
;
463 hardware
->pxe
.pci_bus
= (gnt
.info
.pci
.BusDevFunc
>> 8) & 0xff;
464 hardware
->pxe
.pci_dev
= (gnt
.info
.pci
.BusDevFunc
>> 3) & 0x7;
465 hardware
->pxe
.pci_func
= gnt
.info
.pci
.BusDevFunc
& 0x03;
466 hardware
->pxe
.base_class
= gnt
.info
.pci
.Base_Class
;
467 hardware
->pxe
.sub_class
= gnt
.info
.pci
.Sub_Class
;
468 hardware
->pxe
.prog_intf
= gnt
.info
.pci
.Prog_Intf
;
469 hardware
->pxe
.nictype
= gnt
.NicType
;
472 hardware
->is_pxe_valid
= true;
473 hardware
->pxe
.vendor_id
= gnt
.info
.cardbus
.Vendor_ID
;
474 hardware
->pxe
.product_id
= gnt
.info
.cardbus
.Dev_ID
;
475 hardware
->pxe
.subvendor_id
= gnt
.info
.cardbus
.SubVendor_ID
;
476 hardware
->pxe
.subproduct_id
=
477 gnt
.info
.cardbus
.SubDevice_ID
,
478 hardware
->pxe
.rev
= gnt
.info
.cardbus
.Rev
;
479 hardware
->pxe
.pci_bus
=
480 (gnt
.info
.cardbus
.BusDevFunc
>> 8) & 0xff;
481 hardware
->pxe
.pci_dev
=
482 (gnt
.info
.cardbus
.BusDevFunc
>> 3) & 0x7;
483 hardware
->pxe
.pci_func
= gnt
.info
.cardbus
.BusDevFunc
& 0x03;
484 hardware
->pxe
.base_class
= gnt
.info
.cardbus
.Base_Class
;
485 hardware
->pxe
.sub_class
= gnt
.info
.cardbus
.Sub_Class
;
486 hardware
->pxe
.prog_intf
= gnt
.info
.cardbus
.Prog_Intf
;
487 hardware
->pxe
.nictype
= gnt
.NicType
;
495 /* The firt pass try to find the exact pci device */
496 hardware
->pxe
.pci_device
= NULL
;
497 hardware
->pxe
.pci_device_pos
= 0;
498 struct pci_device
*pci_device
;
500 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
502 if ((__pci_bus
== hardware
->pxe
.pci_bus
) &&
503 (__pci_slot
== hardware
->pxe
.pci_dev
) &&
504 (__pci_func
== hardware
->pxe
.pci_func
) &&
505 (pci_device
->vendor
== hardware
->pxe
.vendor_id
)
506 && (pci_device
->product
== hardware
->pxe
.product_id
)) {
507 hardware
->pxe
.pci_device
= pci_device
;
508 hardware
->pxe
.pci_device_pos
= pci_number
;
513 /* If we reach that part, it means the pci device pointed by
514 * the pxe rom wasn't found in our list.
515 * Let's try to find the device only by its pci ids.
516 * The pci device we'll match is maybe not exactly the good one
517 * as we can have the same pci id several times.
518 * At least, the pci id, the vendor/product will be right.
519 * That's clearly a workaround for some weird cases.
520 * This should happend very unlikely */
521 hardware
->pxe
.pci_device
= NULL
;
522 hardware
->pxe
.pci_device_pos
= 0;
524 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
526 if ((pci_device
->vendor
== hardware
->pxe
.vendor_id
)
527 && (pci_device
->product
== hardware
->pxe
.product_id
)) {
528 hardware
->pxe
.pci_device
= pci_device
;
529 hardware
->pxe
.pci_device_pos
= pci_number
;
539 void detect_memory(struct s_hardware
*hardware
) {
540 if (hardware
->memory_detection
== false) {
541 hardware
->memory_detection
= true;
542 hardware
->detected_memory_size
= detect_memsize();
546 void detect_pci(struct s_hardware
*hardware
)
548 if (hardware
->pci_detection
== true)
550 hardware
->pci_detection
= true;
552 hardware
->nb_pci_devices
= 0;
554 /* Scanning to detect pci buses and devices */
555 hardware
->pci_domain
= pci_scan();
557 if (!hardware
->pci_domain
)
560 /* Gathering addtional information */
561 gather_additional_pci_config(hardware
->pci_domain
);
563 struct pci_device
*pci_device
;
564 for_each_pci_func(pci_device
, hardware
->pci_domain
) {
565 hardware
->nb_pci_devices
++;
569 more_printf("PCI: %d devices detected\n", hardware
->nb_pci_devices
);
570 more_printf("PCI: Resolving names\n");
572 /* Assigning product & vendor name for each device */
573 hardware
->pci_ids_return_code
=
574 get_name_from_pci_ids(hardware
->pci_domain
, hardware
->pciids_path
);
577 more_printf("PCI: Resolving class names\n");
578 /* Assigning class name for each device */
579 hardware
->pci_ids_return_code
=
580 get_class_name_from_pci_ids(hardware
->pci_domain
,
581 hardware
->pciids_path
);
584 more_printf("PCI: Resolving module names\n");
585 /* Detecting which kernel module should match each device using modules.pcimap */
586 hardware
->modules_pcimap_return_code
=
587 get_module_name_from_pcimap(hardware
->pci_domain
,
588 hardware
->modules_pcimap_path
);
590 /* Detecting which kernel module should match each device using modules.alias */
591 hardware
->modules_alias_return_code
=
592 get_module_name_from_alias(hardware
->pci_domain
,
593 hardware
->modules_alias_path
);
597 void cpu_detect(struct s_hardware
*hardware
)
599 if (hardware
->cpu_detection
== true)
601 detect_cpu(&hardware
->cpu
);
602 /* Old processors doesn't manage the identify commands
603 * Let's use the dmi value in that case */
604 if (strlen(remove_spaces(hardware
->cpu
.model
)) == 0)
605 strlcpy(hardware
->cpu
.model
, hardware
->dmi
.processor
.version
,
606 sizeof(hardware
->cpu
.model
));
608 /* Some CPUs like to put many spaces in the model name
609 * That makes some weird display in console/menu
610 * Let's remove that mulitple spaces */
611 strlcpy(hardware
->cpu
.model
,del_multi_spaces(hardware
->cpu
.model
),sizeof(hardware
->cpu
.model
));
613 if ((hardware
->is_acpi_valid
) && (hardware
->acpi
.madt
.valid
)) {
614 hardware
->physical_cpu_count
=hardware
->acpi
.madt
.processor_local_apic_count
/ hardware
->cpu
.num_cores
;
616 hardware
->cpu_detection
= true;
620 * Find the last instance of a particular command line argument
621 * (which should include the final =; do not use for boolean arguments)
623 const char *find_argument(const char **argv
, const char *argument
)
625 int la
= strlen(argument
);
627 const char *ptr
= NULL
;
629 for (arg
= argv
; *arg
; arg
++) {
630 if (!memcmp(*arg
, argument
, la
))
637 void clear_screen(void)
639 move_cursor_to_next_line();
641 set_g1_special_char();
643 display_cursor(false);
644 clear_entire_screen();
649 /* remove begining spaces */
650 char *skip_spaces(char *p
)
652 while (*p
&& *p
<= ' ') {
659 /* remove trailing & begining spaces */
660 char *remove_spaces(char *p
)
664 while (*p
&& *p
<= ' ') {
669 while (*p
&& *p
<= ' ') {
676 /* remove trailing LF */
677 char *remove_trailing_lf(char *p
)
681 while (*p
&& *p
== 10) {
690 /* delete multiple spaces, one is enough */
691 char *del_multi_spaces(char *p
)
693 /* Saving the original pointer */
696 /* Let's parse the complete string
697 * As we search for a double spacing
698 * we have to be sure then string is
699 * long enough to be processed */
700 while (*p
&& *(p
+ 1)) {
702 /* If we have two consecutive spaces */
703 if ((*p
== ' ') && (*(p
+ 1) == ' ')) {
705 /* Let's copy to the current position
706 * the content from the second space*/
707 strlcpy(p
, p
+ 1, strlen(p
+ 1));
709 /* Don't increment the pointer as we
710 * changed the content of the current position*/
714 /* Nothing as been found, let's see on the next char */
717 /* Returning the original pointer */
721 /* Reset the more_printf counter */
722 void reset_more_printf(void)
727 int draw_background(const char *what
)
730 return vesacon_default_background();
732 return vesacon_load_background(what
);
735 void init_console(struct s_hardware
*hardware
)
738 openconsole(&dev_rawcon_r
, &dev_vesaserial_w
);
739 draw_background(hardware
->vesa_background
);
744 void detect_hardware(struct s_hardware
*hardware
)
747 more_printf("ACPI: Detecting\n");
748 detect_acpi(hardware
);
751 more_printf("MEMORY: Detecting\n");
752 detect_memory(hardware
);
755 more_printf("DMI: Detecting Table\n");
756 if (detect_dmi(hardware
) == -ENODMITABLE
) {
757 more_printf("DMI: ERROR ! Table not found ! \n");
758 more_printf("DMI: Many hardware components will not be detected ! \n");
761 more_printf("DMI: Table found ! (version %u.%u)\n",
762 hardware
->dmi
.dmitable
.major_version
,
763 hardware
->dmi
.dmitable
.minor_version
);
767 more_printf("CPU: Detecting\n");
768 cpu_detect(hardware
);
771 more_printf("DISKS: Detecting\n");
772 detect_disks(hardware
);
775 more_printf("VPD: Detecting\n");
776 detect_vpd(hardware
);
778 detect_pci(hardware
);
780 more_printf("PCI: %d Devices Found\n", hardware
->nb_pci_devices
);
783 more_printf("PXE: Detecting\n");
784 detect_pxe(hardware
);
787 more_printf("VESA: Detecting\n");
788 detect_vesa(hardware
);