5 * A com32 module to load gfxboot graphics.
7 * Copyright (c) 2009 Steffen Winterfeldt.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, Inc., 53 Temple Place Ste 330, Boston MA
12 * 02111-1307, USA; either version 2 of the License, or (at your option) any
13 * later version; incorporated herein by reference.
22 #include <sys/types.h>
27 #include <syslinux/loadfile.h>
28 #include <syslinux/config.h>
29 #include <syslinux/linux.h>
30 #include <syslinux/boot.h>
35 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 #define MAX_CONFIG_LINE_LEN 2048
37 #define MAX_CMDLINE_LEN 2048
39 // buffer for realmode callback
40 // must be at least block size; can in theory be larger than 4k, but there's
41 // not enough space left
42 #define REALMODE_BUF_SIZE 4096
43 #define LOWMEM_BUF_SIZE 65536
45 // gfxboot working memory in MB
46 #define GFX_MEMORY_SIZE 7
48 // read chunk size for progress bar
49 #define CHUNK_SIZE (64 << 10)
51 // callback function numbers
54 #define GFX_CB_INPUT 2
55 #define GFX_CB_MENU_INIT 3
56 #define GFX_CB_INFOBOX_INIT 4
57 #define GFX_CB_INFOBOX_DONE 5
58 #define GFX_CB_PROGRESS_INIT 6
59 #define GFX_CB_PROGRESS_DONE 7
60 #define GFX_CB_PROGRESS_UPDATE 8
61 #define GFX_CB_PROGRESS_LIMIT 9 // unused
62 #define GFX_CB_PASSWORD_INIT 10
63 #define GFX_CB_PASSWORD_DONE 11
65 // real mode code chunk, will be placed into lowmem buffer
66 extern const char realmode_callback_start
[], realmode_callback_end
[];
72 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73 // gfxboot config data (64 bytes)
74 typedef struct __attribute__ ((packed
)) {
75 uint8_t bootloader
; // 0: boot loader type (0: lilo, 1: syslinux, 2: grub)
76 uint8_t sector_shift
; // 1: sector shift
77 uint8_t media_type
; // 2: media type (0: disk, 1: floppy, 2: cdrom)
78 uint8_t failsafe
; // 3: turn on failsafe mode (bitmask)
81 // 2: skip monitor detection
82 uint8_t sysconfig_size
; // 4: size of sysconfig data
83 uint8_t boot_drive
; // 5: BIOS boot drive
84 uint16_t callback
; // 6: offset to callback handler
85 uint16_t bootloader_seg
; // 8: code/data segment used by bootloader; must follow gfx_callback
86 uint16_t serial_port
; // 10: syslinux initialized serial port from 'serial' option
87 uint32_t user_info_0
; // 12: data for info box
88 uint32_t user_info_1
; // 16: data for info box
89 uint32_t bios_mem_size
; // 20: BIOS memory size (in bytes)
90 uint16_t xmem_0
; // 24: extended mem area 0 (start:size in MB; 12:4 bits) - obsolete
91 uint16_t xmem_1
; // 26: extended mem area 1 - obsolete
92 uint16_t xmem_2
; // 28: extended mem area 2 - obsolete
93 uint16_t xmem_3
; // 30: extended mem area 3 - obsolete
94 uint32_t file
; // 32: start of gfx file
95 uint32_t archive_start
; // 36: start of cpio archive
96 uint32_t archive_end
; // 40: end of cpio archive
97 uint32_t mem0_start
; // 44: low free memory start
98 uint32_t mem0_end
; // 48: low free memory end
99 uint32_t xmem_start
; // 52: extended mem start
100 uint32_t xmem_end
; // 56: extended mem end
101 uint16_t features
; // 60: feature flags returned by GFX_CB_INIT
102 // 0: GFX_CB_MENU_INIT accepts 32 bit addresses
103 // 1: knows about xmem_start, xmem_end
104 uint16_t reserved_1
; // 62:
105 uint32_t gfxboot_cwd
; // 64: if set, points to current gfxboot working directory relative
106 // to syslinux working directory
110 // gfxboot menu description (18 bytes)
111 typedef struct __attribute__ ((packed
)) {
122 typedef struct menu_s
{
124 char *label
; // config entry name
125 char *menu_label
; // text to show in boot menu
126 char *kernel
; // name of program to load
127 char *alt_kernel
; // alternative name in case user has replaced it
128 char *linux
; // de facto an alias for 'kernel'
129 char *localboot
; // boot from local disk
130 char *initrd
; // initrd as separate line (instead of as part of 'append')
131 char *append
; // kernel args
132 char *ipappend
; // append special pxelinux args (see doc)
136 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137 gfx_config_t gfx_config
;
141 menu_t
*menu_default
;
142 static menu_t
*menu_ptr
, **menu_next
;
145 uint32_t jmp_table
[12];
154 char cmdline
[MAX_CMDLINE_LEN
];
156 // progress bar is visible
157 unsigned progress_active
;
160 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161 void show_message(char *file
);
162 char *get_config_file_name(void);
163 char *skip_nonspaces(char *s
);
164 void chop_line(char *s
);
165 int read_config_file(const char *filename
);
166 unsigned magic_ok(unsigned char *buf
, unsigned *code_size
);
167 unsigned find_file(unsigned char *buf
, unsigned len
, unsigned *gfx_file_start
, unsigned *file_len
, unsigned *code_size
);
168 int gfx_init(char *file
);
169 int gfx_menu_init(void);
172 void gfx_infobox(int type
, char *str1
, char *str2
);
173 void gfx_progress_init(ssize_t kernel_size
, char *label
);
174 void gfx_progress_update(ssize_t size
);
175 void gfx_progress_done(void);
176 void *load_one(char *file
, ssize_t
*file_size
);
177 void boot(int index
);
178 void boot_entry(menu_t
*menu_ptr
, char *arg
);
181 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182 int main(int argc
, char **argv
)
185 const union syslinux_derivative_info
*sdi
;
186 char working_dir
[256];
188 openconsole(&dev_stdcon_r
, &dev_stdcon_w
);
190 lowmem_buf
= lmalloc(LOWMEM_BUF_SIZE
);
192 printf("Could not allocate memory.\n");
196 sdi
= syslinux_derivative_info();
198 gfx_config
.sector_shift
= sdi
->disk
.sector_shift
;
199 gfx_config
.boot_drive
= sdi
->disk
.drive_number
;
201 if(sdi
->c
.filesystem
== SYSLINUX_FS_PXELINUX
) {
202 gfx_config
.sector_shift
= 11;
203 gfx_config
.boot_drive
= 0;
206 gfx_config
.media_type
= gfx_config
.boot_drive
< 0x80 ? 1 : 0;
208 if(sdi
->c
.filesystem
== SYSLINUX_FS_ISOLINUX
) {
209 gfx_config
.media_type
= sdi
->iso
.cd_mode
? 0 : 2;
212 gfx_config
.bootloader
= 1;
213 gfx_config
.sysconfig_size
= sizeof gfx_config
;
214 gfx_config
.bootloader_seg
= 0; // apparently not needed
217 printf("Usage: gfxboot.c32 bootlogo_file [message_file]\n");
218 if(argc
> 2) show_message(argv
[2]);
223 if(read_config_file("~")) {
224 printf("Error reading config file\n");
225 if(argc
> 2) show_message(argv
[2]);
230 if(getcwd(working_dir
, sizeof working_dir
)) {
231 gfx_config
.gfxboot_cwd
= (uint32_t) working_dir
;
234 if(gfx_init(argv
[1])) {
235 printf("Error setting up gfxboot\n");
236 if(argc
> 2) show_message(argv
[2]);
244 menu_index
= gfx_input();
246 // abort gfx, return to text mode prompt
247 if(menu_index
== -1) {
252 // does not return if it succeeds
256 if(argc
> 2) show_message(argv
[2]);
262 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
263 void show_message(char *file
)
268 if(!(f
= fopen(file
, "r"))) return;
270 while((c
= getc(f
)) != EOF
) {
271 if(c
< ' ' && c
!= '\n' && c
!= '\t') continue;
279 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
280 char *skip_nonspaces(char *s
)
282 while(*s
&& *s
!= ' ' && *s
!= '\t') s
++;
288 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
289 void chop_line(char *s
)
296 if(s
[i
] == ' ' || s
[i
] == '\t' || s
[i
] == '\n') {
306 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307 // Read and parse syslinux config file.
312 int read_config_file(const char *filename
)
315 char *s
, *t
, buf
[MAX_CONFIG_LINE_LEN
];
316 unsigned u
, top_level
= 0, text
= 0;
318 if(!strcmp(filename
, "~")) {
320 filename
= syslinux_config_file();
321 gfx_menu
.entries
= 0;
322 gfx_menu
.label_size
= 0;
323 gfx_menu
.arg_size
= 0;
326 menu_default
= calloc(1, sizeof *menu_default
);
329 if(!(f
= fopen(filename
, "r"))) return 1;
331 while((s
= fgets(buf
, sizeof buf
, f
))) {
334 if(!*s
|| *s
== '#') continue;
335 t
= skip_nonspaces(s
);
339 if(!strcasecmp(s
, "endtext")) {
347 if(!strcasecmp(s
, "timeout")) {
352 if(!strcasecmp(s
, "default")) {
353 menu_default
->label
= strdup(t
);
355 if(u
> gfx_menu
.label_size
) gfx_menu
.label_size
= u
;
359 if(!strcasecmp(s
, "label")) {
360 menu_ptr
= *menu_next
= calloc(1, sizeof **menu_next
);
361 menu_next
= &menu_ptr
->next
;
363 menu_ptr
->label
= menu_ptr
->menu_label
= strdup(t
);
365 if(u
> gfx_menu
.label_size
) gfx_menu
.label_size
= u
;
369 if(!strcasecmp(s
, "kernel") && menu_ptr
) {
370 menu_ptr
->kernel
= strdup(t
);
374 if(!strcasecmp(s
, "linux") && menu_ptr
) {
375 menu_ptr
->linux
= strdup(t
);
379 if(!strcasecmp(s
, "localboot") && menu_ptr
) {
380 menu_ptr
->localboot
= strdup(t
);
384 if(!strcasecmp(s
, "initrd") && menu_ptr
) {
385 menu_ptr
->initrd
= strdup(t
);
389 if(!strcasecmp(s
, "append")) {
390 (menu_ptr
?: menu_default
)->append
= strdup(t
);
392 if(u
> gfx_menu
.arg_size
) gfx_menu
.arg_size
= u
;
396 if(!strcasecmp(s
, "ipappend") || !strcasecmp(s
, "sysappend")) {
397 (menu_ptr
?: menu_default
)->ipappend
= strdup(t
);
401 if(!strcasecmp(s
, "text")) {
406 if(!strcasecmp(s
, "menu") && menu_ptr
) {
408 t
= skip_nonspaces(s
);
412 if(!strcasecmp(s
, "label")) {
413 menu_ptr
->menu_label
= strdup(t
);
415 if(u
> gfx_menu
.label_size
) gfx_menu
.label_size
= u
;
419 if(!strcasecmp(s
, "include")) {
424 if (!strcasecmp(s
, "include")) {
427 t
= skip_nonspaces(s
);
438 if (gfx_menu
.entries
== 0) {
439 printf("No LABEL keywords found.\n");
444 gfx_menu
.label_size
++;
447 // ensure we have a default entry
448 if(!menu_default
->label
) menu_default
->label
= menu
->label
;
450 if(menu_default
->label
) {
451 for(menu_ptr
= menu
; menu_ptr
; menu_ptr
= menu_ptr
->next
) {
452 if(!strcmp(menu_default
->label
, menu_ptr
->label
)) {
453 menu_default
->menu_label
= menu_ptr
->menu_label
;
459 gfx_menu
.default_entry
= menu_default
->menu_label
;
460 gfx_menu
.label_list
= calloc(gfx_menu
.entries
, gfx_menu
.label_size
);
461 gfx_menu
.arg_list
= calloc(gfx_menu
.entries
, gfx_menu
.arg_size
);
463 for(u
= 0, menu_ptr
= menu
; menu_ptr
; menu_ptr
= menu_ptr
->next
, u
++) {
464 if(!menu_ptr
->append
) menu_ptr
->append
= menu_default
->append
;
465 if(!menu_ptr
->ipappend
) menu_ptr
->ipappend
= menu_default
->ipappend
;
467 if(menu_ptr
->menu_label
) strcpy(gfx_menu
.label_list
+ u
* gfx_menu
.label_size
, menu_ptr
->menu_label
);
468 if(menu_ptr
->append
) strcpy(gfx_menu
.arg_list
+ u
* gfx_menu
.arg_size
, menu_ptr
->append
);
475 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
476 // Check header and return code start offset.
478 unsigned magic_ok(unsigned char *buf
, unsigned *code_size
)
481 *(unsigned *) buf
== 0x0b2d97f00 && // magic id
482 (buf
[4] == 8) // version 8
484 *code_size
= *(unsigned *) (buf
+ 12);
485 return *(unsigned *) (buf
+ 8);
492 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
493 // Search (cpio archive) for gfx file.
495 unsigned find_file(unsigned char *buf
, unsigned len
, unsigned *gfx_file_start
, unsigned *file_len
, unsigned *code_size
)
497 unsigned i
, fname_len
, code_start
= 0;
502 if((code_start
= magic_ok(buf
, code_size
))) return code_start
;
504 for(i
= 0; i
< len
;) {
505 if((len
- i
) >= 0x1a && (buf
[i
] + (buf
[i
+ 1] << 8)) == 0x71c7) {
506 fname_len
= *(unsigned short *) (buf
+ i
+ 20);
507 *file_len
= *(unsigned short *) (buf
+ i
+ 24) + (*(unsigned short *) (buf
+ i
+ 22) << 16);
510 if((code_start
= magic_ok(buf
+ i
, code_size
))) {
526 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
527 // Initialize gfxboot code.
532 int gfx_init(char *file
)
534 size_t archive_size
= 0;
536 unsigned code_start
, code_size
, file_start
, file_len
, u
;
538 void *lowmem
= lowmem_buf
;
539 unsigned lowmem_size
= LOWMEM_BUF_SIZE
;
543 printf("Loading %s...\n", file
);
544 if(loadfile(file
, &archive
, &archive_size
)) return 1;
546 if(!archive_size
) return 1;
548 // printf("%s: %d\n", file, archive_size);
550 gfx_config
.archive_start
= (uint32_t) archive
;
551 gfx_config
.archive_end
= gfx_config
.archive_start
+ archive_size
;
553 // locate file inside cpio archive
554 if(!(code_start
= find_file(archive
, archive_size
, &file_start
, &file_len
, &code_size
))) {
555 printf("%s: invalid file format\n", file
);
561 "code_start = 0x%x, code_size = 0x%x\n"
562 "archive_start = 0x%x, archive size = 0x%x\n"
563 "file_start = 0x%x, file_len = 0x%x\n",
564 code_start
, code_size
,
565 gfx_config
.archive_start
, archive_size
,
570 gfx_config
.file
= gfx_config
.archive_start
+ file_start
;
572 u
= realmode_callback_end
- realmode_callback_start
;
573 u
= (u
+ REALMODE_BUF_SIZE
+ 0xf) & ~0xf;
575 if(u
+ code_size
> lowmem_size
) {
576 printf("lowmem buffer too small: size %u, needed %u\n", lowmem_size
, u
+ code_size
);
580 memcpy(lowmem
+ REALMODE_BUF_SIZE
, realmode_callback_start
,
581 realmode_callback_end
- realmode_callback_start
);
583 // fill in buffer size and location
584 *(uint16_t *) (lowmem
+ REALMODE_BUF_SIZE
) = REALMODE_BUF_SIZE
;
585 *(uint16_t *) (lowmem
+ REALMODE_BUF_SIZE
+ 2) = (uint32_t) lowmem
>> 4;
587 gfx_config
.bootloader_seg
= ((uint32_t) lowmem
+ REALMODE_BUF_SIZE
) >> 4;
588 gfx_config
.callback
= 4; // start address
593 memcpy(lowmem
, archive
+ file_start
+ code_start
, code_size
);
595 gfx_config
.mem0_start
= (uint32_t) lowmem
+ code_size
;
596 gfx_config
.mem0_end
= (uint32_t) lowmem
+ lowmem_size
;
598 gfx_config
.mem0_start
= (gfx_config
.mem0_start
+ 0xf) & ~0xf;
600 gfx_config
.xmem_start
= (uint32_t) malloc(GFX_MEMORY_SIZE
<< 20);
601 if(gfx_config
.xmem_start
) {
602 gfx_config
.xmem_end
= gfx_config
.xmem_start
+ (GFX_MEMORY_SIZE
<< 20);
605 // fake; not used anyway
606 gfx_config
.bios_mem_size
= 256 << 20;
608 gfx
.code_seg
= (uint32_t) lowmem
>> 4;
610 for(u
= 0; u
< sizeof gfx
.jmp_table
/ sizeof *gfx
.jmp_table
; u
++) {
611 gfx
.jmp_table
[u
] = (gfx
.code_seg
<< 16) + *(uint16_t *) (lowmem
+ 2 * u
);
615 for(u
= 0; u
< sizeof gfx
.jmp_table
/ sizeof *gfx
.jmp_table
; u
++) {
616 printf("%d: 0x%08x\n", u
, gfx
.jmp_table
[u
]);
620 // we are ready to start
622 r
.esi
.l
= (uint32_t) &gfx_config
;
623 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_INIT
], &r
, &r
);
625 if((r
.eflags
.l
& EFLAGS_CF
)) {
626 printf("graphics initialization failed\n");
631 if((gfx_config
.features
& 3) != 3) {
634 printf("%s: boot graphics code too old, please use newer version\n", file
);
644 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
645 int gfx_menu_init(void)
649 r
.esi
.l
= (uint32_t) &gfx_menu
;
650 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_MENU_INIT
], &r
, &r
);
656 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
663 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_DONE
], &r
, &r
);
667 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
668 // Run gfxboot main loop.
671 // boot menu index (-1: go to text mode prompt)
677 r
.edi
.l
= (uint32_t) cmdline
;
678 r
.ecx
.l
= sizeof cmdline
;
679 r
.eax
.l
= timeout
* 182 / 100;
680 timeout
= 0; // use timeout only first time
681 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_INPUT
], &r
, &r
);
682 if((r
.eflags
.l
& EFLAGS_CF
)) r
.eax
.l
= 1;
684 if(r
.eax
.l
== 1) return -1;
690 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
691 void gfx_infobox(int type
, char *str1
, char *str2
)
696 r
.esi
.l
= (uint32_t) str1
;
697 r
.edi
.l
= (uint32_t) str2
;
698 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_INFOBOX_INIT
], &r
, &r
);
699 r
.edi
.l
= r
.eax
.l
= 0;
700 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_INPUT
], &r
, &r
);
701 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_INFOBOX_DONE
], &r
, &r
);
705 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
706 void gfx_progress_init(ssize_t kernel_size
, char *label
)
710 if(!progress_active
) {
711 r
.eax
.l
= kernel_size
>> gfx_config
.sector_shift
; // in sectors
712 r
.esi
.l
= (uint32_t) label
;
713 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_PROGRESS_INIT
], &r
, &r
);
720 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
721 void gfx_progress_update(ssize_t advance
)
725 if(progress_active
) {
726 r
.eax
.l
= advance
>> gfx_config
.sector_shift
; // in sectors
727 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_PROGRESS_UPDATE
], &r
, &r
);
732 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
733 void gfx_progress_done(void)
737 if(progress_active
) {
738 __farcall(gfx
.code_seg
, gfx
.jmp_table
[GFX_CB_PROGRESS_DONE
], &r
, &r
);
745 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
746 // Read file and update progress bar.
748 void *load_one(char *file
, ssize_t
*file_size
)
754 ssize_t size
= 0, cur
, i
;
758 if((fd
= open(file
, O_RDONLY
)) == -1) {
759 asprintf(&str
, "%s: file not found", file
);
760 gfx_infobox(0, str
, NULL
);
765 if(!fstat(fd
, &sbuf
) && S_ISREG(sbuf
.st_mode
)) size
= sbuf
.st_size
;
771 for(i
= 1, cur
= 0 ; cur
< size
&& i
> 0; cur
+= i
) {
772 i
= read(fd
, buf
+ cur
, min(CHUNK_SIZE
, size
- cur
));
774 gfx_progress_update(i
);
779 buf
= realloc(buf
, size
+ CHUNK_SIZE
);
780 i
= read(fd
, buf
+ size
, CHUNK_SIZE
);
783 gfx_progress_update(i
);
790 asprintf(&str
, "%s: read error @ %d", file
, size
);
791 gfx_infobox(0, str
, NULL
);
804 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
807 // cmdline can optionally start with label string.
811 char *arg
, *alt_kernel
;
815 const struct syslinux_ipappend_strings
*ipappend
;
816 char *gfxboot_cwd
= (char *) gfx_config
.gfxboot_cwd
;
820 gfx_config
.gfxboot_cwd
= 0;
823 for(menu_ptr
= menu
; menu_ptr
; menu_ptr
= menu_ptr
->next
, index
--) {
827 // invalid index or menu entry
828 if(!menu_ptr
|| !menu_ptr
->menu_label
) return;
830 arg
= skipspace(cmdline
);
831 label_len
= strlen(menu_ptr
->menu_label
);
833 // if it does not start with label string, assume first word is kernel name
834 if(strncmp(arg
, menu_ptr
->menu_label
, label_len
)) {
836 arg
= skip_nonspaces(arg
);
838 if(*alt_kernel
) menu_ptr
->alt_kernel
= alt_kernel
;
844 arg
= skipspace(arg
);
847 if(menu_ptr
->ipappend
&& (ipapp
= atoi(menu_ptr
->ipappend
))) {
848 ipappend
= syslinux_ipappend_strings();
849 for(i
= 0; i
< ipappend
->count
; i
++) {
850 if((ipapp
& (1 << i
)) && ipappend
->ptr
[i
]) {
851 sprintf(arg
+ strlen(arg
), " %s", ipappend
->ptr
[i
]);
856 boot_entry(menu_ptr
, arg
);
862 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
863 // Load & run kernel.
865 // Returns only on error.
867 void boot_entry(menu_t
*menu_ptr
, char *arg
)
869 void *kernel
, *initrd_buf
;
870 ssize_t kernel_size
= 0, initrd_size
= 0;
871 struct initramfs
*initrd
= NULL
;
872 char *file
, *cmd_buf
;
875 char *s
, *s0
, *t
, *initrd_arg
;
877 if(!menu_ptr
) return;
879 if(menu_ptr
->localboot
) {
881 syslinux_local_boot(strtol(menu_ptr
->localboot
, NULL
, 0));
886 file
= menu_ptr
->alt_kernel
;
887 if(!file
) file
= menu_ptr
->kernel
;
888 if(!file
) file
= menu_ptr
->linux
;
891 asprintf(&cmd_buf
, "%s %s", menu_ptr
->label
, arg
);
892 syslinux_run_command(cmd_buf
);
896 // first, load kernel
900 if((fd
= open(file
, O_RDONLY
)) >= 0) {
901 if(!fstat(fd
, &sbuf
) && S_ISREG(sbuf
.st_mode
)) kernel_size
= sbuf
.st_size
;
905 gfx_progress_init(kernel_size
, file
);
907 kernel
= load_one(file
, &kernel_size
);
913 if(kernel_size
< 1024 || *(uint32_t *) (kernel
+ 0x202) != 0x53726448) {
914 // not a linux kernel
916 asprintf(&cmd_buf
, "%s %s", menu_ptr
->label
, arg
);
917 syslinux_run_command(cmd_buf
);
921 // printf("kernel = %p, size = %d\n", kernel, kernel_size);
923 // parse cmdline for "initrd" option
925 initrd_arg
= menu_ptr
->initrd
;
927 s
= s0
= strdup(arg
);
929 while(*s
&& strncmp(s
, "initrd=", sizeof "initrd=" - 1)) {
930 s
= skipspace(skip_nonspaces(s
));
934 s
+= sizeof "initrd=" - 1;
935 *skip_nonspaces(s
) = 0;
938 else if(initrd_arg
) {
940 initrd_arg
= s0
= strdup(initrd_arg
);
944 initrd
= initramfs_init();
946 while((t
= strsep(&initrd_arg
, ","))) {
947 initrd_buf
= load_one(t
, &initrd_size
);
950 printf("%s: read error\n", t
);
955 initramfs_add_data(initrd
, initrd_buf
, initrd_size
, initrd_size
, 4);
957 // printf("initrd = %p, size = %d\n", initrd_buf, initrd_size);
965 syslinux_boot_linux(kernel
, kernel_size
, initrd
, NULL
, arg
);