#ifndef FW_INCLUDED
#define FW_INCLUDED
+#include <stdint.h>
#include <sys/types.h>
#define MAGIC_HEADER "OPEN"
#define PART_NAME_LENGTH 16
typedef struct header {
- char magic[MAGIC_LENGTH];
- char version[256];
+ uint8_t magic[MAGIC_LENGTH];
+ uint8_t version[256];
u_int32_t crc;
u_int32_t pad;
} __attribute__ ((packed)) header_t;
typedef struct part {
- char magic[MAGIC_LENGTH];
- char name[PART_NAME_LENGTH];
- char pad[12];
+ uint8_t magic[MAGIC_LENGTH];
+ uint8_t name[PART_NAME_LENGTH];
+ uint8_t pad[12];
u_int32_t memaddr;
u_int32_t index;
u_int32_t baseaddr;
} __attribute__ ((packed)) part_crc_t;
typedef struct signature {
- char magic[MAGIC_LENGTH];
+ uint8_t magic[MAGIC_LENGTH];
u_int32_t crc;
u_int32_t pad;
} __attribute__ ((packed)) signature_t;
typedef struct signature_rsa {
- char magic[MAGIC_LENGTH];
+ uint8_t magic[MAGIC_LENGTH];
// u_int32_t crc;
unsigned char rsa_signature[256];
u_int32_t pad;
#include <limits.h>
#include <stdbool.h>
#include "fw.h"
+#include "utils.h"
typedef struct fw_layout_data {
u_int32_t kern_start;
header_t* header = mem;
memset(header, 0, sizeof(header_t));
- memcpy(header->magic, magic, MAGIC_LENGTH);
- strncpy(header->version, version, sizeof(header->version));
- header->crc = htonl(crc32(0L, (unsigned char *)header,
- sizeof(header_t) - 2 * sizeof(u_int32_t)));
+ FW_MEMCPY_STR(header->magic, magic);
+ FW_MEMCPY_STR(header->version, version);
+ header->crc = htonl(crc32(0L, (uint8_t*) header,
+ sizeof(header_t) - 2 * sizeof(u_int32_t)));
header->pad = 0L;
}
-
static void write_signature(void* mem, u_int32_t sig_offset)
{
/* write signature */
signature_t* sign = (signature_t*)(mem + sig_offset);
memset(sign, 0, sizeof(signature_t));
- memcpy(sign->magic, MAGIC_END, MAGIC_LENGTH);
+ FW_MEMCPY_STR(sign->magic, MAGIC_END);
sign->crc = htonl(crc32(0L,(unsigned char *)mem, sig_offset));
sign->pad = 0L;
}
signature_rsa_t* sign = (signature_rsa_t*)(mem + sig_offset);
memset(sign, 0, sizeof(signature_rsa_t));
- memcpy(sign->magic, MAGIC_ENDS, MAGIC_LENGTH);
+ FW_MEMCPY_STR(sign->magic, MAGIC_ENDS);
// sign->crc = htonl(crc32(0L,(unsigned char *)mem, sig_offset));
sign->pad = 0L;
}
munmap(addr, d->stats.st_size);
memset(p->name, 0, PART_NAME_LENGTH);
- memcpy(p->magic, MAGIC_PART, MAGIC_LENGTH);
- memcpy(p->name, d->partition_name, PART_NAME_LENGTH);
+ FW_MEMCPY_STR(p->magic, MAGIC_PART);
+ FW_MEMCPY_STR(p->name, d->partition_name);
p->index = htonl(d->partition_index);
p->data_size = htonl(d->stats.st_size);