Remove the notion of "sys*"

- This idea originates from very early in the project and was, at the
  time, a very easy way to categorise things.
- Now, it doesn't really make much sense - it is fairly arbitary, often
  occuring when there is a change in kernel, but not from builder-hex0
  to fiwix, and sysb is in reality completely unnecessary.
- In short, the sys* stuff is a bit of a mess that makes the project
  more difficult to understand.
- This puts everything down into one folder and has a manifest file that
  is used to generate the build scripts on the fly rather than using
  coded scripts.
- This is created in the "seed" stage.

stage0-posix -- (calls) --> seed -- (generates) --> main steps

Alongside this change there are a variety of other smaller fixups to the
general structure of the live-bootstrap rootfs.

- Creating a rootfs has become much simpler and is defined as code in
  go.sh. The new structure, for an about-to-be booted system, is

/
-- /steps (direct copy of steps/)
-- /distfiles (direct copy of distfiles/)
-- all files from seed/*
-- all files from seed/stage0-posix/*

- There is no longer such a thing as /usr/include/musl, this didn't
  really make any sense, as musl is the final libc used. Rather, to
  separate musl and mes, we have /usr/include/mes, which is much easier
  to work with.
- This also makes mes easier to blow away later.
- A few things that weren't properly in packages have been changed;
  checksum-transcriber, simple-patch, kexec-fiwix have all been given
  fully qualified package names.
- Highly breaking change, scripts now exist in their package directory
  but NOT WITH THE packagename.sh. Rather, they use pass1.sh, pass2.sh,
  etc. This avoids manual definition of passes.
  - Ditto with patches; default directory is patches, but then any patch
    series specific to a pass are named patches-passX.
This commit is contained in:
fosslinux 2023-11-07 10:51:23 +11:00
parent 0907cfd073
commit 6ed2e09f3a
546 changed files with 700 additions and 1299 deletions

View file

@ -0,0 +1,228 @@
/* SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "multiboot1.h"
#define MULTIBOOT_MAGIC 0x2BADB002
#define INITRD_MB 1152
int main() {
/* Read the kernel */
printf("kexec-fiwix: starting...\n\n");
FILE *fiwix_file = fopen("/boot/fiwix", "r");
fseek(fiwix_file, 0, SEEK_END);
int fiwix_len = ftell(fiwix_file);
printf("kexec-fiwix: Fiwix kernel file length: %d\n", fiwix_len);
puts("kexec-fiwix: Reading kernel...");
fseek(fiwix_file, 0, SEEK_SET);
char * fiwix_mem = malloc(fiwix_len);
int read_len = fread(fiwix_mem, fiwix_len, 1, fiwix_file);
fclose(fiwix_file);
if (read_len < 1) {
printf("kexec-fiwix: kernel fread error: %d\n", read_len);
return EXIT_FAILURE;
}
/* Display info from ELF header */
unsigned int e_entry = *((unsigned int *) (&fiwix_mem[0x18]));
printf("ELF virtual entry point : 0x%x\n", e_entry);
unsigned int e_phoff = *((unsigned int *) (&fiwix_mem[0x1C]));
printf("ELF program header offset : 0x%x\n", e_phoff);
unsigned int e_phnum = *((unsigned int *) (&fiwix_mem[0x2C]));
e_phnum &= 0xFFFF;
printf("ELF number of program headers: %d\n", e_phnum);
unsigned int e_phentsize = *((unsigned int *) (&fiwix_mem[0x2A]));
e_phentsize &= 0xFFFF;
printf("ELF size of program headers : %d\n", e_phentsize);
/* Load the kernel */
puts("kexec-fiwix: Placing kernel in memory...");
int header_num;
for (header_num = 0; header_num < e_phnum; header_num++) {
char * fiwix_prog_header = &fiwix_mem[e_phoff + header_num * e_phentsize];
unsigned int p_offset = *((unsigned int *) (&fiwix_prog_header[0x04]));
unsigned int p_vaddr = *((unsigned int *) (&fiwix_prog_header[0x08]));
unsigned int p_paddr = *((unsigned int *) (&fiwix_prog_header[0x0C]));
unsigned int p_filesz = *((unsigned int *) (&fiwix_prog_header[0x10]));
unsigned int p_memsz = *((unsigned int *) (&fiwix_prog_header[0x14]));
if (header_num == 0) {
e_entry -= (p_vaddr - p_paddr);
printf("ELF physical entry point : 0x%x\n", e_entry);
}
printf("header %d:\n", header_num);
printf(" p_offset: 0x%08x\n", p_offset);
printf(" p_paddr : 0x%08x\n", p_paddr);
printf(" p_filesz: 0x%08x\n", p_filesz);
printf(" p_memsz : 0x%08x\n", p_memsz);
memset((void *)p_paddr, 0, p_memsz + 0x10000);
memcpy((void *)p_paddr, &fiwix_mem[p_offset], p_filesz);
}
puts("Preparing multiboot info for kernel...");
char cmdline[256];
/* Don't use a serial console if configured for bare metal */
char *bare_metal = getenv("BARE_METAL");
if (bare_metal != NULL && strcmp(bare_metal, "True") == 0)
{
sprintf(cmdline, "fiwix root=/dev/ram0 ramdisksize=%d initrd=fiwix.ext2 kexec_proto=linux kexec_size=280000 kexec_cmdline=\"init=/init\"", INITRD_MB * 1024);
}
else
{
sprintf(cmdline, "fiwix console=/dev/ttyS0 root=/dev/ram0 ramdisksize=%d initrd=fiwix.ext2 kexec_proto=linux kexec_size=280000 kexec_cmdline=\"init=/init console=ttyS0\"", INITRD_MB * 1024);
}
char * boot_loader_name = "kexec-fiwix";
unsigned int next_avail_mem = 0x9800;
multiboot_info_t * pmultiboot_info = (multiboot_info_t *) next_avail_mem;
memset(pmultiboot_info, 0, sizeof(multiboot_info_t));
pmultiboot_info->flags = MULTIBOOT_INFO_BOOT_LOADER_NAME
| MULTIBOOT_INFO_MEMORY
| MULTIBOOT_INFO_CMDLINE
| MULTIBOOT_INFO_MODS
| MULTIBOOT_INFO_MEM_MAP;
next_avail_mem += sizeof(multiboot_info_t);
pmultiboot_info->mem_lower = 0x0000027F;
pmultiboot_info->mem_upper = 0x002FFB80;
/* Set command line */
pmultiboot_info->cmdline = next_avail_mem;
strcpy((char *) next_avail_mem, cmdline);
next_avail_mem += (strlen(cmdline) + 1);
/* Set ramdrive info */
pmultiboot_info->mods_count = 1;
pmultiboot_info->mods_addr = next_avail_mem;
multiboot_module_t *pmultiboot_module = (multiboot_module_t *) next_avail_mem;
pmultiboot_module->mod_start = 0x1C6000;
pmultiboot_module->mod_end = 0x1C6000 + (INITRD_MB * 1024 * 1024);
next_avail_mem += sizeof(multiboot_module_t);
pmultiboot_module->cmdline = next_avail_mem;
strcpy((char *) next_avail_mem, "fiwix.ext2");
next_avail_mem += (strlen("fiwix.ext2") + 1);
/* Set memory map info */
pmultiboot_info->mmap_addr = next_avail_mem;
pmultiboot_info->mmap_length = 7 * sizeof(multiboot_memory_map_t);
multiboot_memory_map_t *pmultiboot_memory_map = (multiboot_memory_map_t *) next_avail_mem;
pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t);
pmultiboot_memory_map->addr = 0x00000000;
pmultiboot_memory_map->len = 0x0009FC00;
pmultiboot_memory_map->type = MULTIBOOT_MEMORY_AVAILABLE;
pmultiboot_memory_map++;
pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t);
pmultiboot_memory_map->addr = 0x0009FC00;
pmultiboot_memory_map->len = 0x00000400;
pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED;
pmultiboot_memory_map++;
pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t);
pmultiboot_memory_map->addr = 0x000F0000;
pmultiboot_memory_map->len = 0x00010000;
pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED;
pmultiboot_memory_map++;
pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t);
pmultiboot_memory_map->addr = 0x00100000;
pmultiboot_memory_map->len = 0xBFEE0000;
pmultiboot_memory_map->type = MULTIBOOT_MEMORY_AVAILABLE;
pmultiboot_memory_map++;
pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t);
pmultiboot_memory_map->addr = 0XBFFE0000;
pmultiboot_memory_map->len = 0x00020000;
pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED;
pmultiboot_memory_map++;
pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t);
pmultiboot_memory_map->addr = 0XFEFFC000;
pmultiboot_memory_map->len = 0x00004000;
pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED;
pmultiboot_memory_map++;
pmultiboot_memory_map->size = sizeof(multiboot_memory_map_t) - sizeof(multiboot_uint32_t);
pmultiboot_memory_map->addr = 0XFFFC0000;
pmultiboot_memory_map->len = 0x00040000;
pmultiboot_memory_map->type = MULTIBOOT_MEMORY_RESERVED;
pmultiboot_memory_map++;
next_avail_mem += pmultiboot_info->mmap_length;
/* Set boot loader name */
pmultiboot_info->boot_loader_name = next_avail_mem;
strcpy((char *) next_avail_mem, boot_loader_name);
/* next_avail_mem += (strlen(boot_loader_name) + 1); */
/* Jump to kernel entry point */
unsigned int magic = MULTIBOOT_BOOTLOADER_MAGIC;
unsigned int dummy = 0;
unsigned int multiboot_info_num = (unsigned int) pmultiboot_info;
int filenum;
unsigned int filename_addr;
for (filenum = 4, filename_addr = 0x201000; filenum <= 14335; filenum++, filename_addr += 1024) {
if (!strcmp((char *) filename_addr, "/boot/fiwix.ext2")) {
printf("Found image at filenum %d\n", filenum);
break;
}
}
unsigned int initrd_src = *((unsigned int *) (0x01000000 + (16 * filenum) + 4));
unsigned int initrd_len = *((unsigned int *) (0x01000000 + (16 * filenum) + 8));
printf("initrd_src: 0x%08x\n", initrd_src);
printf("initrd_len: 0x%08x\n", initrd_len);
printf("Preparing trampoline...\n");
/* The ramdrive needs to be written to a location that would overwrite this program.
* Therfore, the code that copies the ram drive and jumps to the kernel needs to be
* run from a safe location. So, we put that code into an array variable and
* copy the code (called a "trampoline") to a safe location and then jump to it.
* The 0x00000000 values below are place holders which are set below
*/
char trampoline[] = {
0xBE, 0x00, 0x00, 0x00, 0x00, /* mov esi, 0x00000000 */
0xBF, 0x00, 0x00, 0x00, 0x00, /* mov edi, 0x00000000 */
0xB9, 0x00, 0x00, 0x00, 0x00, /* mov ecx, 0x00000000 */
0xFC, /* cld */
0xF3, 0xA4, /* rep movsb */
0xB8, 0x00, 0x00, 0x00, 0x00, /* mov eax, 0x00000000 */
0xBB, 0x00, 0x00, 0x00, 0x00, /* mov ebx, 0x00000000 */
0xEA, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 /* jmp far 0x0008:0x00000000 */
};
/* Set place holder values */
*((unsigned int *) &trampoline[1]) = initrd_src;
*((unsigned int *) &trampoline[6]) = 0x001C6000;
*((unsigned int *) &trampoline[11]) = INITRD_MB * 1024 * 1024;
*((unsigned int *) &trampoline[19]) = magic;
*((unsigned int *) &trampoline[24]) = multiboot_info_num;
*((unsigned int *) &trampoline[29]) = e_entry;
memcpy((void *)0x4000, trampoline, sizeof(trampoline));
printf("kexec-fiwix: jumping to trampoline...\n");
__asm__ __volatile__ (
"ljmp $0x8, $0x00004000\n\t"
);
}

