Skip to content

Commit 4437c44

Browse files
committed
fix: make elf file optional
1 parent e14ebb2 commit 4437c44

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/APITypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface APIResultError {
4949

5050
export interface APISimStartParams {
5151
firmware: string;
52-
elf: string;
52+
elf?: string;
5353
pause?: boolean;
5454
chips?: string[];
5555
}

src/WokwiConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface WokwiTOML {
77
wokwi: {
88
version: number;
99
firmware: string;
10-
elf: string;
10+
elf?: string;
1111
gdbServerPort?: number;
1212
};
1313
chip?: WokwiTOMLChip[];

src/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ export async function parseConfig(data: string, configRoot: string) {
1212
throw new Error(`Unsupported wokwi.toml version: ${wokwi.version}`);
1313
}
1414

15-
if (typeof wokwi.firmware !== 'string' || typeof wokwi.elf !== 'string') {
16-
throw new Error('Firmware and ELF paths must be strings');
15+
if (typeof wokwi.firmware !== 'string') {
16+
throw new Error('Firmware path must be a string');
17+
}
18+
if (wokwi.elf != null && typeof wokwi.elf !== 'string') {
19+
throw new Error('ELF path must be a string');
1720
}
1821

1922
return wokwiConfig;

src/main.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ async function main() {
162162
config = await parseConfig(configData, rootDir);
163163

164164
firmwarePath = elf ?? join(rootDir, config.wokwi.firmware);
165-
elfPath = elf ?? join(rootDir, config.wokwi.elf);
165+
const configElfPath = config.wokwi.elf ? join(rootDir, config.wokwi.elf) : undefined;
166+
elfPath = elf ?? configElfPath;
166167
} else if (elf) {
167168
firmwarePath = elf;
168169
elfPath = elf;
@@ -181,7 +182,7 @@ async function main() {
181182
process.exit(1);
182183
}
183184

184-
if (!existsSync(elfPath)) {
185+
if (elfPath != null && !existsSync(elfPath)) {
185186
const fullPath = path.resolve(elfPath);
186187
console.error(chalkTemplate`{red Error:} ELF file not found: {yellow ${fullPath}}.`);
187188
console.error(
@@ -268,7 +269,9 @@ async function main() {
268269
await client.connected;
269270
await client.fileUpload('diagram.json', diagram);
270271
const firmwareName = await uploadFirmware(client, firmwarePath);
271-
await client.fileUpload('firmware.elf', readFileSync(elfPath));
272+
if (elfPath != null) {
273+
await client.fileUpload('firmware.elf', readFileSync(elfPath));
274+
}
272275

273276
for (const chip of chips) {
274277
await client.fileUpload(`${chip.name}.chip.json`, readFileSync(chip.jsonPath, 'utf-8'));
@@ -333,8 +336,8 @@ async function main() {
333336
};
334337

335338
await client.simStart({
336-
elf: 'test.elf',
337339
firmware: firmwareName,
340+
elf: elfPath != null ? 'firmware.elf' : undefined,
338341
chips: chips.map((chip) => chip.name),
339342
pause: timeToNextEvent >= 0,
340343
});

0 commit comments

Comments
 (0)