Releasing debian version 4.04+dfsg-9.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-common.c
blobf1557b860d559a03fe711e07cf8a6df6d5d8cd03
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
12 * conditions:
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 * -----------------------------------------------------------------------
29 #include <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <getkey.h>
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>
38 #include <memory.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)
45 return;
46 /* Searching the dot */
47 char *dot = strchr(filename, '.');
48 /* Exiting if no dot exists in that string */
49 if (dot == NULL)
50 return;
51 /* Exiting if the extension is 3 char or less */
52 if (strlen(dot) <= 4)
53 return;
55 /* We have an extension bigger than .blah
56 * so we have to shorten it to 3*/
57 dot[4] = '\0';
60 void detect_parameters(const int argc, const char *argv[],
61 struct s_hardware *hardware)
63 /* Quiet mode - make the output more quiet */
64 quiet = true;
66 /* Vesa mode isn't set until we explictly call it */
67 vesamode = false;
69 /* Automode isn't the default*/
70 automode = false;
72 /* Menu mode is the default*/
73 menumode = true;
75 for (int i = 1; i < argc; i++) {
76 if (!strncmp(argv[i], "quiet", 5)) {
77 quiet = true;
78 } else if (!strncmp(argv[i], "verbose", 7)) {
79 quiet = false;
80 } else if (!strncmp(argv[i], "modules_pcimap=", 15)) {
81 strlcpy(hardware->modules_pcimap_path, argv[i] + 15,
82 sizeof(hardware->modules_pcimap_path));
83 convert_isolinux_filename(hardware->modules_pcimap_path, hardware);
84 } else if (!strncmp(argv[i], "pciids=", 7)) {
85 strlcpy(hardware->pciids_path, argv[i] + 7,
86 sizeof(hardware->pciids_path));
87 convert_isolinux_filename(hardware->pciids_path, hardware);
88 } else if (!strncmp(argv[i], "modules_alias=", 14)) {
89 strlcpy(hardware->modules_alias_path, argv[i] + 14,
90 sizeof(hardware->modules_alias_path));
91 convert_isolinux_filename(hardware->modules_alias_path, hardware);
92 } else if (!strncmp(argv[i], "memtest=", 8)) {
93 strlcpy(hardware->memtest_label, argv[i] + 8,
94 sizeof(hardware->memtest_label));
95 convert_isolinux_filename(hardware->memtest_label, hardware);
96 } else if (!strncmp(argv[i], "vesa", 4)) {
97 vesamode = true;
98 max_console_lines = MAX_VESA_CLI_LINES;
99 /* If the user defines a background image */
100 if (!strncmp(argv[i], "vesa=", 5)) {
101 strlcpy(hardware->vesa_background, argv[i] + 5,
102 sizeof(hardware->vesa_background));
104 } else if (!strncmp(argv[i], "novesa", 6)) {
105 vesamode = false;
106 max_console_lines = MAX_CLI_LINES;
107 } else if (!strncmp(argv[i], "nomenu", 6)) {
108 menumode = false;
109 } else if (!strncmp(argv[i], "auto=", 5)) {
110 /* The auto= parameter is separated in several argv[]
111 * as it can contains spaces.
112 * We use the AUTO_DELIMITER char to define the limits
113 * of this parameter.
114 * i.e auto='show dmi; show pci'
117 automode=true;
118 /* Extracting the first parameter */
119 strcpy(hardware->auto_label, argv[i] + 6);
120 strcat(hardware->auto_label, " ");
121 char *pos;
122 i++;
124 /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */
125 while (((pos = strstr(argv[i], AUTO_DELIMITER)) == NULL)
126 && (i < argc)) {
127 strcat(hardware->auto_label, argv[i]);
128 strcat(hardware->auto_label, " ");
129 i++;
132 /* If we didn't reach the end of the line, let's grab the last item */
133 if (i < argc) {
134 strcat(hardware->auto_label, argv[i]);
135 hardware->auto_label[strlen(hardware->auto_label) - 1] = 0;
141 void detect_syslinux(struct s_hardware *hardware)
143 hardware->sv = syslinux_version();
144 switch (hardware->sv->filesystem) {
145 case SYSLINUX_FS_SYSLINUX:
146 strlcpy(hardware->syslinux_fs, "SYSlinux", 9);
147 break;
148 case SYSLINUX_FS_PXELINUX:
149 strlcpy(hardware->syslinux_fs, "PXElinux", 9);
150 break;
151 case SYSLINUX_FS_ISOLINUX:
152 strlcpy(hardware->syslinux_fs, "ISOlinux", 9);
153 break;
154 case SYSLINUX_FS_EXTLINUX:
155 strlcpy(hardware->syslinux_fs, "EXTlinux", 9);
156 break;
157 case SYSLINUX_FS_UNKNOWN:
158 default:
159 strlcpy(hardware->syslinux_fs, "Unknown Bootloader",
160 sizeof hardware->syslinux_fs);
161 break;
165 void init_hardware(struct s_hardware *hardware)
167 hardware->pci_ids_return_code = 0;
168 hardware->modules_pcimap_return_code = 0;
169 hardware->modules_alias_return_code = 0;
170 hardware->cpu_detection = false;
171 hardware->pci_detection = false;
172 hardware->disk_detection = false;
173 hardware->disks_count = 0;
174 hardware->dmi_detection = false;
175 hardware->pxe_detection = false;
176 hardware->vesa_detection = false;
177 hardware->vpd_detection = false;
178 hardware->memory_detection = false;
179 hardware->acpi_detection = false;
180 hardware->nb_pci_devices = 0;
181 hardware->is_dmi_valid = false;
182 hardware->is_pxe_valid = false;
183 hardware->is_vpd_valid = false;
184 hardware->is_acpi_valid = false;
185 hardware->pci_domain = NULL;
186 hardware->detected_memory_size = 0;
187 hardware->physical_cpu_count =1; /* we have at least one cpu */
189 /* Cleaning structures */
190 memset(hardware->disk_info, 0, sizeof(hardware->disk_info));
191 memset(hardware->mbr_ids, 0, sizeof(hardware->mbr_ids));
192 memset(&hardware->dmi, 0, sizeof(s_dmi));
193 memset(&hardware->cpu, 0, sizeof(s_cpu));
194 memset(&hardware->pxe, 0, sizeof(struct s_pxe));
195 memset(&hardware->vesa, 0, sizeof(struct s_vesa));
196 memset(&hardware->vpd, 0, sizeof(s_vpd));
197 memset(&hardware->acpi, 0, sizeof(s_acpi));
198 memset(hardware->syslinux_fs, 0, sizeof hardware->syslinux_fs);
199 memset(hardware->pciids_path, 0, sizeof hardware->pciids_path);
200 memset(hardware->modules_pcimap_path, 0,
201 sizeof hardware->modules_pcimap_path);
202 memset(hardware->modules_alias_path, 0,
203 sizeof hardware->modules_alias_path);
204 memset(hardware->memtest_label, 0, sizeof hardware->memtest_label);
205 memset(hardware->auto_label, 0, sizeof hardware->auto_label);
206 memset(hardware->vesa_background, 0, sizeof hardware->vesa_background);
207 strcat(hardware->pciids_path, "pci.ids");
208 strcat(hardware->modules_pcimap_path, "modules.pcimap");
209 strcat(hardware->modules_alias_path, "modules.alias");
210 strcat(hardware->memtest_label, "memtest");
211 strlcpy(hardware->vesa_background, CLI_DEFAULT_BACKGROUND,
212 sizeof(hardware->vesa_background));
216 * Detecting if a DMI table exist
217 * if yes, let's parse it
219 int detect_dmi(struct s_hardware *hardware)
221 if (hardware->dmi_detection == true)
222 return -1;
223 hardware->dmi_detection = true;
224 if (dmi_iterate(&hardware->dmi) == -ENODMITABLE) {
225 hardware->is_dmi_valid = false;
226 return -ENODMITABLE;
229 parse_dmitable(&hardware->dmi);
230 hardware->is_dmi_valid = true;
231 return 0;
235 * Detecting ACPI
236 * if yes, let's parse it
238 int detect_acpi(struct s_hardware *hardware)
240 int retval;
241 if (hardware->acpi_detection == true)
242 return -1;
243 hardware->acpi_detection = true;
244 if ((retval=parse_acpi(&hardware->acpi)) != ACPI_FOUND) {
245 hardware->is_acpi_valid = false;
246 return retval;
249 hardware->is_acpi_valid = true;
250 return retval;
254 * vpd_detection - populate the VPD structure
256 * VPD is a structure available on IBM machines.
257 * It is documented at:
258 * http://www.pc.ibm.com/qtechinfo/MIGR-45120.html
259 * (XXX the page seems to be gone)
261 int detect_vpd(struct s_hardware *hardware)
263 if (hardware->vpd_detection)
264 return -1;
265 else
266 hardware->vpd_detection = true;
268 if (vpd_decode(&hardware->vpd) == -ENOVPDTABLE) {
269 hardware->is_vpd_valid = false;
270 return -ENOVPDTABLE;
271 } else {
272 hardware->is_vpd_valid = true;
273 return 0;
277 /* Detection vesa stuff*/
278 int detect_vesa(struct s_hardware *hardware)
280 static com32sys_t rm;
281 struct vesa_general_info *gi;
282 struct vesa_mode_info *mi;
283 uint16_t mode, *mode_ptr;
284 char *oem_ptr;
286 if (hardware->vesa_detection == true)
287 return -1;
289 hardware->vesa_detection = true;
290 hardware->is_vesa_valid = false;
292 /* Allocate space in the bounce buffer for these structures */
293 gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
294 mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
296 gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
297 rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
298 rm.edi.w[0] = OFFS(gi);
299 rm.es = SEG(gi);
300 __intcall(0x10, &rm, &rm);
302 if (rm.eax.w[0] != 0x004F) {
303 return -1;
306 mode_ptr = GET_PTR(gi->video_mode_ptr);
307 oem_ptr = GET_PTR(gi->oem_vendor_name_ptr);
308 strlcpy(hardware->vesa.vendor, oem_ptr, sizeof(hardware->vesa.vendor));
309 oem_ptr = GET_PTR(gi->oem_product_name_ptr);
310 strlcpy(hardware->vesa.product, oem_ptr, sizeof(hardware->vesa.product));
311 oem_ptr = GET_PTR(gi->oem_product_rev_ptr);
312 strlcpy(hardware->vesa.product_revision, oem_ptr,
313 sizeof(hardware->vesa.product_revision));
315 hardware->vesa.major_version = (gi->version >> 8) & 0xff;
316 hardware->vesa.minor_version = gi->version & 0xff;
317 hardware->vesa.total_memory = gi->total_memory;
318 hardware->vesa.software_rev = gi->oem_software_rev;
320 hardware->vesa.vmi_count = 0;
322 while ((mode = *mode_ptr++) != 0xFFFF) {
324 rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
325 rm.ecx.w[0] = mode;
326 rm.edi.w[0] = OFFS(mi);
327 rm.es = SEG(mi);
328 __intcall(0x10, &rm, &rm);
330 /* Must be a supported mode */
331 if (rm.eax.w[0] != 0x004f)
332 continue;
334 /* Saving detected values */
335 memcpy(&hardware->vesa.vmi[hardware->vesa.vmi_count].mi, mi,
336 sizeof(struct vesa_mode_info));
337 hardware->vesa.vmi[hardware->vesa.vmi_count].mode = mode;
339 hardware->vesa.vmi_count++;
341 hardware->is_vesa_valid = true;
342 return 0;
345 /* Try to detect disks from port 0x80 to 0xff */
346 void detect_disks(struct s_hardware *hardware)
348 int i = -1;
349 int err;
351 if (hardware->disk_detection)
352 return;
354 hardware->disk_detection = true;
355 for (int drive = 0x80; drive < 0xff; drive++) {
356 i++;
357 hardware->disk_info[i].disk = drive;
358 err = get_drive_parameters(&hardware->disk_info[i]);
361 * Do not print output when drive does not exist or
362 * doesn't support int13 (cdrom, ...)
364 if (err == -1 || !hardware->disk_info[i].cbios)
365 continue;
367 /* Detect MBR */
368 hardware->mbr_ids[i] = get_mbr_id(&hardware->disk_info[i]);
370 hardware->disks_count++;
374 int detect_pxe(struct s_hardware *hardware)
376 void *dhcpdata;
378 size_t dhcplen;
379 t_PXENV_UNDI_GET_NIC_TYPE gnt;
381 if (hardware->pxe_detection == true)
382 return -1;
383 hardware->pxe_detection = true;
384 hardware->is_pxe_valid = false;
385 memset(&gnt, 0, sizeof(t_PXENV_UNDI_GET_NIC_TYPE));
386 memset(&hardware->pxe, 0, sizeof(struct s_pxe));
388 /* This code can only work if pxelinux is loaded */
389 if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) {
390 return -1;
392 // printf("PXE: PXElinux detected\n");
393 if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
394 pxe_bootp_t *dhcp = &hardware->pxe.dhcpdata;
395 memcpy(&hardware->pxe.dhcpdata, dhcpdata,
396 sizeof(hardware->pxe.dhcpdata));
397 snprintf(hardware->pxe.mac_addr, sizeof(hardware->pxe.mac_addr),
398 "%02x:%02x:%02x:%02x:%02x:%02x", dhcp->CAddr[0],
399 dhcp->CAddr[1], dhcp->CAddr[2], dhcp->CAddr[3],
400 dhcp->CAddr[4], dhcp->CAddr[5]);
402 /* Saving our IP address in a easy format */
403 hardware->pxe.ip_addr[0] = hardware->pxe.dhcpdata.yip & 0xff;
404 hardware->pxe.ip_addr[1] = hardware->pxe.dhcpdata.yip >> 8 & 0xff;
405 hardware->pxe.ip_addr[2] = hardware->pxe.dhcpdata.yip >> 16 & 0xff;
406 hardware->pxe.ip_addr[3] = hardware->pxe.dhcpdata.yip >> 24 & 0xff;
408 if (!pxe_get_nic_type(&gnt)) {
409 switch (gnt.NicType) {
410 case PCI_NIC:
411 hardware->is_pxe_valid = true;
412 hardware->pxe.vendor_id = gnt.info.pci.Vendor_ID;
413 hardware->pxe.product_id = gnt.info.pci.Dev_ID;
414 hardware->pxe.subvendor_id = gnt.info.pci.SubVendor_ID;
415 hardware->pxe.subproduct_id =
416 gnt.info.pci.SubDevice_ID,
417 hardware->pxe.rev = gnt.info.pci.Rev;
418 hardware->pxe.pci_bus = (gnt.info.pci.BusDevFunc >> 8) & 0xff;
419 hardware->pxe.pci_dev = (gnt.info.pci.BusDevFunc >> 3) & 0x7;
420 hardware->pxe.pci_func = gnt.info.pci.BusDevFunc & 0x03;
421 hardware->pxe.base_class = gnt.info.pci.Base_Class;
422 hardware->pxe.sub_class = gnt.info.pci.Sub_Class;
423 hardware->pxe.prog_intf = gnt.info.pci.Prog_Intf;
424 hardware->pxe.nictype = gnt.NicType;
425 break;
426 case CardBus_NIC:
427 hardware->is_pxe_valid = true;
428 hardware->pxe.vendor_id = gnt.info.cardbus.Vendor_ID;
429 hardware->pxe.product_id = gnt.info.cardbus.Dev_ID;
430 hardware->pxe.subvendor_id = gnt.info.cardbus.SubVendor_ID;
431 hardware->pxe.subproduct_id =
432 gnt.info.cardbus.SubDevice_ID,
433 hardware->pxe.rev = gnt.info.cardbus.Rev;
434 hardware->pxe.pci_bus =
435 (gnt.info.cardbus.BusDevFunc >> 8) & 0xff;
436 hardware->pxe.pci_dev =
437 (gnt.info.cardbus.BusDevFunc >> 3) & 0x7;
438 hardware->pxe.pci_func = gnt.info.cardbus.BusDevFunc & 0x03;
439 hardware->pxe.base_class = gnt.info.cardbus.Base_Class;
440 hardware->pxe.sub_class = gnt.info.cardbus.Sub_Class;
441 hardware->pxe.prog_intf = gnt.info.cardbus.Prog_Intf;
442 hardware->pxe.nictype = gnt.NicType;
443 break;
444 case PnP_NIC:
445 default:
446 return -1;
447 break;
450 /* The firt pass try to find the exact pci device */
451 hardware->pxe.pci_device = NULL;
452 hardware->pxe.pci_device_pos = 0;
453 struct pci_device *pci_device;
454 int pci_number = 0;
455 for_each_pci_func(pci_device, hardware->pci_domain) {
456 pci_number++;
457 if ((__pci_bus == hardware->pxe.pci_bus) &&
458 (__pci_slot == hardware->pxe.pci_dev) &&
459 (__pci_func == hardware->pxe.pci_func) &&
460 (pci_device->vendor == hardware->pxe.vendor_id)
461 && (pci_device->product == hardware->pxe.product_id)) {
462 hardware->pxe.pci_device = pci_device;
463 hardware->pxe.pci_device_pos = pci_number;
464 return 0;
468 /* If we reach that part, it means the pci device pointed by
469 * the pxe rom wasn't found in our list.
470 * Let's try to find the device only by its pci ids.
471 * The pci device we'll match is maybe not exactly the good one
472 * as we can have the same pci id several times.
473 * At least, the pci id, the vendor/product will be right.
474 * That's clearly a workaround for some weird cases.
475 * This should happend very unlikely */
476 hardware->pxe.pci_device = NULL;
477 hardware->pxe.pci_device_pos = 0;
478 pci_number = 0;
479 for_each_pci_func(pci_device, hardware->pci_domain) {
480 pci_number++;
481 if ((pci_device->vendor == hardware->pxe.vendor_id)
482 && (pci_device->product == hardware->pxe.product_id)) {
483 hardware->pxe.pci_device = pci_device;
484 hardware->pxe.pci_device_pos = pci_number;
485 return 0;
491 return 0;
494 void detect_memory(struct s_hardware *hardware) {
495 if (hardware->memory_detection == false) {
496 hardware->memory_detection = true;
497 hardware->detected_memory_size = detect_memsize();
501 void detect_pci(struct s_hardware *hardware)
503 if (hardware->pci_detection == true)
504 return;
505 hardware->pci_detection = true;
507 hardware->nb_pci_devices = 0;
509 /* Scanning to detect pci buses and devices */
510 hardware->pci_domain = pci_scan();
512 if (!hardware->pci_domain)
513 return;
515 /* Gathering addtional information */
516 gather_additional_pci_config(hardware->pci_domain);
518 struct pci_device *pci_device;
519 for_each_pci_func(pci_device, hardware->pci_domain) {
520 hardware->nb_pci_devices++;
523 if (!quiet) {
524 more_printf("PCI: %d devices detected\n", hardware->nb_pci_devices);
525 more_printf("PCI: Resolving names\n");
527 /* Assigning product & vendor name for each device */
528 hardware->pci_ids_return_code =
529 get_name_from_pci_ids(hardware->pci_domain, hardware->pciids_path);
531 if (!quiet)
532 more_printf("PCI: Resolving class names\n");
533 /* Assigning class name for each device */
534 hardware->pci_ids_return_code =
535 get_class_name_from_pci_ids(hardware->pci_domain,
536 hardware->pciids_path);
538 if (!quiet)
539 more_printf("PCI: Resolving module names\n");
540 /* Detecting which kernel module should match each device using modules.pcimap */
541 hardware->modules_pcimap_return_code =
542 get_module_name_from_pcimap(hardware->pci_domain,
543 hardware->modules_pcimap_path);
545 /* Detecting which kernel module should match each device using modules.alias */
546 hardware->modules_alias_return_code =
547 get_module_name_from_alias(hardware->pci_domain,
548 hardware->modules_alias_path);
552 void cpu_detect(struct s_hardware *hardware)
554 if (hardware->cpu_detection == true)
555 return;
556 detect_cpu(&hardware->cpu);
557 /* Old processors doesn't manage the identify commands
558 * Let's use the dmi value in that case */
559 if (strlen(remove_spaces(hardware->cpu.model)) == 0)
560 strlcpy(hardware->cpu.model, hardware->dmi.processor.version,
561 sizeof(hardware->cpu.model));
563 /* Some CPUs like to put many spaces in the model name
564 * That makes some weird display in console/menu
565 * Let's remove that mulitple spaces */
566 strlcpy(hardware->cpu.model,del_multi_spaces(hardware->cpu.model),sizeof(hardware->cpu.model));
568 if ((hardware->is_acpi_valid) && (hardware->acpi.madt.valid)) {
569 hardware->physical_cpu_count=hardware->acpi.madt.processor_local_apic_count / hardware->cpu.num_cores;
571 hardware->cpu_detection = true;
575 * Find the last instance of a particular command line argument
576 * (which should include the final =; do not use for boolean arguments)
578 const char *find_argument(const char **argv, const char *argument)
580 int la = strlen(argument);
581 const char **arg;
582 const char *ptr = NULL;
584 for (arg = argv; *arg; arg++) {
585 if (!memcmp(*arg, argument, la))
586 ptr = *arg + la;
589 return ptr;
592 void clear_screen(void)
594 move_cursor_to_next_line();
595 disable_utf8();
596 set_g1_special_char();
597 set_us_g0_charset();
598 display_cursor(false);
599 clear_entire_screen();
600 gotoxy(0,0);
601 reset_more_printf();
604 /* remove begining spaces */
605 char *skip_spaces(char *p)
607 while (*p && *p <= ' ') {
608 p++;
611 return p;
614 /* remove trailing & begining spaces */
615 char *remove_spaces(char *p)
617 char *save = p;
618 p += strlen(p) - 1;
619 while (*p && *p <= ' ') {
620 *p = '\0';
621 p--;
623 p = save;
624 while (*p && *p <= ' ') {
625 p++;
628 return p;
631 /* remove trailing LF */
632 char *remove_trailing_lf(char *p)
634 char *save = p;
635 p += strlen(p) - 1;
636 while (*p && *p == 10) {
637 *p = '\0';
638 p--;
640 p = save;
642 return p;
645 /* delete multiple spaces, one is enough */
646 char *del_multi_spaces(char *p)
648 /* Saving the original pointer */
649 char *save = p;
651 /* Let's parse the complete string
652 * As we search for a double spacing
653 * we have to be sure then string is
654 * long enough to be processed */
655 while (*p && *p + 1) {
657 /* If we have two consecutive spaces */
658 if ((*p == ' ') && (*(p + 1) == ' ')) {
660 /* Let's copy to the current position
661 * the content from the second space*/
662 strlcpy(p, p + 1, strlen(p + 1));
664 /* Don't increment the pointer as we
665 * changed the content of the current position*/
666 continue;
669 /* Nothing as been found, let's see on the next char */
670 p++;
672 /* Returning the original pointer */
673 return save;
676 /* Reset the more_printf counter */
677 void reset_more_printf(void)
679 display_line_nb = 0;
682 int draw_background(const char *what)
684 if (!what)
685 return vesacon_default_background();
686 else
687 return vesacon_load_background(what);
690 void init_console(struct s_hardware *hardware)
692 if (vesamode) {
693 openconsole(&dev_rawcon_r, &dev_vesaserial_w);
694 draw_background(hardware->vesa_background);
695 } else
696 console_ansi_raw();
699 void detect_hardware(struct s_hardware *hardware)
701 if (!quiet)
702 more_printf("ACPI: Detecting\n");
703 detect_acpi(hardware);
705 if (!quiet)
706 more_printf("MEMORY: Detecting\n");
707 detect_memory(hardware);
709 if (!quiet)
710 more_printf("DMI: Detecting Table\n");
711 if (detect_dmi(hardware) == -ENODMITABLE) {
712 printf("DMI: ERROR ! Table not found ! \n");
713 printf("DMI: Many hardware components will not be detected ! \n");
714 } else {
715 if (!quiet)
716 more_printf("DMI: Table found ! (version %u.%u)\n",
717 hardware->dmi.dmitable.major_version,
718 hardware->dmi.dmitable.minor_version);
721 if (!quiet)
722 more_printf("CPU: Detecting\n");
723 cpu_detect(hardware);
725 if (!quiet)
726 more_printf("DISKS: Detecting\n");
727 detect_disks(hardware);
729 if (!quiet)
730 more_printf("VPD: Detecting\n");
731 detect_vpd(hardware);
733 detect_pci(hardware);
734 if (!quiet)
735 more_printf("PCI: %d Devices Found\n", hardware->nb_pci_devices);
737 if (!quiet)
738 more_printf("PXE: Detecting\n");
739 detect_pxe(hardware);
741 if (!quiet)
742 more_printf("VESA: Detecting\n");
743 detect_vesa(hardware);