• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2009 Erwan Velu - All Rights Reserved
4  *
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:
13  *
14  *   The above copyright notice and this permission notice shall
15  *   be included in all copies or substantial portions of the Software.
16  *
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.
25  *
26  * -----------------------------------------------------------------------
27  */
28 
29 #ifndef DEFINE_HDT_COMMON_H
30 #define DEFINE_HDT_COMMON_H
31 #include <stdio.h>
32 #include <syslinux/pxe.h>
33 #include <console.h>
34 #include <consoles.h>
35 #include <syslinux/vesacon.h>
36 #include "sys/pci.h"
37 
38 #include <disk/bootloaders.h>
39 #include <disk/errno_disk.h>
40 #include <disk/error.h>
41 #include <disk/geom.h>
42 #include <disk/mbrs.h>
43 #include <disk/msdos.h>
44 #include <disk/partition.h>
45 #include <disk/swsusp.h>
46 #include <disk/read.h>
47 
48 #include "cpuid.h"
49 #include "dmi/dmi.h"
50 #include "hdt-ata.h"
51 #include <lib/sys/vesa/vesa.h>
52 #include <vpd/vpd.h>
53 #include <libansi.h>
54 #include <acpi/acpi.h>
55 #include <libupload/upload_backend.h>
56 
57 /* This two values are used for switching for the menu to the CLI mode */
58 #define HDT_SWITCH_TO_CLI "hdt_switch_to_cli"
59 #define HDT_DUMP "hdt_dump"
60 #define HDT_RETURN_TO_CLI 100
61 #define MAX_VESA_MODES 255
62 
63 /* This value is used for rebooting from the menu mode */
64 #define HDT_REBOOT "hdt_reboot"
65 
66 /* The maximum number of commands we can process */
67 #define MAX_NB_AUTO_COMMANDS 255
68 /* The maximum size of a command */
69 #define AUTO_COMMAND_SIZE 255
70 /* The char that separate two commands */
71 #define AUTO_SEPARATOR ";"
72 /* The char that surround the list of commands */
73 #define AUTO_DELIMITER '\''
74 
75 /* Graphic to load in background when using the vesa mode */
76 #define CLI_DEFAULT_BACKGROUND "backgnd.png"
77 
78 /* The maximum number of lines */
79 #define MAX_CLI_LINES 20
80 #define MAX_VESA_CLI_LINES 24
81 
82 struct upload_backend *upload;
83 
84 /* Defines if the cli is quiet*/
85 bool quiet;
86 
87 /* Defines if the cli is totally silent*/
88 bool silent;
89 
90 /* Defines if we must use the vesa mode */
91 bool vesamode;
92 
93 /* Defines if we must use the menu mode */
94 bool menumode;
95 
96 /* Defines if we are running the auto mode */
97 bool automode;
98 
99 /* Defines the number of lines in the console
100  * Default is 20 for a std console */
101 extern int max_console_lines;
102 
103 extern int display_line_nb;
104 extern bool disable_more_printf;
105 
106 #define pause_printf() do {\
107        printf("--More--");\
108        get_key(stdin, 0);\
109        printf("\033[2K\033[1G\033[1F\n");\
110 } while (0);
111 
112 /* The brokeness of that macro is that
113  * it assumes that __VA_ARGS__ contains
114  * one \n (and only one)
115  */
116 #define more_printf(...) do {\
117  if (__likely(!silent)) {\
118   if (__likely(!disable_more_printf)) {\
119    if (display_line_nb == max_console_lines) {\
120     display_line_nb=0;\
121     printf("\n--More--");\
122     get_key(stdin, 0);\
123     printf("\033[2K\033[1G\033[1F");\
124    }\
125    display_line_nb++;\
126   }\
127   printf(__VA_ARGS__);\
128  }\
129 } while (0);
130 
131 /* Display CPU registers for debugging purposes */
printregs(const com32sys_t * r)132 static inline void printregs(const com32sys_t * r)
133 {
134     printf("eflags = %08x  ds = %04x  es = %04x  fs = %04x  gs = %04x\n"
135 	   "eax = %08x  ebx = %08x  ecx = %08x  edx = %08x\n"
136 	   "ebp = %08x  esi = %08x  edi = %08x  esp = %08x\n",
137 	   r->eflags.l, r->ds, r->es, r->fs, r->gs,
138 	   r->eax.l, r->ebx.l, r->ecx.l, r->edx.l,
139 	   r->ebp.l, r->esi.l, r->edi.l, r->_unused_esp.l);
140 }
141 
142 struct s_pxe {
143     uint16_t vendor_id;
144     uint16_t product_id;
145     uint16_t subvendor_id;
146     uint16_t subproduct_id;
147     uint8_t rev;
148     uint8_t pci_bus;
149     uint8_t pci_dev;
150     uint8_t pci_func;
151     uint8_t base_class;
152     uint8_t sub_class;
153     uint8_t prog_intf;
154     uint8_t nictype;
155     char mac_addr[18];		/* The current mac address */
156     uint8_t ip_addr[4];
157     pxe_bootp_t dhcpdata;	/* The dhcp answer */
158     struct pci_device *pci_device;	/* The matching pci device */
159     uint8_t pci_device_pos;	/* It position in our pci sorted list */
160 };
161 
162 struct s_vesa_mode_info {
163     struct vesa_mode_info mi;
164     uint16_t mode;
165 };
166 
167 struct s_vesa {
168     uint8_t major_version;
169     uint8_t minor_version;
170     struct s_vesa_mode_info vmi[MAX_VESA_MODES];
171     uint8_t vmi_count;
172     uint16_t total_memory;
173     char vendor[256];
174     char product[256];
175     char product_revision[256];
176     uint16_t software_rev;
177 };
178 
179 struct s_hardware {
180     s_dmi dmi;			/* DMI table */
181     s_cpu cpu;			/* CPU information */
182     uint8_t physical_cpu_count; /* Number of physical cpu */
183     s_vpd vpd;			/* VPD information */
184     s_acpi acpi;
185     struct pci_domain *pci_domain;	/* PCI Devices */
186     struct driveinfo disk_info[256];	/* Disk Information */
187     uint32_t mbr_ids[256];	/* MBR ids */
188     int disks_count;		/* Number of detected disks */
189     struct s_pxe pxe;
190     struct s_vesa vesa;
191     unsigned long detected_memory_size;	/* The detected memory size (in KB) */
192 
193     int pci_ids_return_code;
194     int modules_pcimap_return_code;
195     int modules_alias_return_code;
196     int nb_pci_devices;
197     bool is_dmi_valid;
198     bool is_pxe_valid;
199     bool is_vesa_valid;
200     bool is_vpd_valid;
201     bool is_acpi_valid;
202 
203     bool dmi_detection;		/* Does the dmi stuff has already been detected? */
204     bool pci_detection;		/* Does the pci stuff has already been detected? */
205     bool cpu_detection;		/* Does the cpu stuff has already been detected? */
206     bool disk_detection;	/* Does the disk stuff has already been detected? */
207     bool pxe_detection;		/* Does the pxe stuff has already been detected? */
208     bool vesa_detection;	/* Does the vesa sutff have been already detected? */
209     bool vpd_detection;		/* Does the vpd stuff has already been detected? */
210     bool memory_detection;	/* Does the memory size got detected ?*/
211     bool acpi_detection;	/* Does the acpi got detected ?*/
212 
213     char syslinux_fs[22];
214     const struct syslinux_version *sv;
215     char modules_pcimap_path[255];
216     char modules_alias_path[255];
217     char pciids_path[255];
218     char dump_path[255]; /* Dump path on the tftp server */
219     char dump_filename[255]; /* Dump filename on the tftp server */
220     char tftp_ip[255];   /* IP address of tftp server (dump mode) */
221     char memtest_label[255];
222     char auto_label[AUTO_COMMAND_SIZE];
223     char vesa_background[255];
224     char postexec[255];
225 };
226 
227 void reset_more_printf(void);
228 const char *find_argument(const char **argv, const char *argument);
229 char *remove_spaces(char *p);
230 char *remove_trailing_lf(char *p);
231 char *skip_spaces(char *p);
232 char *del_multi_spaces(char *p);
233 int detect_dmi(struct s_hardware *hardware);
234 int detect_vpd(struct s_hardware *hardware);
235 void detect_disks(struct s_hardware *hardware);
236 void detect_pci(struct s_hardware *hardware);
237 void cpu_detect(struct s_hardware *hardware);
238 int detect_pxe(struct s_hardware *hardware);
239 void init_hardware(struct s_hardware *hardware);
240 void clear_screen(void);
241 void detect_syslinux(struct s_hardware *hardware);
242 int detect_acpi(struct s_hardware *hardware);
243 void detect_parameters(const int argc, const char *argv[],
244 		       struct s_hardware *hardware);
245 int detect_vesa(struct s_hardware *hardware);
246 void detect_memory(struct s_hardware *hardware);
247 void init_console(struct s_hardware *hardware);
248 void detect_hardware(struct s_hardware *hardware);
249 void dump(struct s_hardware *hardware);
250 #endif
251