Changeset 63a045c in mainline for boot/arch/ppc32


Ignore:
Timestamp:
2018-10-10T17:41:44Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9286475
Parents:
63c1dd5
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-10 17:11:15)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-10 17:41:44)
Message:

Unify handling of compressed init data and use regular tar + gzip to achieve it

There are two issues this commit solves.

First is that architecture-specific code duplicates most of the init binary
handling in each architecture, each with miniscule and confusing variations.
After this commit, the init binary expansion is almost entirely handled by
unified generic code.

Second is that the way we used to generate the incorporated data is somewhat
convoluted. Previously we have a Python script which generates a zip archive
with individual deflate-compressed files and accompanying header and C files
which contain structures describing the archive contents.
The zip file is then extracted and the individual deflate-compressed files are
included in the binary via assembler code.
Since gas doesn't take particular care to be consistent between architectures,
the assembly portions are also not uniform and the build script needs to know
particulars of the architecture's assembly.

Instead of doing that, after this commit we first gzip each included file, then
we pack the gzipped files into a tar archive, and then we include the archive
into the binary using objcopy.
Linker script provides symbols for the start and end of the archive,
and the payload is in a self-describing format, so there is no need for any
generated code.

Note that we are doing the opposite of the conventional .tar.gz format.
It would be somewhat inconvenient to use .tar.gz since the uncompressed files
need to be aligned to page size, so we'd have to first decompress the entire
payload to determine the final position of the files (and hence the required
amount of memory).

Location:
boot/arch/ppc32
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/ppc32/Makefile.inc

    r63c1dd5 r63a045c  
    6161        arch/$(BARCH)/src/main.c \
    6262        arch/$(BARCH)/src/ofw.c \
    63         $(COMPS).s \
    64         $(COMPS)_desc.c \
     63        $(COMPS).o \
    6564        genarch/src/ofw.c \
    6665        genarch/src/ofw_tree.c \
     
    7473        generic/src/str.c \
    7574        generic/src/version.c \
    76         generic/src/inflate.c
    77 
    78 PRE_DEPEND = $(COMPS).s $(COMPS).h $(COMPS)_desc.c $(COMPONENTS_DEFLATE)
     75        generic/src/inflate.c \
     76        generic/src/gzip.c \
     77        generic/src/tar.c \
     78        generic/src/payload.c
  • boot/arch/ppc32/_link.ld.in

    r63c1dd5 r63a045c  
    44        . = 0x08000000;
    55        .text : {
     6                loader_start = .;
    67                *(BOOTSTRAP);
    78                *(REALMODE);
     
    1819                *(.bss);        /* uninitialized static variables */
    1920                *(COMMON);      /* global variables */
    20                 *(.components);
     21                loader_end = .;
     22                payload_start = .;
     23                *(.payload);
     24                payload_end = .;
    2125        }
    2226
  • boot/arch/ppc32/src/main.c

    r63c1dd5 r63a045c  
    4141#include <str.h>
    4242#include <errno.h>
    43 #include <inflate.h>
    44 #include "../../components.h"
     43#include <payload.h>
    4544
    4645#define BALLOC_MAX_SIZE  131072
     
    7473            (void *) LOADER_ADDRESS, loader_address_pa);
    7574
    76         size_t i;
    77         for (i = 0; i < COMPONENTS; i++)
    78                 printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
    79                     ofw_translate(components[i].addr), components[i].name,
    80                     components[i].inflated, components[i].size);
     75        size_t uncompressed_size = payload_uncompressed_size();
     76        printf("Payload uncompressed size: %d bytes\n", uncompressed_size);
    8177
    82         size_t dest[COMPONENTS];
    83         size_t top = 0;
    84         size_t cnt = 0;
    85         bootinfo.taskmap.cnt = 0;
    86         for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    87                 top = ALIGN_UP(top, PAGE_SIZE);
    88 
    89                 if (i > 0) {
    90                         bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
    91                             (void *) PA2KA(top);
    92                         bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
    93                             components[i].inflated;
    94 
    95                         str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
    96                             BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    97 
    98                         bootinfo.taskmap.cnt++;
    99                 }
    100 
    101                 dest[i] = top;
    102                 top += components[i].inflated;
    103                 cnt++;
    104         }
    105 
    106         if (top >= (size_t) loader_address_pa) {
     78        if (uncompressed_size >= (size_t) loader_address_pa) {
    10779                printf("Inflated components overlap loader area.\n");
    10880                printf("The boot image is too large. Halting.\n");
     
    11890        void *inflate_base;
    11991        void *inflate_base_pa;
    120         ofw_alloc("inflate area", &inflate_base, &inflate_base_pa, top,
    121             loader_address_pa);
     92        ofw_alloc("inflate area", &inflate_base, &inflate_base_pa,
     93            uncompressed_size, loader_address_pa);
    12294        printf(" %p|%p: inflate area\n", inflate_base, inflate_base_pa);
    12395
    124         uintptr_t balloc_start = ALIGN_UP(top, PAGE_SIZE);
     96        uintptr_t balloc_start = ALIGN_UP(uncompressed_size, PAGE_SIZE);
    12597        size_t pages = (balloc_start + ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE)) >>
    12698            PAGE_WIDTH;
     
    135107        check_overlap("translate table", transtable_pa, pages);
    136108
    137         printf("\nInflating components ... ");
    138 
    139         for (i = cnt; i > 0; i--) {
    140                 printf("%s ", components[i - 1].name);
    141 
    142                 int err = inflate(components[i - 1].addr, components[i - 1].size,
    143                     inflate_base + dest[i - 1], components[i - 1].inflated);
    144 
    145                 if (err != EOK) {
    146                         printf("\n%s: Inflating error %d, halting.\n",
    147                             components[i - 1].name, err);
    148                         halt();
    149                 }
    150         }
    151 
    152         printf(".\n");
     109        /* Inflate components. */
     110        extract_payload(&bootinfo.taskmap, inflate_base,
     111            inflate_base + uncompressed_size, PA2KA(0), NULL);
    153112
    154113        printf("Setting up boot allocator ...\n");
     
    163122
    164123        printf("Setting up translate table ...\n");
    165         for (i = 0; i < pages; i++) {
     124        for (size_t i = 0; i < pages; i++) {
    166125                uintptr_t off = i << PAGE_WIDTH;
    167126                void *phys;
Note: See TracChangeset for help on using the changeset viewer.