-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathdataflash.py
More file actions
67 lines (51 loc) · 2.09 KB
/
dataflash.py
File metadata and controls
67 lines (51 loc) · 2.09 KB
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
# -*- coding: utf-8 -*-
"""
Evic is a USB programmer for devices based on the Joyetech Evic VTC Mini.
Copyright © Jussi Timperi
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 3 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, see <http://www.gnu.org/licenses/>.
"""
import binstruct
class DataFlashError(Exception):
"""Data flash verification error."""
pass
class DataFlash(binstruct.StructTemplate):
"""Device data flash class.
Attributes:
hw_version: An integer hardware version number.
bootflag: 0 or 1. Controls whether APROM or LDROM is booted
when the device is restarted.
0 = APROM
1 = LDROM
product_id: Product ID string.
fw_version: An integer firmware version number.
ldrom_version: An integer LDROM versrion number.
"""
hw_version = binstruct.Int32Field(4)
bootflag = binstruct.Int8Field(9)
product_id = binstruct.StringField(312, 4)
fw_version = binstruct.Int32Field(256)
ldrom_version = binstruct.Int32Field(260)
df_year = binstruct.Int16Field(320)
df_month = binstruct.Int8Field(322)
df_day = binstruct.Int8Field(323)
df_hour = binstruct.Int8Field(324)
df_minute = binstruct.Int8Field(325)
df_second = binstruct.Int8Field(326)
def verify(self, checksum):
"""Verifies the data flash against given checksum.
Args:
checksum: Checksum of the data.
Raises:
DataFlashError: Data flash verification failed.
"""
if sum(self.array) != checksum:
raise DataFlashError("Data flash verification failed.")