Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memory visualization #321

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
"prepare": "husky install"
},
"devDependencies": {
"nrf-intel-hex": "^1.2.0",
"nrf-intel-hex": "^1.3.0",
"pc-nrfconnect-shared": "git+https://github.com/NordicSemiconductor/pc-nrfconnect-shared.git#v6.6.1",
"react-timer-hook": "^3.0.5"
},
"dependencies": {},
"dependencies": {
"elfy": "^1.0.0"
},
"eslintConfig": {
"extends": "./node_modules/pc-nrfconnect-shared/config/eslintrc"
},
Expand Down
30 changes: 30 additions & 0 deletions resources/css/canvas.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2015 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
*/

.canvas-container {
width: 100%;
height: 100%;
overflow: scroll;

&::-webkit-scrollbar,
jesper2k marked this conversation as resolved.
Show resolved Hide resolved
&::-webkit-scrollbar-corner {
width: 10px;
height: 0px; // Needed, don't remove
}

&::-webkit-scrollbar-thumb {
background: $gray-500;
border-radius: 5px;
border: 3px solid white;
}
&::-webkit-scrollbar-thumb:hover {
background: $gray-700;
}

canvas {
border: 1px solid white;
}
}
23 changes: 23 additions & 0 deletions resources/css/section-info-view.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2015 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
*/

.section-info-view {
padding-top: 4px;
font-size: 12px;
min-width: 155px;
.fields {
padding-top: 12px;
border-bottom: 1px solid $gray-200;
}
div:last-child {
border: none;
}
p {
text-align: left !important;
padding-top: 0 !important;
color: $gray-900 !important;
}
}
42 changes: 39 additions & 3 deletions src/actions/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'pc-nrfconnect-shared';

import {
elfParse,
fileParse,
filesEmpty,
mcubootFileKnown,
Expand Down Expand Up @@ -239,6 +240,35 @@ const parseHexFile =
dispatch(updateTargetWritable());
};

const parseElf = (filePath: string) => async (dispatch: TDispatch) => {
const stats = await new Promise<Stats>((resolve, reject) => {
stat(filePath, (statsError, result) => {
if (statsError) {
logger.error(
`Could not open Elf file: ${describeError(statsError)}`
);
dispatch(
ErrorDialogActions.showDialog(describeError(statsError))
);
removeMruFile(filePath);
return reject();
}
return resolve(result);
});
});

logger.info('Checking Elf file: ', filePath);
logger.info('File was last modified at ', stats.mtime.toLocaleString());
addMruFile(filePath);
// License for elfy can be found at https://github.com/indutny/elfy
/* eslint-disable global-require */
const elfy = require('elfy');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason for using an inline require instead of a global import statement.

const fs = require('fs');
const fileData = fs.readFileSync(filePath);
const elf = elfy.parse(fileData);
dispatch(elfParse(elf));
};

export const openFile =
(...params: string[]) =>
async (dispatch: TDispatch): Promise<unknown> => {
Expand All @@ -256,22 +286,28 @@ export const openFile =
dispatch(updateTargetWritable());
return dispatch(openFile(...params.slice(1)));
}
if (filePath.toLowerCase().endsWith('.elf')) {
dispatch(filesEmpty());
await dispatch(parseElf(filePath));
return dispatch(openFile(...params.slice(1)));
}
if (
filePath.toLowerCase().endsWith('.hex') ||
filePath.toLowerCase().endsWith('.ihex')
) {
dispatch(filesEmpty());
jesper2k marked this conversation as resolved.
Show resolved Hide resolved
await dispatch(parseHexFile(filePath));
return dispatch(openFile(...params.slice(1)));
}
};

export const openFileDialog = () => (dispatch: TDispatch) => {
const dialogOptions = {
title: 'Select a HEX / ZIP file',
title: 'Select a HEX / ZIP / ELF file',
filters: [
{
name: 'HEX / ZIP files',
extensions: ['hex', 'iHex', 'zip'],
name: 'HEX / ZIP / ELF files',
extensions: ['hex', 'iHex', 'zip', 'elf'],
},
],
properties: ['openFile', 'multiSelections'],
Expand Down
10 changes: 6 additions & 4 deletions src/components/AppMainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { useSelector } from 'react-redux';

import { getLoaded, getZipFilePath } from '../reducers/fileReducer';
import { getElf, getLoaded, getZipFilePath } from '../reducers/fileReducer';
import { getDeviceInfo, getSerialNumber } from '../reducers/targetReducer';
import useOpenFileFromArgs from '../useOpenFileFromArgs';
import { DeviceDefinition } from '../util/devices';
Expand Down Expand Up @@ -38,6 +38,7 @@ const AppMainView = () => {
const zipFilePath = useSelector(getZipFilePath);
const serialNumber = useSelector(getSerialNumber);
const deviceInfo = useSelector(getDeviceInfo);
const elf = useSelector(getElf);

useOpenFileFromArgs();

Expand All @@ -47,17 +48,18 @@ const AppMainView = () => {
<div className="memory-box-container">
<MemoryBoxView
title="File memory layout"
description="Drag & drop HEX/ZIP files here"
iconName="mdi mdi-folder-open"
description="Drag & drop HEX/ZIP/ELF files here"
iconName="mdi mdi-file-outline"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for changing the title and icon?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think it's more intuitive that you're looking at an elf-file if there's a file icon + extension, than if you just see a directory/folder icon. But the title change should be reverted, thanks for catching that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is right now it changes the default behaviour so that mdi-file-outline is shown also for all other states (like no files or other file types).
Do ask Ketil though, maybe he thinks this is how it should be.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Ketil approves

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1337

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will work on this so it works with hex and zip files too

isHolder={!hasFileContent(loaded) && !zipFilePath}
containsVisualization={elf !== undefined}
/>
<MemoryBoxView
title={
getTargetTitle(serialNumber, deviceInfo) ||
'Device memory layout'
}
description="Connect a device to display memory contents"
iconName="appicon-chip"
iconName="mdi appicon-chip"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is mdi added here for some kind of layout css?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Yep, and I'm assuming that this change was made to inherit the correct fonts since that's what I changed for the "icon with file extension" feature that we discussed above.

isHolder={!serialNumber}
isTarget={!!serialNumber}
/>
Expand Down
Loading