39,8 → 39,10 |
|
#include <lib/rd.h> |
#include <arch/byteorder.h> |
#include <mm/frame.h> |
#include <sysinfo/sysinfo.h> |
|
int init_rd(rd_header * header) |
int init_rd(rd_header * header, size_t size) |
{ |
/* Identify RAM disk */ |
if ((header->magic[0] != RD_MAG0) || (header->magic[1] != RD_MAG1) || (header->magic[2] != RD_MAG2) || (header->magic[3] != RD_MAG3)) |
50,18 → 52,33 |
if (header->version != RD_VERSION) |
return RE_UNSUPPORTED; |
|
uint64_t hsize; |
uint32_t hsize; |
uint64_t dsize; |
switch (header->data_type) { |
case RD_DATA_LSB: |
hsize = uint64_t_le2host(header->header_size); |
hsize = uint32_t_le2host(header->header_size); |
dsize = uint64_t_le2host(header->data_size); |
break; |
// case RD_DATA_MSB: |
// hsize = uint64_t_be2host(header->header_size); |
// break; |
case RD_DATA_MSB: |
hsize = uint32_t_be2host(header->header_size); |
dsize = uint64_t_le2host(header->data_size); |
break; |
default: |
return RE_UNSUPPORTED; |
} |
|
|
if ((hsize % FRAME_SIZE) || (dsize % FRAME_SIZE)) |
return RE_UNSUPPORTED; |
|
if (hsize > size) |
return RE_INVALID; |
|
if ((uint64_t) hsize + dsize > size) |
dsize = size - hsize; |
|
sysinfo_set_item_val("rd", NULL, true); |
sysinfo_set_item_val("rd.size", NULL, dsize); |
sysinfo_set_item_val("rd.address.physical", NULL, (unative_t) KA2PA((void *) header + hsize)); |
|
return RE_OK; |
} |