Changeset 63a045c in mainline for boot/arch/sparc64/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/sparc64/src/main.c

    r63c1dd5 r63a045c  
    4242#include <str.h>
    4343#include <errno.h>
    44 #include <inflate.h>
    45 #include "../../components.h"
     44#include <payload.h>
    4645
    4746/* The lowest ID (read from the VER register) of some US3 CPU model */
     
    217216            (void *) LOADER_ADDRESS, (void *) loader_address_pa);
    218217
    219         size_t i;
    220         for (i = 0; i < COMPONENTS; i++)
    221                 printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
    222                     ofw_translate(components[i].addr), components[i].name,
    223                     components[i].inflated, components[i].size);
    224 
    225         void *dest[COMPONENTS];
    226         size_t top = KERNEL_ADDRESS;
    227         size_t cnt = 0;
    228         bootinfo.taskmap.cnt = 0;
    229         for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    230                 top = ALIGN_UP(top, PAGE_SIZE);
    231 
    232                 if (i > 0) {
    233                         bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
    234                             (void *) top;
    235                         bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
    236                             components[i].inflated;
    237 
    238                         str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
    239                             BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    240 
    241                         bootinfo.taskmap.cnt++;
    242                 }
    243 
    244                 dest[i] = (void *) top;
    245                 top += components[i].inflated;
    246                 cnt++;
    247         }
    248 
    249         printf("\nInflating components ... ");
    250 
    251         for (i = cnt; i > 0; i--) {
    252                 printf("%s ", components[i - 1].name);
    253 
    254                 /*
    255                  * At this point, we claim and map the physical memory that we
    256                  * are going to use. We should be safe in case of the virtual
    257                  * address space because the OpenFirmware, according to its
    258                  * SPARC binding, should restrict its use of virtual memory to
    259                  * addresses from [0xffd00000; 0xffefffff] and [0xfe000000;
    260                  * 0xfeffffff].
    261                  */
    262                 ofw_claim_phys(bootinfo.physmem_start + dest[i - 1],
    263                     ALIGN_UP(components[i - 1].inflated, PAGE_SIZE));
    264 
    265                 ofw_map(bootinfo.physmem_start + dest[i - 1], dest[i - 1],
    266                     ALIGN_UP(components[i - 1].inflated, PAGE_SIZE), -1);
    267 
    268                 int err = inflate(components[i - 1].addr, components[i - 1].size,
    269                     dest[i - 1], components[i - 1].inflated);
    270 
    271                 if (err != EOK) {
    272                         printf("\n%s: Inflating error %d, halting.\n",
    273                             components[i - 1].name, err);
    274                         halt();
    275                 }
    276         }
    277 
    278         printf(".\n");
     218        /*
     219         * At this point, we claim and map the physical memory that we
     220         * are going to use. We should be safe in case of the virtual
     221         * address space because the OpenFirmware, according to its
     222         * SPARC binding, should restrict its use of virtual memory to
     223         * addresses from [0xffd00000; 0xffefffff] and [0xfe000000;
     224         * 0xfeffffff].
     225         */
     226
     227        size_t sz = ALIGN_UP(payload_uncompressed_size(), PAGE_SIZE);
     228        ofw_claim_phys((void *) (bootinfo.physmem_start + KERNEL_ADDRESS), sz);
     229        ofw_map((void *) (bootinfo.physmem_start + KERNEL_ADDRESS),
     230            (void *) KERNEL_ADDRESS, sz, -1);
     231
     232        /* Extract components. */
     233
     234        // TODO: Cache-coherence callback?
     235        extract_payload(&bootinfo.taskmap, (void *) KERNEL_ADDRESS,
     236            (void *) KERNEL_ADDRESS + sz, KERNEL_ADDRESS, NULL);
    279237
    280238        /*
     
    283241         */
    284242        printf("Setting up boot allocator ...\n");
    285         void *balloc_base = (void *) ALIGN_UP(top, PAGE_SIZE);
     243        void *balloc_base = (void *) KERNEL_ADDRESS + sz;
    286244        ofw_claim_phys(bootinfo.physmem_start + balloc_base, BALLOC_MAX_SIZE);
    287245        ofw_map(bootinfo.physmem_start + balloc_base, balloc_base,
Note: See TracChangeset for help on using the changeset viewer.