Changeset dcc2c5d in mainline for boot/generic/src/payload.c


Ignore:
Timestamp:
2018-10-12T17:44:35Z (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:
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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.