Changeset 63a045c in mainline for boot/arch/mips32/src/main.c


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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/mips32/src/main.c

    r63c1dd5 r63a045c  
    3939#include <str.h>
    4040#include <errno.h>
    41 #include <inflate.h>
    42 #include "../../components.h"
    43 
    44 #define TOP2ADDR(top)  (((void *) PA2KA(BOOT_OFFSET)) + (top))
     41#include <payload.h>
    4542
    4643static bootinfo_t *bootinfo = (bootinfo_t *) PA2KA(BOOTINFO_OFFSET);
     
    6360            (void *) PA2KA(LOADER_OFFSET), (void *) LOADER_OFFSET);
    6461
    65         size_t i;
    66         for (i = 0; i < COMPONENTS; i++)
    67                 printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
    68                     (uintptr_t) components[i].addr >= PA2KSEG(0) ?
    69                     (void *) KSEG2PA(components[i].addr) :
    70                     (void *) KA2PA(components[i].addr),
    71                     components[i].name, components[i].inflated,
    72                     components[i].size);
     62        uint8_t *kernel_start = (uint8_t *) PA2KA(BOOT_OFFSET);
     63        // FIXME: Use the correct value.
     64        uint8_t *ram_end = kernel_start + (1 << 24);
    7365
    74         void *dest[COMPONENTS];
    75         size_t top = 0;
    76         size_t cnt = 0;
    77         bootinfo->cnt = 0;
    78         for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    79                 top = ALIGN_UP(top, PAGE_SIZE);
     66        // TODO: Make sure that the I-cache, D-cache and memory are coherent.
     67        //       (i.e. provide the clear_cache callback)
    8068
    81                 if (i > 0) {
    82                         bootinfo->tasks[bootinfo->cnt].addr = TOP2ADDR(top);
    83                         bootinfo->tasks[bootinfo->cnt].size = components[i].inflated;
    84 
    85                         str_cpy(bootinfo->tasks[bootinfo->cnt].name,
    86                             BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    87 
    88                         bootinfo->cnt++;
    89                 }
    90 
    91                 dest[i] = TOP2ADDR(top);
    92                 top += components[i].inflated;
    93                 cnt++;
    94         }
    95 
    96         printf("\nInflating components ... ");
    97 
    98         for (i = cnt; i > 0; i--) {
    99 #ifdef MACHINE_msim
    100                 void *tail = dest[i - 1] + components[i].inflated;
    101                 if (tail >= ((void *) PA2KA(LOADER_OFFSET))) {
    102                         printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
    103                             components[i].name, tail, (void *) PA2KA(LOADER_OFFSET));
    104                         halt();
    105                 }
    106 #endif
    107 
    108                 printf("%s ", components[i - 1].name);
    109 
    110                 int err = inflate(components[i - 1].addr, components[i - 1].size,
    111                     dest[i - 1], components[i - 1].inflated);
    112 
    113                 if (err != EOK) {
    114                         printf("\n%s: Inflating error %d, halting.\n",
    115                             components[i - 1].name, err);
    116                         halt();
    117                 }
    118         }
    119 
    120         printf(".\n");
     69        extract_payload(&bootinfo->taskmap, kernel_start, ram_end,
     70            (uintptr_t) kernel_start, NULL);
    12171
    12272        printf("Copying CPU map ... \n");
    12373
    12474        bootinfo->cpumap = 0;
    125         for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
     75        for (int i = 0; i < CPUMAP_MAX_RECORDS; i++) {
    12676                if (cpumap[i] != 0)
    12777                        bootinfo->cpumap |= (1 << i);
Note: See TracChangeset for help on using the changeset viewer.