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

    r63c1dd5 r63a045c  
    4343#include <str.h>
    4444#include <errno.h>
    45 #include <inflate.h>
    46 #include "../../components.h"
     45#include <payload.h>
    4746
    4847#define DEFAULT_MEMORY_BASE             0x4000000ULL
     
    150149        version_print();
    151150
     151        printf("Boot loader: %p -> %p\n", loader_start, loader_end);
    152152        printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
    153153        printf(" %p|%p: kernel entry point\n",
     
    156156            (void *) LOADER_ADDRESS, (void *) LOADER_ADDRESS);
    157157
    158         size_t i;
    159         for (i = 0; i < COMPONENTS; i++)
    160                 printf(" %p|%p: %s image (%zu/%zu bytes)\n", components[i].addr,
    161                     components[i].addr, components[i].name,
    162                     components[i].inflated, components[i].size);
    163 
    164         void *dest[COMPONENTS];
    165         size_t top = KERNEL_ADDRESS;
    166         size_t cnt = 0;
    167         bootinfo.taskmap.cnt = 0;
    168         for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    169                 top = ALIGN_UP(top, PAGE_SIZE);
    170 
    171                 if (i > 0) {
    172                         bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
    173                             (void *) top;
    174                         bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
    175                             components[i].inflated;
    176 
    177                         str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
    178                             BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    179 
    180                         bootinfo.taskmap.cnt++;
    181                 }
    182 
    183                 dest[i] = (void *) top;
    184                 top += components[i].inflated;
    185                 cnt++;
    186         }
    187 
    188         printf("\nInflating components ... ");
    189 
    190         /*
    191          * We will use the next available address for a copy of each component to
    192          * make sure that inflate() works with disjunctive memory regions.
    193          */
    194         top = ALIGN_UP(top, PAGE_SIZE);
    195 
    196         for (i = cnt; i > 0; i--) {
    197                 printf("%s ", components[i - 1].name);
    198 
    199                 /*
    200                  * Copy the component to a location which is guaranteed not to
    201                  * overlap with the destination for inflate().
    202                  */
    203                 memmove((void *) top, components[i - 1].addr, components[i - 1].size);
    204 
    205                 int err = inflate((void *) top, components[i - 1].size,
    206                     dest[i - 1], components[i - 1].inflated);
    207 
    208                 if (err != EOK) {
    209                         printf("\n%s: Inflating error %d, halting.\n",
    210                             components[i - 1].name, err);
    211                         halt();
    212                 }
    213         }
    214 
    215         printf(".\n");
    216 
    217158        read_efi_memmap();
    218159        read_sal_configuration();
    219160        read_pal_configuration();
    220161
     162        uint8_t *kernel_start = (uint8_t *) KERNEL_ADDRESS;
     163        uint8_t *ram_end = NULL;
     164
     165        /* Find the end of the memory area occupied by the kernel. */
     166        for (unsigned i = 0; i < bootinfo.memmap_items; i++) {
     167                memmap_item_t m = bootinfo.memmap[i];
     168                if (m.type == MEMMAP_FREE_MEM &&
     169                    m.base <= (uintptr_t) kernel_start &&
     170                    m.base + m.size > (uintptr_t) kernel_start) {
     171                        ram_end = (uint8_t *) (m.base + m.size);
     172                }
     173        }
     174
     175        if (ram_end == NULL) {
     176                printf("Memory map doesn't contain usable area at kernel's address.\n");
     177                halt();
     178        }
     179
     180        // FIXME: Correct kernel's logical address.
     181        extract_payload(&bootinfo.taskmap, kernel_start, ram_end,
     182            (uintptr_t) kernel_start, NULL);
     183
    221184        printf("Booting the kernel ...\n");
    222185        jump_to_kernel(&bootinfo);
Note: See TracChangeset for help on using the changeset viewer.