mirror of
https://github.com/grub4dos/ntloader.git
synced 2025-05-08 19:51:14 +08:00
embed bcd
This commit is contained in:
parent
74b421ba89
commit
bbdafa058e
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -65,7 +65,6 @@ jobs:
|
||||
cp fsuuid.exe build/
|
||||
cp bmtool.exe build/
|
||||
cp mkinitrd.exe build/
|
||||
cp utils/bcd.bat build/
|
||||
- name: Download README.pdf
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,8 +17,10 @@ mkinitrd
|
||||
mkinitrd.exe
|
||||
bmtools
|
||||
bmtools.exe
|
||||
bin2c
|
||||
ntloader.i386
|
||||
ntloader.arm64
|
||||
ntloader.x86_64
|
||||
initrd.cpio
|
||||
docs/README.md
|
||||
include/bcd_raw.h
|
||||
|
6
Makefile
6
Makefile
@ -199,6 +199,9 @@ ntloader.%.efi : ntloader.%.elf elf2efi64 Makefile
|
||||
ntloader.% : ntloader.%.efi Makefile
|
||||
$(CP) $< $@
|
||||
|
||||
# Utilities
|
||||
include utils/build.mk
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# i386 objects
|
||||
@ -260,9 +263,6 @@ lib.arm64.a : $(OBJECTS_arm64) Makefile
|
||||
$(RM) -f $@
|
||||
$(AR_arm64) -r -s $@ $(OBJECTS_arm64)
|
||||
|
||||
# Utilities
|
||||
include utils/build.mk
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Cleanup
|
||||
|
@ -29,10 +29,5 @@ find * | cpio -o -H newc > ../initrd.cpio
|
||||
### bmtool
|
||||
`bmtool` is a program for extracting bootmgr.exe from bootmgr.
|
||||
|
||||
### bcd.bat
|
||||
`bcd.bat` is a batch script to create the BCD file.
|
||||
Do not edit it unless you know how NTloader works.
|
||||
:warning: Administrator privileges are required.
|
||||
|
||||
<div style="page-break-after: always;"></div>
|
||||
|
||||
|
@ -30,6 +30,18 @@
|
||||
#include "cmdline.h"
|
||||
#include "efi.h"
|
||||
|
||||
#ifdef __x86_64__
|
||||
extern unsigned char
|
||||
__i386_bcd_raw[] __attribute__ ((section (".bcd"), aligned (512)));
|
||||
extern unsigned int __i386_bcd_raw_len;
|
||||
#define BCD_RAW __i386_bcd_raw
|
||||
#define BCD_LEN __i386_bcd_raw_len
|
||||
#else
|
||||
#include "bcd_raw.h"
|
||||
#define BCD_RAW bcd_raw
|
||||
#define BCD_LEN bcd_raw_len
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Read virtual file from memory
|
||||
*
|
||||
@ -87,12 +99,6 @@ static int add_file (const char *name, void *data, size_t len)
|
||||
nt_cmdline->bootmgr_length = len;
|
||||
nt_cmdline->bootmgr = data;
|
||||
}
|
||||
else if (strcasecmp (name, "BCD") == 0)
|
||||
{
|
||||
DBG ("...found BCD\n");
|
||||
nt_cmdline->bcd_length = len;
|
||||
nt_cmdline->bcd = data;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -105,6 +111,12 @@ static int add_file (const char *name, void *data, size_t len)
|
||||
*/
|
||||
void extract_initrd (void *ptr, size_t len)
|
||||
{
|
||||
nt_cmdline->bcd_length = BCD_LEN;
|
||||
nt_cmdline->bcd = BCD_RAW;
|
||||
printf ("...load BCD @%p %c%c%c%c [%x]\n", BCD_RAW,
|
||||
BCD_RAW[0], BCD_RAW[1], BCD_RAW[2], BCD_RAW[3], BCD_LEN);
|
||||
vdisk_add_file ("BCD", BCD_RAW, BCD_LEN, read_mem_file);
|
||||
|
||||
if (cpio_extract (ptr, len, add_file) != 0)
|
||||
die ("FATAL: could not extract initrd files\n");
|
||||
|
||||
|
9
prefix.S
9
prefix.S
@ -171,6 +171,15 @@ setup:
|
||||
cld
|
||||
rep movsb
|
||||
|
||||
/* Copy bcd */
|
||||
movl $(LOADED_HIGH_ADDRESS + _payload_pos - SETUP_LEN), %eax
|
||||
addl $_payload_len, %eax
|
||||
movl %eax, %esi
|
||||
movl $_bcd, %edi
|
||||
movl $_bcd_len, %ecx
|
||||
cld
|
||||
rep movsb
|
||||
|
||||
/* Copy parameters required by runtime */
|
||||
movl %cs:( cmd_line_ptr - _prefix ), %eax
|
||||
movl %eax, i386(cmdline)
|
||||
|
14
script.lds
14
script.lds
@ -122,8 +122,20 @@ SECTIONS {
|
||||
}
|
||||
_bss_len = ABSOLUTE ( _ebss ) - ABSOLUTE ( _bss );
|
||||
|
||||
/* Windows Boot Configuration Data (BCD) section */
|
||||
_bcd_pos = ( _text_pos + _text_len );
|
||||
.bcd : AT ( _bcd_pos ) {
|
||||
_bcd = .;
|
||||
*(.bcd)
|
||||
*(.bcd.*)
|
||||
_ebcd = .;
|
||||
ASSERT ( ABSOLUTE ( . ) <= ABSOLUTE ( _ebda_start ),
|
||||
"Binary is too large (overlap the EBDA)" );
|
||||
}
|
||||
_bcd_len = ABSOLUTE ( _ebcd ) - ABSOLUTE ( _bcd );
|
||||
|
||||
/* Secure Boot Advanced Targeting (SBAT) section */
|
||||
_sbat_pos = ( _text_pos + _text_len );
|
||||
_sbat_pos = ( _bcd_pos + _bcd_len );
|
||||
.sbat : AT ( _sbat_pos ) {
|
||||
_sbat = .;
|
||||
*(.sbat)
|
||||
|
84
utils/bin2c.c
Normal file
84
utils/bin2c.c
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This is bin2c program, which allows you to convert binary file to
|
||||
* C language array, for use as embedded resource, for instance you
|
||||
* can embed graphics or audio file directly into your program.
|
||||
* This is public domain software, use it on your own risk.
|
||||
* Contact Serge Fukanchik at fuxx@mail.ru if you have any questions.
|
||||
*
|
||||
* Some modifications were made by
|
||||
* Gwilym Kuiper (kuiper.gwilym@gmail.com)
|
||||
* I have decided not to change the licence.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *buf;
|
||||
char *ident;
|
||||
unsigned int i, file_size, need_comma;
|
||||
|
||||
FILE *f_input, *f_output;
|
||||
|
||||
if (argc < 4)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Usage: %s INPUT OUTPUT ARRAY_NAME [ATTRIBUTE]\n",
|
||||
argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
f_input = fopen (argv[1], "rb");
|
||||
if (f_input == NULL)
|
||||
{
|
||||
fprintf (stderr, "can't open %s for reading\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the file length
|
||||
fseek (f_input, 0, SEEK_END);
|
||||
file_size = ftell (f_input);
|
||||
fseek (f_input, 0, SEEK_SET);
|
||||
|
||||
buf = (char *) malloc (file_size);
|
||||
assert (buf);
|
||||
|
||||
fread (buf, file_size, 1, f_input);
|
||||
fclose (f_input);
|
||||
|
||||
f_output = fopen (argv[2], "w");
|
||||
if (f_output == NULL)
|
||||
{
|
||||
fprintf (stderr, "can't open %s for writing\n", argv[2]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ident = argv[3];
|
||||
|
||||
need_comma = 0;
|
||||
|
||||
fprintf (f_output, "unsigned char %s[] %s = {",
|
||||
ident, argc >= 5 ? argv[4] : "");
|
||||
for (i = 0; i < file_size; ++i)
|
||||
{
|
||||
if (need_comma)
|
||||
fprintf (f_output, ", ");
|
||||
else
|
||||
need_comma = 1;
|
||||
if ((i % 11) == 0)
|
||||
fprintf (f_output, "\n ");
|
||||
fprintf (f_output, "0x%.2x", buf[i] & 0xff);
|
||||
}
|
||||
fprintf (f_output, "\n};\n\n");
|
||||
|
||||
fprintf (f_output,
|
||||
"unsigned int %s_len = %i;\n", ident, file_size);
|
||||
|
||||
fclose (f_output);
|
||||
|
||||
return 0;
|
||||
}
|
@ -64,3 +64,13 @@ bmtool : $(BMTOOL_FILES)
|
||||
$(HOST_CC) $(HOST_CFLAGS) -iquote include/ $(BMTOOL_FILES) -o $@
|
||||
|
||||
RM_FILES += bmtool bmtool.exe
|
||||
|
||||
# bin2c
|
||||
#
|
||||
bin2c : utils/bin2c.c
|
||||
$(HOST_CC) $(HOST_CFLAGS) $< -o $@
|
||||
include/bcd_raw.h : utils/bcd bin2c
|
||||
./bin2c utils/bcd $@ bcd_raw "__attribute__ ((section (\".bcd\"), aligned (512)))"
|
||||
|
||||
HEADERS += include/bcd_raw.h
|
||||
RM_FILES += bin2c include/bcd_raw.h
|
Loading…
x
Reference in New Issue
Block a user