summaryrefslogtreecommitdiff
path: root/common/tools/mksimage/mksimage.c
blob: 8d65b57b0194c2ae05209247fd2cbca4e41f1c09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * scripts/spidhdr/spidhdr.c
 *
 * (C) Copyright 2009 SPiDCOM Technologies
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 * Author(s):
 * 30 Apr 2009  Drasko DRASKOVIC    <drasko.draskovic@spidcom.com>
 */

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "spid_img_desc.h"

spidcom_image_desc_t image = {
  .magic            = SPIDCOM_IMG_DESC_MAGIC,
  .index            = 0xffffffff,		/* mandatory to be changed into the flash */
  .is_valid         = 1,
  .is_1st_boot      = 1,
  .is_not_success   = 1,
  .is_not_update    = 1,
  .type             = 0,
  .version          = "v0.0",
  .description      = "SPiDCOM image",
  .arch             = SPIDCOM_IMG_DESC_SPC300,
  .plc_ram          = SPIDCOM_IMG_DESC_PLC_RAM
};

static void print_usage(const char *cmd)
{
  fprintf(stderr, "%s : \n", cmd);
}

int main(int argc, char **argv)
{
    int c, i = 0;
    int j = 0;
    char tmpstr[3];

    struct option opt[] =
    {
        { "size", required_argument, NULL, 's' },
        { "ver",  required_argument, NULL, 'v' },
        { "desc", required_argument, NULL, 'd' },
        { "md5",  required_argument, NULL, 'm' },
        { "plc-ram",  required_argument, NULL, 'r' },
        { "help", no_argument,       NULL, 'h' }
    };

    while((c = getopt_long(argc, argv, "s:v:d:m:r:h", opt, &i)) != EOF)
    {
        switch(c)
        {
        case 's' :
            image.size = atoi(optarg);
            break;
        case 'v' :
            strncpy(image.version, optarg, sizeof(image.version));
            break;
        case 'd' :
            strncpy(image.description, optarg, sizeof(image.description));
            break;
        case 'm' :
            for (j=0; j<16; j++)
            {
                strncpy(tmpstr, optarg + j*2, 2);
                tmpstr[2] = '\0';
                image.md5_sum[j] = (unsigned char)strtoul(tmpstr, NULL, 16);
            }
            break;
        case 'r' :
            image.plc_ram = atoi(optarg) * 1024 * 1024;
            break;
        case 'h' :
        case '?' :
            print_usage(argv[0]);
            return -1;
        }
    }

    write(fileno(stdout), &image, sizeof(spidcom_image_desc_t));
    return 0;
}