Fix #7428
[opentx.git] / radio / util / fat12.py
blob16c07d3a654507a0c0c85a71464c7133110fcde9
1 #!/usr/bin/env python
3 from __future__ import division, print_function
5 curr = 0
6 idx = 0
7 byte = 0
10 def push4bits(val):
11 global curr, idx, byte
12 val = val & 0x0f
13 curr += val << idx
14 idx += 4
15 if idx == 8:
16 print("0x%02X," % curr, end=' ')
17 idx = 0
18 curr = 0
19 byte += 1
20 if byte % 16 == 0:
21 print()
24 cluster = 0
27 def pushCluster(val):
28 global cluster
29 push4bits(val)
30 push4bits(val >> 4)
31 push4bits(val >> 8)
32 cluster += 1
35 def pushFile(size):
36 sectors = size // 512
37 count = sectors // 8
38 for i in range(count - 1):
39 pushCluster(cluster + 1)
40 pushCluster(0xFFF)
43 def pushDisk(eeprom, flash):
44 global curr, idx, byte, cluster
45 curr = idx = byte = cluster = 0
46 print("Disk with %dk EEPROM and %dk FLASH:" % (eeprom, flash))
47 pushCluster(0xFF8)
48 pushCluster(0xFFF)
49 pushFile(flash * 1024)
50 if eeprom > 0:
51 pushFile(eeprom * 1024)
52 while byte < 512:
53 push4bits(0)
54 print()
57 #pushDisk(32, 512)
58 pushDisk(32, 512)
60 pushDisk(0, 2048)