View file

@ -0,0 +1,353 @@
/* multiboot.h - Multiboot header file. */
/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SPDX-FileCopyrightText: 2010 FSF <licensing@fsf.org>
* SPDX-License-Identifier: MIT
*/
#ifndef MULTIBOOT_HEADER
#define MULTIBOOT_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT_SEARCH 8192
#define MULTIBOOT_HEADER_ALIGN 4
/* The magic field should contain this. */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
/* This should be in %eax. */
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
/* Alignment of multiboot modules. */
#define MULTIBOOT_MOD_ALIGN 0x00001000
/* Alignment of the multiboot info structure. */
#define MULTIBOOT_INFO_ALIGN 0x00000004
/* Flags set in the flags member of the multiboot header. */
/* Align all boot modules on i386 page (4KB) boundaries. */
#define MULTIBOOT_PAGE_ALIGN 0x00000001
/* Must pass memory information to OS. */
#define MULTIBOOT_MEMORY_INFO 0x00000002
/* Must pass video information to OS. */
#define MULTIBOOT_VIDEO_MODE 0x00000004
/* This flag indicates the use of the address fields in the header. */
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
/* Flags to be set in the flags member of the multiboot info structure. */
/* is there basic lower/upper memory information? */
#define MULTIBOOT_INFO_MEMORY 0x00000001
/* is there a boot device set? */
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
/* is the command-line defined? */
#define MULTIBOOT_INFO_CMDLINE 0x00000004
/* are there modules to do something with? */
#define MULTIBOOT_INFO_MODS 0x00000008
/* These next two are mutually exclusive */
/* is there a symbol table loaded? */
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
/* is there an ELF section header table? */
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
/* is there a full memory map? */
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
/* Is there drive info? */
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
/* Is there a config table? */
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
/* Is there a boot loader name? */
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
/* Is there a APM table? */
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
/* Is there video information? */
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
#ifndef ASM_FILE
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
/* Feature flags. */
multiboot_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_uint32_t mode_type;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
};
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */
struct multiboot_elf_section_header_table
{
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
multiboot_uint32_t shndx;
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info
{
/* Multiboot info version number */
multiboot_uint32_t flags;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
/* "root" partition */
multiboot_uint32_t boot_device;
/* Kernel command line */
multiboot_uint32_t cmdline;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
union
{
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
/* ROM configuration table */
multiboot_uint32_t config_table;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
/* APM table */
multiboot_uint32_t apm_table;
/* Video */
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
union
{
struct
{
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
};
struct
{
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
};
};
};
typedef struct multiboot_info multiboot_info_t;
struct multiboot_color
{
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
};
struct multiboot_mmap_entry
{
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
} __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list
{
/* the memory used goes from bytes mod_start to mod_end-1 inclusive */
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
/* Module command line */
multiboot_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad;
};
typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */
struct multiboot_apm_info
{
multiboot_uint16_t version;
multiboot_uint16_t cseg;
multiboot_uint32_t offset;
multiboot_uint16_t cseg_16;
multiboot_uint16_t dseg;
multiboot_uint16_t flags;
multiboot_uint16_t cseg_len;
multiboot_uint16_t cseg_16_len;
multiboot_uint16_t dseg_len;
};
/* VBE controller information. */
struct vbe_controller
{
unsigned char signature[4];
unsigned short version;
unsigned long oem_string;
unsigned long capabilities;
unsigned long video_mode;
unsigned short total_memory;
unsigned short oem_software_rev;
unsigned long oem_vendor_name;
unsigned long oem_product_name;
unsigned long oem_product_rev;
unsigned char reserved[222];
unsigned char oem_data[256];
} __attribute__ ((packed));
/* VBE mode information. */
struct vbe_mode
{
unsigned short mode_attributes;
unsigned char win_a_attributes;
unsigned char win_b_attributes;
unsigned short win_granularity;
unsigned short win_size;
unsigned short win_a_segment;
unsigned short win_b_segment;
unsigned long win_func;
unsigned short bytes_per_scanline;
/* >=1.2 */
unsigned short x_resolution;
unsigned short y_resolution;
unsigned char x_char_size;
unsigned char y_char_size;
unsigned char number_of_planes;
unsigned char bits_per_pixel;
unsigned char number_of_banks;
unsigned char memory_model;
unsigned char bank_size;
unsigned char number_of_image_pages;
unsigned char reserved0;
/* direct color */
unsigned char red_mask_size;
unsigned char red_field_position;
unsigned char green_mask_size;
unsigned char green_field_position;
unsigned char blue_mask_size;
unsigned char blue_field_position;
unsigned char reserved_mask_size;
unsigned char reserved_field_position;
unsigned char direct_color_mode_info;
/* >=2.0 */
unsigned long phys_base;
unsigned long reserved1;
unsigned short reversed2;
/* >=3.0 */
unsigned short linear_bytes_per_scanline;
unsigned char banked_number_of_image_pages;
unsigned char linear_number_of_image_pages;
unsigned char linear_red_mask_size;
unsigned char linear_red_field_position;
unsigned char linear_green_mask_size;
unsigned char linear_green_field_position;
unsigned char linear_blue_mask_size;
unsigned char linear_blue_field_position;
unsigned char linear_reserved_mask_size;
unsigned char linear_reserved_field_position;
unsigned long max_pixel_clock;
unsigned char reserved3[190];
} __attribute__ ((packed));
#endif /* ! ASM_FILE */
#endif /* ! MULTIBOOT_HEADER */