Skip to content

Commit 87c1cbc

Browse files
fs-builder: End filesystem area at appended script and add check
1 parent c8b92ca commit 87c1cbc

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/appended-script.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ function appendScriptToIntelHex(intelHex: string, pyCode: string): string {
102102
* Checks the Intel Hex memory map to see if there is an appended script.
103103
*
104104
* TODO: Actually implement this.
105-
* At the moment this is only used in the fs-builder and we are not yet
106-
* implementing this feature.
107-
* @param intelHex
108-
* @returns True if present.
105+
* At the moment the test version of the Python Editor also appends the script
106+
* so that it is still readable by the editor.
107+
* @param intelHexMap - Memory map for the MicroPython Intel Hex.
108+
* @returns True if script is present, false otherwise.
109109
*/
110110
function isAppendedScriptPresent(intelHexMap: object): boolean {
111-
return false;
111+
return true;
112112
}
113113

114114
export {

src/fs-builder.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ const CALIBRATION_PAGE_SIZE = FLASH_PAGE_SIZE;
3737
// Temporary maintained state pointing to the next available chunk.
3838
// TODO: Remove once nextAvailableChunk() is updated.
3939
// Chosen by fair dice roll, guaranteed to be random.
40-
const FS_START_CHUNK = 0x2b;
40+
const FS_START_CHUNK = 0x01;
4141
let FS_NEXT_AVAILABLE_CHUNK = FS_START_CHUNK;
4242

4343
function fsIncreaseChunkIndex(numberOfChunks: number): void {
4444
FS_NEXT_AVAILABLE_CHUNK += numberOfChunks;
45+
const unusedMap = new MemoryMap();
46+
// Check if we are over the filesystem area
47+
if (
48+
chuckIndexAddress(unusedMap, FS_NEXT_AVAILABLE_CHUNK) >=
49+
getEndAddress(unusedMap)
50+
) {
51+
throw new Error('There is no more space in the file system.');
52+
}
4553
}
4654

4755
function resetFileSystem(): void {
@@ -64,6 +72,7 @@ export function testResetFileSystem(): void {
6472
* @returns Next available filesystem chunk.
6573
*/
6674
function nextAvailableChunk(intelHexMap: object): number {
75+
// TODO: Check if we have run out of memory.
6776
return FS_NEXT_AVAILABLE_CHUNK;
6877
}
6978

@@ -128,10 +137,7 @@ function getPersistentPageAddress(intelHexMap: object): number {
128137
* @param chunkIndex - Index for the chunk to calculate.
129138
* @returns Address in flash for the chunk.
130139
*/
131-
function addressFromChunkIndexNew(
132-
intelHexMap: object,
133-
chunkIndex: number
134-
): number {
140+
function chuckIndexAddress(intelHexMap: object, chunkIndex: number): number {
135141
// Chunk index starts at 1, so we need to account for that in the calculation
136142
return getStartAddress(intelHexMap) + (chunkIndex - 1) * ChunkSizes.All;
137143
}
@@ -245,7 +251,7 @@ function addFileToIntelHex(
245251

246252
// Find next available chunk and its flash address
247253
const chunkIndex = nextAvailableChunk(intelHexMap);
248-
const startAddress = addressFromChunkIndexNew(intelHexMap, chunkIndex);
254+
const startAddress = chuckIndexAddress(intelHexMap, chunkIndex);
249255
// Store in an array each file converted to file system chunks
250256
const fsFile = new FsFile(filename, data);
251257
const fileFsBytes = fsFile.getFsBytes(chunkIndex);

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"outDir": "dist/esm5",
1818
"resolveJsonModule": true,
1919
"importHelpers": true
20+
// Uncomment to temporarily reduce strictness
21+
// "strict": false,
22+
// "noImplicitAny": false
2023
},
2124
"include": ["./src"],
2225
"compileOnSave": false

0 commit comments

Comments
 (0)