LCOV - code coverage report
Current view: top level - core/test - run-flash-firmware-versions.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 30 37 81.1 %
Date: 2024-01-02 21:04:04 Functions: 6 8 75.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Copyright 2018-2019 IBM Corp.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <stdlib.h>
       7                 :            : #include <stdio.h>
       8                 :            : #include <stdarg.h>
       9                 :            : #include <string.h>
      10                 :            : #include <malloc.h>
      11                 :            : #include <stdint.h>
      12                 :            : 
      13                 :            : 
      14                 :            : #include <sys/types.h>
      15                 :            : #include <sys/stat.h>
      16                 :            : #include <sys/mman.h>
      17                 :            : #include <fcntl.h>
      18                 :            : #include <assert.h>
      19                 :            : #include <stdlib.h>
      20                 :            : #include <unistd.h>
      21                 :            : #include <stdint.h>
      22                 :            : 
      23                 :            : 
      24                 :            : #include <interrupts.h>
      25                 :            : #include <bitutils.h>
      26                 :            : 
      27                 :            : #include <compiler.h>
      28                 :            : 
      29                 :            : /*
      30                 :            :  * Skiboot malloc stubs
      31                 :            :  *
      32                 :            :  * The actual prototypes for these are defined in mem_region-malloc.h,
      33                 :            :  * but that file also #defines malloc, and friends so we don't pull that in
      34                 :            :  * directly.
      35                 :            :  */
      36                 :            : 
      37                 :            : #define DEFAULT_ALIGN __alignof__(long)
      38                 :            : 
      39                 :            : void *__memalign(size_t blocksize, size_t bytes, const char *location __unused);
      40                 :        126 : void *__memalign(size_t blocksize, size_t bytes, const char *location __unused)
      41                 :            : {
      42                 :        126 :         return memalign(blocksize, bytes);
      43                 :            : }
      44                 :            : 
      45                 :            : void *__malloc(size_t bytes, const char *location);
      46                 :        126 : void *__malloc(size_t bytes, const char *location)
      47                 :            : {
      48                 :        126 :         return __memalign(DEFAULT_ALIGN, bytes, location);
      49                 :            : }
      50                 :            : 
      51                 :            : void __free(void *p, const char *location __unused);
      52                 :         13 : void __free(void *p, const char *location __unused)
      53                 :            : {
      54                 :         13 :         free(p);
      55                 :         13 : }
      56                 :            : 
      57                 :            : void *__realloc(void *ptr, size_t size, const char *location __unused);
      58                 :          0 : void *__realloc(void *ptr, size_t size, const char *location __unused)
      59                 :            : {
      60                 :          0 :         return realloc(ptr, size);
      61                 :            : }
      62                 :            : 
      63                 :            : void *__zalloc(size_t bytes, const char *location);
      64                 :          0 : void *__zalloc(size_t bytes, const char *location)
      65                 :            : {
      66                 :          0 :         void *p = __malloc(bytes, location);
      67                 :            : 
      68                 :          0 :         if (p)
      69                 :          0 :                 memset(p, 0, bytes);
      70                 :          0 :         return p;
      71                 :            : }
      72                 :            : 
      73                 :            : #include <mem_region-malloc.h>
      74                 :            : 
      75                 :            : #include <opal-api.h>
      76                 :            : 
      77                 :            : #include "../../libfdt/fdt.c"
      78                 :            : #include "../../libfdt/fdt_ro.c"
      79                 :            : #include "../../libfdt/fdt_sw.c"
      80                 :            : #include "../../libfdt/fdt_strerror.c"
      81                 :            : 
      82                 :            : #include "../../core/device.c"
      83                 :            : 
      84                 :            : #include "../../libstb/container-utils.h"
      85                 :            : #include "../../libstb/container.h"
      86                 :            : #include "../../libstb/container.c"
      87                 :            : 
      88                 :            : #include "../flash-firmware-versions.c"
      89                 :            : #include <assert.h>
      90                 :            : 
      91                 :            : char __rodata_start[1], __rodata_end[1];
      92                 :            : 
      93                 :            : const char version[]="Hello world!";
      94                 :            : 
      95                 :            : enum proc_gen proc_gen = proc_gen_p8;
      96                 :            : 
      97                 :            : static char *loaded_version_buf;
      98                 :            : static size_t loaded_version_buf_size;
      99                 :            : 
     100                 :            : #define min(x,y) ((x) < (y) ? x : y)
     101                 :            : 
     102                 :         13 : int start_preload_resource(enum resource_id id, uint32_t subid,
     103                 :            :                            void *buf, size_t *len)
     104                 :            : {
     105                 :            :         (void)id;
     106                 :            :         (void)subid;
     107                 :            :         (void)buf;
     108                 :         13 :         if (loaded_version_buf) {
     109                 :         12 :                 *len = min(*len, loaded_version_buf_size);
     110                 :         12 :                 memcpy(buf, loaded_version_buf, *len);
     111                 :            :         } else {
     112                 :          1 :                 *len = 0;
     113                 :            :         }
     114                 :            : 
     115                 :         13 :         return 0;
     116                 :            : }
     117                 :            : 
     118                 :         13 : int wait_for_resource_loaded(enum resource_id id, uint32_t idx)
     119                 :            : {
     120                 :            :         (void)id;
     121                 :            :         (void)idx;
     122                 :         13 :         return 0;
     123                 :            : }
     124                 :            : 
     125                 :         13 : int main(int argc, char *argv[])
     126                 :            : {
     127                 :            :         int fd;
     128                 :            :         struct stat ver_st;
     129                 :            :         int r;
     130                 :            : 
     131                 :         13 :         dt_root = dt_new_root("");
     132                 :            : 
     133                 :         13 :         if (argc > 1) {
     134                 :         12 :                 fd = open(argv[1], O_RDONLY);
     135                 :            : 
     136                 :         12 :                 assert(fd > 0);
     137                 :         12 :                 r = fstat(fd, &ver_st);
     138                 :         12 :                 assert(r == 0);
     139                 :            : 
     140                 :         12 :                 loaded_version_buf = mmap(NULL, ver_st.st_size,
     141                 :            :                                           PROT_READ, MAP_PRIVATE, fd, 0);
     142                 :         12 :                 assert(loaded_version_buf != (char*)-1);
     143                 :         12 :                 loaded_version_buf_size = ver_st.st_size;
     144                 :            :         }
     145                 :            : 
     146                 :         13 :         flash_fw_version_preload();
     147                 :            : 
     148                 :         13 :         proc_gen = proc_gen_p9;
     149                 :         13 :         flash_fw_version_preload();
     150                 :         13 :         flash_dt_add_fw_version();
     151                 :            : 
     152                 :         13 :         return 0;
     153                 :            : }
     154                 :            : 

Generated by: LCOV version 1.14