Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset dcc2c5d in mainline


Ignore:
Timestamp:
2018-10-12T17:44:35Z (3 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master
Children:
68a0d60
Parents:
d4eba6d
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-12 17:38:51)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-12 17:44:35)
Message:

Make bootimage compression optional

Fixes issue #411

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    rd4eba6d rdcc2c5d  
    435435! RCU (choice)
    436436
     437% Compress init data
     438! CONFIG_COMPRESSED_INIT (y/n)
    437439
    438440## User space features options
  • boot/Makefile.build

    rd4eba6d rdcc2c5d  
    6969DEPENDS := $(addsuffix .d,$(basename $(SOURCES)))
    7070
     71ifeq ($(CONFIG_COMPRESSED_INIT),y)
     72        COMPONENTS := $(addsuffix .gz, $(COMPONENTS))
     73endif
     74
    7175all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BOOT_OUTPUT)
    7276
     
    101105        gzip -n -k -f $<
    102106
    103 $(COMPS).tar: $(addsuffix .gz, $(COMPONENTS))
     107$(COMPS).tar: $(COMPONENTS)
    104108        tar --mtime='2032-01-01 00:00:00' --group=0 --owner=0 --no-acls --no-selinux --no-xattrs --format=ustar --transform 's/.*\///g' -cvf $@ $^
    105109
  • boot/arch/ppc32/src/main.c

    rd4eba6d rdcc2c5d  
    7373            (void *) LOADER_ADDRESS, loader_address_pa);
    7474
    75         size_t uncompressed_size = payload_uncompressed_size();
    76         printf("Payload uncompressed size: %d bytes\n", uncompressed_size);
     75        size_t unpacked_size = payload_unpacked_size();
     76        printf("Payload uncompressed size: %d bytes\n", unpacked_size);
    7777
    78         if (uncompressed_size >= (size_t) loader_address_pa) {
     78        if (unpacked_size >= (size_t) loader_address_pa) {
    7979                printf("Inflated components overlap loader area.\n");
    8080                printf("The boot image is too large. Halting.\n");
     
    9191        void *inflate_base_pa;
    9292        ofw_alloc("inflate area", &inflate_base, &inflate_base_pa,
    93             uncompressed_size, loader_address_pa);
     93            unpacked_size, loader_address_pa);
    9494        printf(" %p|%p: inflate area\n", inflate_base, inflate_base_pa);
    9595
    96         uintptr_t balloc_start = ALIGN_UP(uncompressed_size, PAGE_SIZE);
     96        uintptr_t balloc_start = ALIGN_UP(unpacked_size, PAGE_SIZE);
    9797        size_t pages = (balloc_start + ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE)) >>
    9898            PAGE_WIDTH;
     
    109109        /* Inflate components. */
    110110        extract_payload(&bootinfo.taskmap, inflate_base,
    111             inflate_base + uncompressed_size, PA2KA(0), NULL);
     111            inflate_base + unpacked_size, PA2KA(0), NULL);
    112112
    113113        printf("Setting up boot allocator ...\n");
  • boot/arch/sparc64/src/main.c

    rd4eba6d rdcc2c5d  
    225225         */
    226226
    227         size_t sz = ALIGN_UP(payload_uncompressed_size(), PAGE_SIZE);
     227        size_t sz = ALIGN_UP(payload_unpacked_size(), PAGE_SIZE);
    228228        ofw_claim_phys((void *) (bootinfo.physmem_start + KERNEL_ADDRESS), sz);
    229229        ofw_map((void *) (bootinfo.physmem_start + KERNEL_ADDRESS),
  • boot/generic/include/payload.h

    rd4eba6d rdcc2c5d  
    4040extern uint8_t loader_end[];
    4141
    42 size_t payload_uncompressed_size(void);
     42size_t payload_unpacked_size(void);
    4343void extract_payload(taskmap_t *, uint8_t *, uint8_t *, uintptr_t,
    4444    void (*)(void *, size_t));
  • boot/generic/src/payload.c

    rd4eba6d rdcc2c5d  
    4141#include <halt.h>
    4242
    43 static void basename(char *s)
    44 {
    45         char *last = s;
     43static const char *ext(const char *s)
     44{
     45        const char *last = s;
    4646
    4747        while (*s) {
     
    5353
    5454        if (*last == '.')
    55                 *last = '\0';
     55                return last;
     56
     57        return NULL;
     58}
     59
     60static void basename(char *s)
     61{
     62        char *e = (char *) ext(s);
     63        if (str_cmp(e, ".gz") == 0)
     64                *e = '\0';
     65}
     66
     67static bool isgzip(const char *s)
     68{
     69        return str_cmp(ext(s), ".gz") == 0;
    5670}
    5771
     
    6882        const char *name;
    6983        const uint8_t *data;
    70         size_t compressed_size;
    71         size_t uncompressed_size;
    72 
    73         if (!tar_info(*cstart, cend, &name, &compressed_size))
     84        size_t packed_size;
     85        size_t unpacked_size;
     86
     87        if (!tar_info(*cstart, cend, &name, &packed_size))
    7488                return false;
    7589
    7690        data = *cstart + TAR_BLOCK_SIZE;
    77         *cstart += TAR_BLOCK_SIZE + ALIGN_UP(compressed_size, TAR_BLOCK_SIZE);
    78 
    79         uncompressed_size = gzip_size(data, compressed_size);
     91        *cstart += TAR_BLOCK_SIZE + ALIGN_UP(packed_size, TAR_BLOCK_SIZE);
     92
     93        bool gz = isgzip(name);
     94
     95        unpacked_size = gz ? gzip_size(data, packed_size) : packed_size;
    8096
    8197        /* Components must be page-aligned. */
     
    8399        actual_ustart += new_ustart - ustart;
    84100        ustart = new_ustart;
    85         uint8_t *comp_end = ustart + uncompressed_size;
     101        uint8_t *comp_end = ustart + unpacked_size;
    86102
    87103        /* Check limits and overlap. */
     
    92108                actual_ustart += new_ustart - ustart;
    93109                ustart = new_ustart;
    94                 comp_end = ustart + uncompressed_size;
     110                comp_end = ustart + unpacked_size;
    95111        }
    96112
     
    102118
    103119        printf(" %p|%p: %s image (%zu/%zu bytes)\n", (void *) actual_ustart,
    104             ustart, name, uncompressed_size, compressed_size);
     120            ustart, name, unpacked_size, packed_size);
    105121
    106122        if (task) {
    107123                task->addr = (void *) actual_ustart;
    108                 task->size = uncompressed_size;
     124                task->size = unpacked_size;
    109125                str_cpy(task->name, BOOTINFO_TASK_NAME_BUFLEN, name);
    110126                /* Remove .gz extension */
    111                 basename(task->name);
    112         }
    113 
    114         int rc = gzip_expand(data, compressed_size, ustart, uncompressed_size);
    115         if (rc != EOK) {
    116                 printf("\n%s: Inflating error %d\n", name, rc);
    117                 halt();
     127                if (gz)
     128                        basename(task->name);
     129        }
     130
     131        if (gz) {
     132                int rc = gzip_expand(data, packed_size, ustart, unpacked_size);
     133                if (rc != EOK) {
     134                        printf("\n%s: Inflating error %d\n", name, rc);
     135                        halt();
     136                }
     137        } else {
     138                memcpy(ustart, data, unpacked_size);
    118139        }
    119140
    120141        if (clear_cache)
    121                 clear_cache(ustart, uncompressed_size);
     142                clear_cache(ustart, unpacked_size);
     143
    122144        return true;
    123145}
    124146
    125 /* @return Bytes needed for uncompressed payload. */
    126 size_t payload_uncompressed_size(void)
     147/* @return Bytes needed for unpacked payload. */
     148size_t payload_unpacked_size(void)
    127149{
    128150        size_t sz = 0;
    129151        uint8_t *start = payload_start;
    130152        const char *name;
    131         size_t compressed_size;
    132 
    133         while (tar_info(start, payload_end, &name, &compressed_size)) {
     153        size_t packed_size;
     154
     155        while (tar_info(start, payload_end, &name, &packed_size)) {
    134156                sz = ALIGN_UP(sz, PAGE_SIZE);
    135                 sz += gzip_size(start + TAR_BLOCK_SIZE, compressed_size);
    136 
    137                 start += TAR_BLOCK_SIZE +
    138                     ALIGN_UP(compressed_size, TAR_BLOCK_SIZE);
     157                if (isgzip(name))
     158                        sz += gzip_size(start + TAR_BLOCK_SIZE, packed_size);
     159                else
     160                        sz += packed_size;
     161
     162                start += TAR_BLOCK_SIZE + ALIGN_UP(packed_size, TAR_BLOCK_SIZE);
    139163        }
    140164
     
    186210                /*
    187211                 * First, move the payload to the very end of available memory,
    188                  * to make space for the decompressed data.
     212                 * to make space for the unpacked data.
    189213                 */
    190214                real_payload_start = (uint8_t *) ALIGN_DOWN((uintptr_t)(mem_end - payload_size), PAGE_SIZE);
Note: See TracChangeset for help on using the changeset viewer.