-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysfs.sh
More file actions
executable file
·99 lines (67 loc) · 1.83 KB
/
Copy pathsysfs.sh
File metadata and controls
executable file
·99 lines (67 loc) · 1.83 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
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
#!/bin/bash
OVERWRITE=false
COMPRESS_ATTO=false
if [ "$1" = "--overwrite" ]; then
OVERWRITE=true
fi
mkdir -p firmware/sysfs
> firmware/_sysfs.h
> firmware/_sysfs.cpp
tee -a firmware/_sysfs.h > /dev/null << EOF
// Autogenerated by \`sysfs.sh\`
#ifndef SYSFS_H_
#define SYSFS_H_
#include "datatypes.h"
EOF
tee -a firmware/_sysfs.cpp > /dev/null << EOF
// Autogenerated by \`sysfs.sh\`
#include <Arduino.h>
#include "_sysfs.h"
#include "fs.h"
bool sysfs::addFile(String path, const unsigned char* data, unsigned int length) {
if (!fs::ensureParentDirectories(path)) {
return false;
}
if (!$OVERWRITE && fs::exists(path)) {
return true;
}
fs::remove(path);
fs::FileHandle* file = fs::open(path, fs::FileMode::WRITE);
if (!file) {
return false;
}
file->write((const char*)data, length);
delete file;
Serial.print("Populated system file: ");
Serial.println(path);
return true;
}
bool sysfs::populate() {
EOF
for file in $(find rootfs -type f); do
path=${file#rootfs/}
id=${path//[\.\/]/_}
if [[ "$file" == *.at ]]; then
continue
fi
if [ $COMPRESS_ATTO = true ] && [[ "$file" == *.atto ]]; then
lib/catto/runtime/build/catto $file --gen-at ${file%.atto}.at
id=${id%_atto}_at
file=${file%.atto}.at
path=${path%.atto}.at
fi
xxd -n $id -i $file | sed -e "s/unsigned/inline unsigned/" > firmware/sysfs/$id.h
echo "#include \"sysfs/$id.h\"" >> firmware/_sysfs.h
echo " if (!addFile(\"$path\", $id, ${id}_len)) {return false;}" >> firmware/_sysfs.cpp
done
tee -a firmware/_sysfs.h > /dev/null << EOF
namespace sysfs {
bool addFile(String path, const unsigned char* data, unsigned int length);
bool populate();
}
#endif
EOF
tee -a firmware/_sysfs.cpp > /dev/null << EOF
return true;
}
EOF