Subversion Repositories freemyipod

Rev

Rev 651 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
469 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "emcorelib.h"
25
#include "export/libboot.h"
26
 
27
 
655 theseven 28
static struct libboot_api apitable =
469 theseven 29
{
30
    .verify_rockbox_checksum = verify_rockbox_checksum
31
};
32
 
33
 
651 theseven 34
EMCORE_LIB_HEADER(LIBBOOT_IDENTIFIER, LIBBOOT_API_VERSION, LIBBOOT_MIN_API_VERSION,
35
                  NULL, NULL, apitable)
469 theseven 36
 
37
 
38
int verify_rockbox_checksum(void* image, size_t size)
39
{
40
    int i;
41
    uint8_t* data = (uint8_t*)image;
42
    uint32_t checksum = data[3] | (data[2] << 8) | (data[1] << 16) | (data[0] << 24);
43
    uint32_t platform;
44
    switch (get_platform_id())
45
    {
46
        case 0x47324e49:  // IN2G
47
            checksum -= 62;
48
            platform = 0x67326e6e;  // nn2g
49
            break;
50
        case 0x4c435049:  // IPCL
51
            checksum -= 71;
52
            platform = 0x67367069;  // ip6g
53
            break;
54
        default:
55
            return -3;
56
    }
57
    if (*((uint32_t*)&data[4]) != platform) return -2;
58
    for (i = 0; i < size - 8; i++)
59
    {
60
        data[i] = data[i + 8];
61
        checksum -= data[i + 8];
62
    }
63
    if (checksum) return -1;
64
    return 0;
65
}