Parcourir la source

have the device give out its own source code

Thomas Buck il y a 1 an
Parent
révision
558224aa67
4 fichiers modifiés avec 62 ajouts et 2 suppressions
  1. 8
    0
      CMakeLists.txt
  2. 1
    1
      include/fat_disk.h
  3. 20
    0
      pack_data.sh
  4. 33
    1
      src/fat_disk.c

+ 8
- 0
CMakeLists.txt Voir le fichier

@@ -84,6 +84,14 @@ target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/st7789/src)
84 84
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/st7789/interface)
85 85
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/decoder)
86 86
 target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mcufont/fonts)
87
+target_include_directories(gadget PUBLIC ${CMAKE_CURRENT_LIST_DIR}/build)
88
+
89
+# compress source code and stuff we want to include
90
+add_custom_target(pack bash -c "./pack_data.sh"
91
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
92
+    BYPRODUCTS "build/pack_data.h"
93
+)
94
+add_dependencies(gadget pack)
87 95
 
88 96
 # enable generous warnings
89 97
 target_compile_options(gadget PUBLIC

+ 1
- 1
include/fat_disk.h Voir le fichier

@@ -16,7 +16,7 @@
16 16
  * See <http://www.gnu.org/licenses/>.
17 17
  */
18 18
 
19
-#define DISK_BLOCK_COUNT 256
19
+#define DISK_BLOCK_COUNT 300
20 20
 #define DISK_BLOCK_SIZE 512
21 21
 
22 22
 void fat_disk_init(void);

+ 20
- 0
pack_data.sh Voir le fichier

@@ -0,0 +1,20 @@
1
+#!/bin/bash
2
+set -euo pipefail
3
+
4
+cd "$(dirname "$0")"
5
+echo "Packing data"
6
+
7
+mkdir -p build/src
8
+cp COPYING build/src
9
+cp README.md build/src
10
+cp CMakeLists.txt build/src
11
+cp -r include build/src
12
+cp -r src build/src
13
+
14
+cd build
15
+rm -rf data.tar data.tar.xz
16
+tar -f data.tar -c src
17
+xz -z -9 data.tar
18
+
19
+xxd -i data.tar.xz > pack_data.h
20
+sed -i 's/unsigned/static const unsigned/g' pack_data.h

+ 33
- 1
src/fat_disk.c Voir le fichier

@@ -29,6 +29,8 @@
29 29
 #include "debug.h"
30 30
 #include "fat_disk.h"
31 31
 
32
+#include "pack_data.h"
33
+
32 34
 static uint8_t disk[DISK_BLOCK_COUNT * DISK_BLOCK_SIZE];
33 35
 
34 36
 void fat_disk_init(void) {
@@ -58,7 +60,8 @@ void fat_disk_init(void) {
58 60
         pos += snprintf(readme + pos, 1024 - pos, "\r\n");
59 61
         pos += snprintf(readme + pos, 1024 - pos, "Project by Thomas Buck <thomas@xythobuz.de>\r\n");
60 62
         pos += snprintf(readme + pos, 1024 - pos, "Licensed under GPLv3.\r\n");
61
-        pos += snprintf(readme + pos, 1024 - pos, "Source at https://git.xythobuz.de/thomas/sb-py\r\n");
63
+        pos += snprintf(readme + pos, 1024 - pos, "See included src.tar.xz for sources.\r\n");
64
+        pos += snprintf(readme + pos, 1024 - pos, "Repo at https://git.xythobuz.de/thomas/sb-py\r\n");
62 65
 
63 66
         size_t len = strlen(readme);
64 67
         UINT bw;
@@ -73,6 +76,35 @@ void fat_disk_init(void) {
73 76
         }
74 77
     }
75 78
 
79
+    res = f_open(&file, "src.tar.xz", FA_CREATE_ALWAYS | FA_WRITE);
80
+    if (res != FR_OK) {
81
+        debug("error: f_open returned %d", res);
82
+    } else {
83
+        UINT bw;
84
+        UINT len = 0;
85
+        while (1) {
86
+            debug("write %d", len);
87
+            res = f_write(&file, data_tar_xz + len, data_tar_xz_len - len, &bw);
88
+            if (bw == 0) {
89
+                debug("abort");
90
+                break;
91
+            }
92
+            len += bw;
93
+            if (res != FR_OK) {
94
+                debug("error: f_write returned %d", res);
95
+                break;
96
+            }
97
+            if (bw == data_tar_xz_len) {
98
+                break;
99
+            }
100
+        }
101
+
102
+        res = f_close(&file);
103
+        if (res != FR_OK) {
104
+            debug("error: f_close returned %d", res);
105
+        }
106
+    }
107
+
76 108
     if (debug_msc_unmount() != 0) {
77 109
         debug("error unmounting disk");
78 110
     }

Chargement…
Annuler
Enregistrer