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


Ignore:
Timestamp:
2018-10-10T17:41:44Z (6 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/arm32/src/main.c

    r63c1dd5 r63a045c  
    4949#include <inflate.h>
    5050#include <arch/cp15.h>
    51 #include "../../components.h"
     51#include <payload.h>
    5252
    53 #define TOP2ADDR(top)  (((void *) PA2KA(BOOT_OFFSET)) + (top))
    54 
    55 extern void *bdata_start;
    56 extern void *bdata_end;
    57 
    58 static inline void clean_dcache_poc(void *address, size_t size)
     53static void clean_dcache_poc(void *address, size_t size)
    5954{
    6055        const uintptr_t addr = (uintptr_t) address;
     
    9186        version_print();
    9287
    93         printf("Boot data: %p -> %p\n", &bdata_start, &bdata_end);
     88        printf("Boot loader: %p -> %p\n", loader_start, loader_end);
    9489        printf("\nMemory statistics\n");
    9590        printf(" %p|%p: bootstrap stack\n", &boot_stack, &boot_stack);
     
    9994            (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
    10095
    101         for (size_t i = 0; i < COMPONENTS; i++) {
    102                 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].addr,
    103                     components[i].addr, components[i].name, components[i].inflated,
    104                     components[i].size);
    105         }
     96        // FIXME: Use the correct value.
     97        uint8_t *kernel_dest = (uint8_t *) BOOT_OFFSET;
     98        uint8_t *ram_end = kernel_dest + (1 << 24);
    10699
    107         void *dest[COMPONENTS];
    108         size_t top = 0;
    109         size_t cnt = 0;
    110         bootinfo.cnt = 0;
    111         for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    112                 top = ALIGN_UP(top, PAGE_SIZE);
    113 
    114                 if (i > 0) {
    115                         bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top);
    116                         bootinfo.tasks[bootinfo.cnt].size = components[i].inflated;
    117 
    118                         str_cpy(bootinfo.tasks[bootinfo.cnt].name,
    119                             BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    120 
    121                         bootinfo.cnt++;
    122                 }
    123 
    124                 dest[i] = TOP2ADDR(top);
    125                 top += components[i].inflated;
    126                 cnt++;
    127         }
    128 
    129         printf("\nInflating components ... ");
    130 
    131         for (size_t i = cnt; i > 0; i--) {
    132                 void *tail = components[i - 1].addr + components[i - 1].size;
    133                 if (tail >= dest[i - 1]) {
    134                         printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
    135                             components[i].name, tail, dest[i - 1]);
    136                         halt();
    137                 }
    138 
    139                 printf("%s ", components[i - 1].name);
    140 
    141                 int err = inflate(components[i - 1].addr, components[i - 1].size,
    142                     dest[i - 1], components[i - 1].inflated);
    143                 if (err != EOK) {
    144                         printf("\n%s: Inflating error %d\n", components[i - 1].name, err);
    145                         halt();
    146                 }
    147                 /* Make sure data are in the memory, ICache will need them */
    148                 clean_dcache_poc(dest[i - 1], components[i - 1].inflated);
    149         }
    150 
    151         printf(".\n");
     100        extract_payload(&bootinfo.taskmap, kernel_dest, ram_end,
     101            PA2KA(kernel_dest), clean_dcache_poc);
    152102
    153103        /* Flush PT too. We need this if we disable caches later */
Note: See TracChangeset for help on using the changeset viewer.