blob: 79b5acead7aee5a8a71e7b0377abd1636756dbc7 [file] [log] [blame]
Liam Girdwood05ef4342018-02-13 20:29:40 +00001/*
2 * Copyright (c) 2017, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
14 * Keyon Jie <yang.jie@linux.intel.com>
15 */
16
17#include <stdio.h>
18#include <sys/time.h>
19#include "rimage.h"
20#include "css.h"
21#include "manifest.h"
22
23void ri_css_hdr_create(struct image *image)
24{
25 struct css_header *css = image->fw_image + MAN_CSS_HDR_OFFSET;
26 struct tm *date;
27 struct timeval tv;
28 int val;
29
30 fprintf(stdout, " cse: completing CSS manifest\n");
31
32 /* get local time and date */
33 gettimeofday(&tv, NULL);
34 date = localtime(&tv.tv_sec);
Pan Xiuli1e231b92018-05-11 15:55:40 +080035
36 if (!date) {
37 fprintf(stderr, "error: cant get localtime %d\n", -errno);
38 return;
39 }
40
Liam Girdwood05ef4342018-02-13 20:29:40 +000041 date->tm_year += 1900;
42 fprintf(stdout, " css: set build date to %d:%2.2d:%2.2d\n",
43 date->tm_year, date->tm_mon, date->tm_mday);
44
45 /* year yYyy */
46 val = date->tm_year / 1000;
47 css->date |= val << 28;
48 date->tm_year -= val * 1000;
49 /* year yyYy */
50 val = date->tm_year / 100;
51 css->date |= val << 24;
52 date->tm_year -= val * 100;
53 /* year yyyY */
54 val = date->tm_year / 10;
55 css->date |= val << 20;
56 date->tm_year -= val * 10;
57 /* year Yyyy */
58 val = date->tm_year;
59 css->date |= val << 16;
60
61 /* month Mm - for some reason month starts at 0 */
62 val = ++date->tm_mon / 10;
63 css->date |= val << 12;
64 date->tm_mon -= (val * 10);
65 /* month mM */
66 val = date->tm_mon;
67 css->date |= val << 8;
68
69 /* Day Dd */
70 val = date->tm_mday / 10;
71 css->date |= val << 4;
72 date->tm_mday -= (val * 10);
73 /* Day dD */
74 val = date->tm_mday;
75 css->date |= val << 0;
76}