boot: Compress ramdisk image with gzip
This commit is contained in:
parent
4a0492aad5
commit
abbe298cd7
2
.gitignore
vendored
2
.gitignore
vendored
@ -16,6 +16,7 @@
|
|||||||
/cdrom/netinit
|
/cdrom/netinit
|
||||||
/cdrom/mod/*
|
/cdrom/mod/*
|
||||||
/cdrom/ramdisk.img
|
/cdrom/ramdisk.img
|
||||||
|
/cdrom/ramdisk.igz
|
||||||
/cdrom/boot.sys
|
/cdrom/boot.sys
|
||||||
/cdrom/fat.img
|
/cdrom/fat.img
|
||||||
/fatbase/extra
|
/fatbase/extra
|
||||||
@ -23,6 +24,7 @@
|
|||||||
/fatbase/netinit
|
/fatbase/netinit
|
||||||
/fatbase/mod/*
|
/fatbase/mod/*
|
||||||
/fatbase/ramdisk.img
|
/fatbase/ramdisk.img
|
||||||
|
/fatbase/ramdisk.igz
|
||||||
/fatbase/efi/boot/bootia32.efi
|
/fatbase/efi/boot/bootia32.efi
|
||||||
/util/tarballs
|
/util/tarballs
|
||||||
/util/build
|
/util/build
|
||||||
|
14
Makefile
14
Makefile
@ -26,7 +26,7 @@ TARGET_TRIPLET=i686-pc-toaru
|
|||||||
CC=$(TARGET_TRIPLET)-gcc
|
CC=$(TARGET_TRIPLET)-gcc
|
||||||
AR=$(TARGET_TRIPLET)-ar
|
AR=$(TARGET_TRIPLET)-ar
|
||||||
AS=$(TARGET_TRIPLET)-as
|
AS=$(TARGET_TRIPLET)-as
|
||||||
CFLAGS= -O3 -g -std=gnu99 -I. -Iapps -pipe -mmmx -msse -msse2 -fplan9-extensions -Wall -Wextra -Wno-unused-parameter
|
CFLAGS= -O3 -s -std=gnu99 -I. -Iapps -pipe -mmmx -msse -msse2 -fplan9-extensions -Wall -Wextra -Wno-unused-parameter
|
||||||
|
|
||||||
##
|
##
|
||||||
# C library objects from libc/ C sources (and setjmp, which is assembly)
|
# C library objects from libc/ C sources (and setjmp, which is assembly)
|
||||||
@ -259,8 +259,10 @@ base/bin/%.krk: apps/%.krk
|
|||||||
chmod +x $@
|
chmod +x $@
|
||||||
|
|
||||||
# Ramdisk
|
# Ramdisk
|
||||||
fatbase/ramdisk.img: ${RAMDISK_FILES} $(shell find base) Makefile util/createramdisk.py | dirs
|
fatbase/ramdisk.igz: ${RAMDISK_FILES} $(shell find base) Makefile util/createramdisk.py | dirs
|
||||||
python3 util/createramdisk.py
|
python3 util/createramdisk.py
|
||||||
|
gzip -c fatbase/ramdisk.img > fatbase/ramdisk.igz
|
||||||
|
rm fatbase/ramdisk.img
|
||||||
|
|
||||||
# CD image
|
# CD image
|
||||||
|
|
||||||
@ -274,7 +276,7 @@ EFI_UPDATE=util/update-extents.py
|
|||||||
|
|
||||||
image.iso: ${EFI_BOOT} cdrom/boot.sys fatbase/netinit ${MODULES} util/update-extents.py
|
image.iso: ${EFI_BOOT} cdrom/boot.sys fatbase/netinit ${MODULES} util/update-extents.py
|
||||||
xorriso -as mkisofs -R -J -c bootcat \
|
xorriso -as mkisofs -R -J -c bootcat \
|
||||||
-b boot.sys -no-emul-boot -boot-load-size 24 \
|
-b boot.sys -no-emul-boot -boot-load-size full \
|
||||||
${EFI_XORRISO} \
|
${EFI_XORRISO} \
|
||||||
-o image.iso cdrom
|
-o image.iso cdrom
|
||||||
${EFI_UPDATE}
|
${EFI_UPDATE}
|
||||||
@ -286,7 +288,7 @@ image.iso: ${EFI_BOOT} cdrom/boot.sys fatbase/netinit ${MODULES} util/update-ext
|
|||||||
# This is the filesystem the EFI loaders see, so it must contain
|
# This is the filesystem the EFI loaders see, so it must contain
|
||||||
# the kernel, modules, and ramdisk, plus anything else we want
|
# the kernel, modules, and ramdisk, plus anything else we want
|
||||||
# available to the bootloader (eg., netinit).
|
# available to the bootloader (eg., netinit).
|
||||||
cdrom/fat.img: fatbase/ramdisk.img ${MODULES} fatbase/kernel fatbase/netinit fatbase/efi/boot/bootia32.efi fatbase/efi/boot/bootx64.efi util/mkdisk.sh | dirs
|
cdrom/fat.img: fatbase/ramdisk.igz ${MODULES} fatbase/kernel fatbase/netinit fatbase/efi/boot/bootia32.efi fatbase/efi/boot/bootx64.efi util/mkdisk.sh | dirs
|
||||||
util/mkdisk.sh $@ fatbase
|
util/mkdisk.sh $@ fatbase
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -317,7 +319,7 @@ cdrom/boot.sys: boot/boot.o boot/cstuff.o boot/link.ld | dirs
|
|||||||
${KLD} -T boot/link.ld -o $@ boot/boot.o boot/cstuff.o
|
${KLD} -T boot/link.ld -o $@ boot/boot.o boot/cstuff.o
|
||||||
|
|
||||||
boot/cstuff.o: boot/cstuff.c boot/*.h
|
boot/cstuff.o: boot/cstuff.c boot/*.h
|
||||||
${CC} -c -Os -o $@ $<
|
${CC} -c -Os -s -o $@ $<
|
||||||
|
|
||||||
boot/boot.o: boot/boot.S
|
boot/boot.o: boot/boot.S
|
||||||
${AS} -o $@ $<
|
${AS} -o $@ $<
|
||||||
@ -329,7 +331,7 @@ clean:
|
|||||||
rm -f ${APPS_X} ${APPS_SH_X}
|
rm -f ${APPS_X} ${APPS_SH_X}
|
||||||
rm -f libc/*.o libc/*/*.o
|
rm -f libc/*.o libc/*/*.o
|
||||||
rm -f image.iso
|
rm -f image.iso
|
||||||
rm -f fatbase/ramdisk.img
|
rm -f fatbase/ramdisk.img fatbase/ramdisk.igz
|
||||||
rm -f cdrom/boot.sys
|
rm -f cdrom/boot.sys
|
||||||
rm -f boot/*.o
|
rm -f boot/*.o
|
||||||
rm -f boot/*.efi
|
rm -f boot/*.efi
|
||||||
|
@ -6,6 +6,18 @@ EFI_HANDLE ImageHandleIn;
|
|||||||
# include "types.h"
|
# include "types.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _BOOT_LOADER
|
||||||
|
struct huff_ring;
|
||||||
|
struct inflate_context {
|
||||||
|
void * input_priv;
|
||||||
|
void * output_priv;
|
||||||
|
uint8_t (*get_input)(struct inflate_context * ctx);
|
||||||
|
void (*write_output)(struct inflate_context * ctx, unsigned int sym);
|
||||||
|
int bit_buffer;
|
||||||
|
int buffer_size;
|
||||||
|
struct huff_ring * ring;
|
||||||
|
};
|
||||||
|
#include "../lib/inflate.c"
|
||||||
#include "ata.h"
|
#include "ata.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -49,7 +61,7 @@ EFI_HANDLE ImageHandleIn;
|
|||||||
|
|
||||||
char * module_dir = "MOD";
|
char * module_dir = "MOD";
|
||||||
char * kernel_path = "KERNEL.";
|
char * kernel_path = "KERNEL.";
|
||||||
char * ramdisk_path = "RAMDISK.IMG";
|
char * ramdisk_path = "RAMDISK.IGZ";
|
||||||
|
|
||||||
#ifdef EFI_PLATFORM
|
#ifdef EFI_PLATFORM
|
||||||
int _efi_do_mode_set = 0;
|
int _efi_do_mode_set = 0;
|
||||||
|
@ -418,6 +418,19 @@ done_video:
|
|||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static uint8_t _get(struct inflate_context * ctx) {
|
||||||
|
uint8_t * x = ctx->input_priv;
|
||||||
|
uint8_t out = *x++;
|
||||||
|
ctx->input_priv = (void*)x;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _write(struct inflate_context * ctx, unsigned int sym) {
|
||||||
|
uint8_t * x = ctx->output_priv;
|
||||||
|
*x++ = (uint8_t)sym;
|
||||||
|
ctx->output_priv = (void*)x;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef EFI_PLATFORM
|
#ifndef EFI_PLATFORM
|
||||||
static void do_it(struct ata_device * _device) {
|
static void do_it(struct ata_device * _device) {
|
||||||
device = _device;
|
device = _device;
|
||||||
@ -480,30 +493,45 @@ done:
|
|||||||
if (navigate(ramdisk_path)) {
|
if (navigate(ramdisk_path)) {
|
||||||
//clear_();
|
//clear_();
|
||||||
ramdisk_off = KERNEL_LOAD_START + offset;
|
ramdisk_off = KERNEL_LOAD_START + offset;
|
||||||
ramdisk_len = dir_entry->extent_length_LSB;
|
|
||||||
modules_mboot[multiboot_header.mods_count-1].mod_start = ramdisk_off;
|
|
||||||
modules_mboot[multiboot_header.mods_count-1].mod_end = ramdisk_off + ramdisk_len;
|
|
||||||
|
|
||||||
print_("Loading ramdisk");
|
print_("Loading ramdisk");
|
||||||
|
|
||||||
int i = dir_entry->extent_start_LSB;
|
int i = dir_entry->extent_start_LSB;
|
||||||
int sectors = dir_entry->extent_length_LSB / 2048 + 1;
|
int sectors = dir_entry->extent_length_LSB / 2048 + 1;
|
||||||
|
size_t off = 0;
|
||||||
|
#define RAMDISK_OFFSET 0x5000000
|
||||||
#define SECTORS 512
|
#define SECTORS 512
|
||||||
while (sectors >= SECTORS) {
|
while (sectors >= SECTORS) {
|
||||||
print_(".");
|
print_(".");
|
||||||
ata_device_read_sectors_atapi(device, i, (uint8_t *)KERNEL_LOAD_START + offset, SECTORS);
|
ata_device_read_sectors_atapi(device, i, (uint8_t *)RAMDISK_OFFSET + off, SECTORS);
|
||||||
|
|
||||||
sectors -= SECTORS;
|
sectors -= SECTORS;
|
||||||
offset += 2048 * SECTORS;
|
off += 2048 * SECTORS;
|
||||||
i += SECTORS;
|
i += SECTORS;
|
||||||
}
|
}
|
||||||
if (sectors > 0) {
|
if (sectors > 0) {
|
||||||
print_("!");
|
print_("!");
|
||||||
ata_device_read_sectors_atapi(device, i, (uint8_t *)KERNEL_LOAD_START + offset, sectors);
|
ata_device_read_sectors_atapi(device, i, (uint8_t *)RAMDISK_OFFSET + off, sectors);
|
||||||
offset += 2048 * sectors;
|
off += 2048 * sectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
final_offset = (uint8_t *)KERNEL_LOAD_START + offset;
|
struct inflate_context ctx;
|
||||||
|
ctx.input_priv = (char *)RAMDISK_OFFSET;
|
||||||
|
ctx.output_priv = (char *)ramdisk_off;
|
||||||
|
ctx.get_input = _get;
|
||||||
|
ctx.write_output = _write;
|
||||||
|
ctx.ring = NULL; /* Use the global one */
|
||||||
|
print_("\nDecompressing ramdisk... ");
|
||||||
|
if (gzip_decompress(&ctx)) {
|
||||||
|
print_("Failed?\n");
|
||||||
|
}
|
||||||
|
ramdisk_len = (uint32_t)ctx.output_priv - ramdisk_off;
|
||||||
|
|
||||||
|
modules_mboot[multiboot_header.mods_count-1].mod_start = ramdisk_off;
|
||||||
|
modules_mboot[multiboot_header.mods_count-1].mod_end = ramdisk_off + ramdisk_len;
|
||||||
|
|
||||||
|
final_offset = ((uint8_t *)ctx.output_priv) + ((uintptr_t)ctx.output_priv) % 4096;
|
||||||
|
|
||||||
set_attr(0x07);
|
set_attr(0x07);
|
||||||
print("Done.\n");
|
print("Done.\n");
|
||||||
move_kernel();
|
move_kernel();
|
||||||
@ -868,12 +896,24 @@ _try_module_again:
|
|||||||
status = uefi_call_wrapper(root->Open,
|
status = uefi_call_wrapper(root->Open,
|
||||||
5, root, &file, name, EFI_FILE_MODE_READ, 0);
|
5, root, &file, name, EFI_FILE_MODE_READ, 0);
|
||||||
if (!EFI_ERROR(status)) {
|
if (!EFI_ERROR(status)) {
|
||||||
|
#define RAMDISK_OFFSET 0x5000000
|
||||||
status = uefi_call_wrapper(file->Read,
|
status = uefi_call_wrapper(file->Read,
|
||||||
3, file, &bytes, (void *)(KERNEL_LOAD_START + (uintptr_t)offset));
|
3, file, &bytes, (void *)(RAMDISK_OFFSET));
|
||||||
if (!EFI_ERROR(status)) {
|
if (!EFI_ERROR(status)) {
|
||||||
|
struct inflate_context ctx;
|
||||||
|
ctx.input_priv = (char *)RAMDISK_OFFSET;
|
||||||
|
ctx.output_priv = (char *)KERNEL_LOAD_START + offset;
|
||||||
|
ctx.get_input = _get;
|
||||||
|
ctx.write_output = _write;
|
||||||
|
ctx.ring = NULL; /* Use the global one */
|
||||||
|
print_("\nDecompressing ramdisk... ");
|
||||||
|
if (gzip_decompress(&ctx)) {
|
||||||
|
print_("Failed?\n");
|
||||||
|
}
|
||||||
|
|
||||||
print_("Loaded "); print_(c); print_("\n");
|
print_("Loaded "); print_(c); print_("\n");
|
||||||
modules_mboot[multiboot_header.mods_count-1].mod_start = KERNEL_LOAD_START + offset;
|
modules_mboot[multiboot_header.mods_count-1].mod_start = KERNEL_LOAD_START + offset;
|
||||||
modules_mboot[multiboot_header.mods_count-1].mod_end = KERNEL_LOAD_START + offset + bytes;
|
modules_mboot[multiboot_header.mods_count-1].mod_end = (uintptr_t)ctx.output_priv;
|
||||||
offset += bytes;
|
offset += bytes;
|
||||||
while (offset % 4096) offset++;
|
while (offset % 4096) offset++;
|
||||||
final_offset = (uint8_t *)KERNEL_LOAD_START + offset;
|
final_offset = (uint8_t *)KERNEL_LOAD_START + offset;
|
||||||
|
@ -12,8 +12,8 @@ SPACE_REQ=$(du -sb "$DIR/../fatbase" | cut -f 1)
|
|||||||
let "SIZE = ($SPACE_REQ / 1000000)"
|
let "SIZE = ($SPACE_REQ / 1000000)"
|
||||||
|
|
||||||
# Minimum size
|
# Minimum size
|
||||||
if [ $SIZE -lt 24 ]; then
|
if [ $SIZE -lt 14 ]; then
|
||||||
SIZE=24
|
SIZE=14
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use more sectors-per-cluster for larger disk sizes
|
# Use more sectors-per-cluster for larger disk sizes
|
||||||
|
Loading…
Reference in New Issue
Block a user