forked from nanochess/bootOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makebase.py
37 lines (32 loc) · 1.11 KB
/
makebase.py
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
import os, shutil, sys, math
files = []
with open("software.txt", "r") as file:
for line in file.readlines():
if line.startswith("#"):
continue
line = line[:-1]
c = []
for file in line.split(" "):
c.append(file.encode())
files.append(c)
flash = bytearray(0)
for s in range(0, len(files)):
dir = bytearray(16 * 32)
file_space = bytearray(512 * 256 - 2)
container = files[s]
for i in range(0, len(container)):
file = container[i]
with open("software/" + file.decode(), "rb") as f:
content = f.read()
if len(content) > 512:
print(file.decode() + " is too big")
continue
dir[i*16:i*16+len(file)] = bytearray(file)
file_space[i*512:i*512+512] = bytearray(content)
flash += bytearray(512) + dir + file_space
if not len(flash) % (512 * 256):
continue
flash += bytearray((256 * 512) - (len(flash) % (256 * 512)))
with open("base.img", "wb") as output:
output.write(flash)
print("Wrote {} bytes of data".format(len(flash)))