mef.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifdef WITH_LOADER_ARCH
00043 #include "contiki.h"
00044 #include "loader/mef.h"
00045
00046 struct Area areas[MEF_AREA_MAX];
00047
00048 void
00049 mef_load(unsigned char* offset)
00050 {
00051 unsigned char* start = offset;
00052 unsigned char areasize = load_byte();
00053 u16_t relocsize;
00054 unsigned int i, j;
00055 u16_t checksum = 0;
00056 unsigned char* buf;
00057 struct Relocation reloc;
00058
00059 for (i = 0; i < areasize; i++) {
00060 buf = (unsigned char *) &areas[i];
00061 for (j = 0; j < sizeof(struct Area); j++) {
00062 *buf++ = load_byte();
00063 }
00064 }
00065
00066 for (i = 0; i < areasize; i++) {
00067 for (j = 0; j < areas[i].size; j++) {
00068 *offset = load_byte();
00069 checksum += *offset;
00070 offset++;
00071 }
00072 if (areas[i].checksum != checksum) {
00073
00074 }
00075 }
00076
00077
00078 relocsize = load_byte();
00079 relocsize = (load_byte() << 8) + relocsize;
00080 for (i = 0; i < relocsize; i++) {
00081 buf = (unsigned char *) &reloc;
00082 for (j = 0; j < sizeof(struct Relocation); j++) {
00083 *buf++ = load_byte();
00084 }
00085 mef_reloc(start, &reloc);
00086 }
00087 }
00088
00089 void
00090 mef_reloc(unsigned char* offset, struct Relocation *reloc)
00091 {
00092 if (reloc->mode & MEF_RELOC_ABSOLUTE) {
00093 return;
00094 }
00095 offset += reloc->address;
00096 if (reloc->mode & MEF_RELOC_MSB_BYTE) {
00097 *offset = (unsigned char) ((reloc->data + (u16_t) offset) >> 8);
00098 } else if (reloc->mode & MEF_RELOC_LSB_BYTE) {
00099 *offset = (unsigned char) ((reloc->data + (u16_t) offset) & 0xff);
00100 } else {
00101 *offset++ = (unsigned char) ((reloc->data + (u16_t) offset) & 0xff);
00102 *offset = (unsigned char) ((reloc->data + (u16_t) offset) >> 8);
00103 }
00104 }
00105
00106
00107 #endif