Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:17 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : updating program in stealth mode???

     Page 1 of 3    
Author Message
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 02:21am 14 Feb 2019
Copy link to clipboard 
Print this post

I've been wanting to try and figure out a way to allow the updating of a program to micromite based projects that may be physically away from me. This is not a problem of course using MMedit and just reloading a program. But if you don't want someone to get their eyes on your code, then you can do a complete hex file with mmbasic and your code and use a pickit to load the new program. Thats fine, but if the end user has no clue what a pickit is and then having to use mplab etc., this makes for a messy way to update multiple boards at multiple locations with multiple users that don't have any technical knowledge, which makes it difficult to do "software updates".

So tell me if I'm crazy, but since the console rx, tx and a ground could be accessed via a three pin header, if the end user wanted to have the latest "update" that could be downloaded from a website or even emailed to them, would it be feasible to write a piece of code, that would take a .bas file from mmedit, and do some kind of simple "encryption" creating an unreadable basic txt file on my end. Then on the user end, the user would download a "software updater" utility that reads the "encrypted" new update, translate it back to a normal .bas file, but not visible to the user, do a couple of control Cs , , or have an update button on the board that you press on power up, that simply stops any running program, and simply send that to the console port of the micromite board and then send "run". Then the biggest expense the user would have to incur is the purchase of an "updater cable" and plug it into the usb port of his computer and load the new update.

This would make it very easy to send new code to remote users. Is this a feasible idea??? The reason this is coming into play is that I have sent out pickit 3s using the "to go" capabilities, but getting someone to hook this up properly, and/or use mplab ipe is not a very good situation in most cases when someone asks for a new function or capability.
and then having them send the pickit back to me.... aaarrrrgggg.
Edited by viscomjim 2019-02-15
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 07:26am 14 Feb 2019
Copy link to clipboard 
Print this post

This sounds like a job for the 1455 now part of many of the designs. Does away with the need for a PICkit etc.

John
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 08:35am 14 Feb 2019
Copy link to clipboard 
Print this post

When I first developed the Micromite I put in a PIN code feature to secure the program. However it seems to have been one of the least used features based on the number of comments and enquiries regarding that feature (zero). Intriguingly, your requirement would take it to an even higher level.

I guess that it could be done but it would not be very secure unless a proper level of encryption was used (eg, AES-128) and that is not practical in a microcontroller with limited program flash. Given that very few people seem to be interested in the PIN feature in the first place and the difficulty of fitting it into the Micromite anyway I am sorry to report that it is unlikely to ever happen.

Geoff

BTW, you can field update the program on the MM+ with LOAD filename,R but that does not include encryption.

Geoff Graham - http://geoffg.net
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 09:04am 14 Feb 2019
Copy link to clipboard 
Print this post

@Geoff
I use the PIN feature on all of the units that have gone into the wild and thank you very much for your efforts. I assume that the use of the PIN feature is not apparent as the code that is published on this site is open to the public so the publishing of the feature is unnecessary.

Please do not feel that any of your efforts are not heavily supported.

Please keep up the fantastic work.

OA47
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 09:06am 14 Feb 2019
Copy link to clipboard 
Print this post

I hope this makes you feel better Geoff... I use the PIN code feature on quite a few projects I make that goes into someone elses hands. It is one of the great features that I really like.

I envision the use of function described above as just a "simple" means of updating programs on boards that are spread all over the place and would not require any new feature developed for the micromite firmware and only require the usb uart cable for 2 or 3 bucks. For this type of "firmware update", a 1455 is not required.

The encryption I am suggesting is just a very basic one. On my side the program would just to make the MMedit "crunched" txt file look like garbage, something like changing one bit in every ascii character (I don't know the exact details) just in case the user opened it in notepad or something. (Maybe even give it a weird extention???) This would unlikely happen, as the end user would most likely have no idea what is happening anyway as most of them are not "technical", its just a just in case thing.

The "update utility" on the user end would open the encrypted text file that was downloaded or emailed to him, magically change it back to the crunched file, stop whatever program is running in the micromite and upload the program to the micromite. Once that is done it would send "run" or the user could just hit a "done" button in the program that would send run to the micromite and all is well with the world.

Something like the MMedit "chat" feature as a standalone utility, that suppressed the text window that shows the code being sent to the micromite and only had a couple of buttons like "open update" - loads file and de-encrypts it, "send update" - does control C and sends the file to micromite, and "done" - sends run to micromite and quits. No site of the info being sent to the micromite.

This is all done on the windows side of things and wouldn't require any firmware revisions on the micromite. Just a quick and dirty way of being able to do simple updates on boards in the field.

I have seen forums on the web for different commercial products (like routers for example) that allow people to do firmware updates in a similar fashion. The user in most instances has no idea what is happening behind the scenes but can follow a youtube video on how to hook up a cable to the pc and connect the other end to some pins on a board and update a product. This is kind of where I am going with this idea. Most of the units I have out in the field are owned by non tech people, hence the simple encryption method. They have no idea what MMbasic, or a pic32 even is. They just want a new feature added or changed.
Edited by viscomjim 2019-02-15
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 11:00am 14 Feb 2019
Copy link to clipboard 
Print this post

I rarely have to do this (twice), but have in the past simply sent out a new "controller board" in a jiffy bag so that the user takes the old one out, inserts the new one and returns the old one for "refurb".

This might require a controller with a convenient connector (mine generally don't but as the user in this case has some technical ability it wasn't an issue).

Subconsciously, I have always built stand-alone controller boards which act almost as a daughter board, with the rest of the project on a main board. Makes this problem easy enough to fix.

One controller I built (a 44pin Mk2) even had two 20pin SIL header plugs so it could just drop into the socket of a PIC16F877 and assume its control functions. wasn't all plain sailing, Had hell 'n' all problems down rating everything to 3.3V on that but all worked in the end.Edited by CaptainBoing 2019-02-15
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 01:42pm 14 Feb 2019
Copy link to clipboard 
Print this post

autosave ignores the top bit of characters being set, so this is one very simple means of encryption already supported. i've just done a quick test and it works - the file was sent from the command prompt using
copy filename.bas com3:
the micromite had already been sent the AUTOSAVE using a terminal emulator.

neither teraterm nor GFXterm handle the top bit being set well, if there is demand i can change GFXterm so that (1) the top bit is allowed to be set when pasting, and (2) work on a mechanism to suppress echoing pasted characters under certain conditions.

as john has pointed out, for easily uploading .hex files there is the combination of a 1455 on a small PCB + pic32prog.exe + "P32P GUI.exe". so all you need to send the customer is a cheap bit of hardware, and a flash file containing two .exe files and the replacement .hex file. this also guarantees that there are no issues introduced by replacing the basic code and not the mmbasic firmware.


cheers,
rob :-)
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 01:50pm 14 Feb 2019
Copy link to clipboard 
Print this post

fyi, an example of what setting the top bit of non-control characters looks like:

Ðòéîô ¢Óéåöå ïæ Åòáôïóôèåîåó Óðååä Ôåóô¢
Ðòéîô
Óôáòô ½ Ôéíåò

±° ×½µ°°ºÄéí Æ¨×©ºÐ½±ºÁ½³
²° Æ¨Ð©½ÁºÐ½Ð«±ºÉæ Ð¾× Ôèåî ÇïÔï ÄÏÎÅ
³° Á½Á«²ºØ½±
´° Ó½Á¯Æ¨Ø©ºÉæ Ó½Éîô¨Ó© Ôèåî ³°
µ° Ø½Ø«±ºÉæ Ø¼Ð Áîä Æ¨Ø©ªÆ¨Ø©¼½Á Ôèåî ´°
¶° ÇïÔï ²°

ÄÏÎź
Åìáðóåä ½ ¨Ôéíåò­Óôáòô©¯±°°°
Ðòéîô Åìáðóåä ¢ óåãïîäó¢
Ðòéîô

É ½ °          § óôáôåíåîô ãïõîôåò
Ê ½ °          § ìéîå ãïõîôåò
Åòáóå Æ

±±° É½É«´º Ê½Ê«±º ×½µ°°ºÄéí Æ¨×©ºÐ½±ºÁ½³
±²° É½É«³º Ê½Ê«±º Æ¨Ð©½ÁºÐ½Ð«±ºÉæ Ð¾× Ôèåî ÇïÔï ÆÉÎÉ
±³° É½É«²º Ê½Ê«±º Á½Á«²ºØ½±
Ðòéîô ¬Ð Ãèò¤¨±³©»
±´° É½É«²º Ê½Ê«±º Ó½Á¯Æ¨Ø©ºÉæ Ó½Éîô¨Ó© Ôèåî É½É«±º ÇïÔï ±³°
±µ° É½É«²º Ê½Ê«±º Ø½Ø«±ºÉæ Ø¼Ð Áîä Æ¨Ø©ªÆ¨Ø©¼½Á Ôèåî É½É«±º ÇïÔï ±´°
±¶° É½É«±º Ê½Ê«±º ÇïÔï ±²°

ÆÉÎɺ
Ðòéîô É ¢ óôáôåíåîôó¢
Ðòéîô Ê ¢ ìéîåó¢
Ðòéîô
Ðòéîô É ¯ Åìáðóåä ¢ óôáôåíåîôó ðåò óåãïîä¢
Ðòéîô Ê ¯ Åìáðóåä ¢ ìéîåó ðåò óåãïîä¢
Ðòéîô


original:

Print "Sieve of Eratosthenes Speed Test"
Print
Start = Timer

10 W=500:Dim F(W):P=1:A=3
20 F(P)=A:P=P+1:If P>W Then GoTo DONE
30 A=A+2:X=1
40 S=A/F(X):If S=Int(S) Then 30
50 X=X+1:If X<P And F(X)*F(X)<=A Then 40
60 GoTo 20

DONE:
Elapsed = (Timer-Start)/1000
Print Elapsed " seconds"
Print

I = 0 ' statement counter
J = 0 ' line counter
Erase F

110 I=I+4: J=J+1: W=500:Dim F(W):P=1:A=3
120 I=I+3: J=J+1: F(P)=A:P=P+1:If P>W Then GoTo FINI
130 I=I+2: J=J+1: A=A+2:X=1
Print ,P Chr$(13);
140 I=I+2: J=J+1: S=A/F(X):If S=Int(S) Then I=I+1: GoTo 130
150 I=I+2: J=J+1: X=X+1:If X<P And F(X)*F(X)<=A Then I=I+1: GoTo 140
160 I=I+1: J=J+1: GoTo 120

FINI:
Print I " statements"
Print J " lines"
Print
Print I / Elapsed " statements per second"
Print J / Elapsed " lines per second"
Print
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 02:38pm 14 Feb 2019
Copy link to clipboard 
Print this post

robert.rozee - that "encryption" is exactly what I am talking about. It is very unreadable and useless to anyone. I thought that maybe the text file could be somehow easily converted to hex or something and then the other end would be converted from hex back to ascii and sent to the console port of the micromite. But what your text file looks like it does what is needed, just looks like scrambled eggs. A "crunched" version would probably look even "better" with no structure...

I have considered using the 1455, but with quite a few boards already out there without this, and if this is actually possible, then the 1455 wouldn't have to be introduced and wouldn't have to make up a bunch of pcb's, solder parts, etc. The more I dig, the cheaper I can find those 3.3v usb uart programming cables.

I have done the exchange of boards with a few people also, but of course that means trusting their abilities to disconnect several wires and then reconnect with a new board properly and then send the old one back. This introduces a lot of ifs.

I am willing to paypal a reasonable fee to a willing and capable participant to write this as it would be very useful for me. I just don't know anything about programming a pc windows type interface (even a simple one) that could handle the task, If anyone is interested, let me know.

 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 03:02pm 14 Feb 2019
Copy link to clipboard 
Print this post

Rob is on to something here.

You don't need the Micromite to decode the encryption. Instead you could write a simple program for the PC that does the decoding then sends the clear text to the Micromite over a serial USB port. The program could start the transmission with AUTOSAVE and finish with Ctrl-Z then RUN. Your PC program would ignore the text being echoed back so the user would never see the clear text.

As a proof of concept you could even write the PC program using the Windows/DOS version of MMBasic. Later you could use a compiled language so that the user cannot examine the code on the PC.

With this arrangement you could adopt as strong an encryption as you need.
Geoff Graham - http://geoffg.net
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 03:12pm 14 Feb 2019
Copy link to clipboard 
Print this post

I think the program will have to do a control C first to stop any running program, maybe do a "new" (??) and then do the autosave and Control Z then run. All the boards I do have option autorun on, so it will have to be stopped first.

I am looking at some of the basics available for windows that have gui type capabilities and can create a small exe file for the user. I just hope they support easy access to a com port. This part is quite a bit over my head, but this is how I learn stuff...

MMbasic for DOS sounds like a great idea to try this out, I will have to download it tonight and check it out.Edited by viscomjim 2019-02-16
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 01:22am 15 Feb 2019
Copy link to clipboard 
Print this post

In an effort to try and do a proof of concept using MMBasic for DOS that I just installed, I tried the following as a start... (baby steps)

I have a program on the micromite to flash an led. I have a usb to serial hooked up to the console port of the micromite from the PC.

In MMBasic for DOS I did the following...

open "com15: baud=38400" as #1
print #1, "run"
end


This worked and started the led flashing program on the micromite.

I looked up the ascii for what a control c would be (dec = 003, ascii = ETX).

I have hit my first (of many, I'm sure) brick wall. How do you send a control C or a control Z from MMbasic DOS? I tried print #1, chr$(3), no joy.

Also, once I can send the control C to the micromite, if I listen to the com port, what am I listening for that the micromite sends back for the > prompt? Would it be ASC(62), ie if reply$ = ASC(62) then... ? Thanks!

Edited by viscomjim 2019-02-16
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 01:35am 15 Feb 2019
Copy link to clipboard 
Print this post

  Quote  I tried print #1, chr$(3)

That's what MMEdit does!
You might want to use a ; to suppress the CRLF but it shouldn't be necessary

There can be a delay before the '>' appears
reply$ might contain additional characters so you have to test all characters or use INSTR.
Geoff has added a new option to serial ports to wait for a specific character but that might cause blocking which is not nice.

Jim



VK7JH
MMedit
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 02:27am 15 Feb 2019
Copy link to clipboard 
Print this post

Tassy Jim, I tried again with a ; and it worked fine. Stopped the program. I did an input$ and got the ">" tested for it using the instr and all is well. Good start for tonight.

As far as opening a .bas file from the hard drive, when I use the

open "test.bas" for input as #2


is the easiest way to send the file to the comport doing a character at a time using something like

Xx = lof(#2)
for Yy = 1 to Xx
sndtxt$ = input$(Yy, #2)
print #1, sndtxt$
next Yy


or is there a better way?

Edit.... I see I have that wrong. Need to get some sleep.

Quick question, if I use notepad plus to write and edit my code, how do I copy and paste it into the MMbasic for DOS edit window? In notepad I selected the code, right clicked "copy" and then in the dos window hit f5 for paste and the dos window has a line in red that says "clipboard is empty". Thanks!Edited by viscomjim 2019-02-16
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:52am 15 Feb 2019
Copy link to clipboard 
Print this post

In the MMbasic editor, F5 refers to the internal clipboard, not the Windows one.
To paste from the Windows clipboard, right click with the mouse.
However, I tried that while in the Editor and only the first line was pasted. It doesn't look like you can paste into the DOS editor.

Re your test program. It is best to send the file a line at a time with a delay between lines to give the micromite time to digest it.

To refresh my understanding of what you require:
You produce an updated Basic program
It gets encoded so the end-user can't snoop.
The end-user connects his device and runs a 'simple to use' program which decodes the bas file and sends it to the device, much the same as 'load and run' works in MMEdit.

Not too difficult to do. It depends a lot on how PC aware the users are. Finding the correct serial port number can be too much for some.

I was thinking about a drag-and-drop updater so give me a few days and see what I come up with.


Jim
VK7JH
MMedit
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 11:01am 15 Feb 2019
Copy link to clipboard 
Print this post

Wow, now that shows how awesome this forum is! A great thing to see first thing in the a.m. I really think this would be a great utility for micromite users that send their boards out into the wild. I'm sure a few of us do this and hear back "can you add this feature" and find ourselves in this exact spot when having to try and walk someone through the MPlab IPE after sending out a pickit 3. I've done it a few times and it really sucks.

TassyJim, I thought about one more gotcha that could rear its ugly head. I typically use Geoffs most excellent PIN feature on some boards. If the utility does a control C to stop the running program and the request comes from the micromite to enter the password, could your utility have a text box that the user could enter this?

As far as the com port search, there are a few you tube videos on this, but I would be willing to do one myself for this just to make it very clear on how to go about this. The updater cable I plan on handing out has a specific name when searching for it in the device manager (Prolific 2303 or something like that), so the end user could find out which number com port it is connected to relatively easy and select the correct one in the utility.

Can't thank you enough for considering giving this a whirl. This exercise also got me started on using MMbasic for DOS, which I know now I will continue to use. Using the com ports on the PC was easier than I thought and can make for a great interface to the micromite and MANY other things using my favorite language.Edited by viscomjim 2019-02-16
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:16pm 15 Feb 2019
Copy link to clipboard 
Print this post

I have never used the PIN option but it should be easy enough. (Famous last words)
Is the PIN specific to each customer or is it the same for all?

Jim
VK7JH
MMedit
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 09:22pm 15 Feb 2019
Copy link to clipboard 
Print this post

Jim, I usually have the PIN XXXX (and other options) in the startup code so I don't forget to implement it from the command line. I suppose there wouldn't be an issue if all software went out with the same PIN.
OA47
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 02:30am 16 Feb 2019
Copy link to clipboard 
Print this post

@TassyJim, I have always used the same pin number for every project (basically so I myself wouldn't forget it)... Most of my "in the wild" programs are used by people who don't have a clue what is going on, they just use the end product. But in general, I would guess that if the "enter pin" prompt came from the micromite due to it being set from the originator, if the end user doesn't have it, they probably shouldn't, and they would/could request it. This is not a mandatory thing, I was just thinking it would be a really great extra level of security that is already built in to MMbasic.

I know for a fact that 99% of the people using whatever I came up with, are not technically inclined enough to worry about, and just setting the msb of the ascii in the .bas file would be enough for most end users to not even think about trying to read and then duplicate my code. Hell, even if they saw it in it's original state, they wouldn't understand. They just want their new feature or function to work for their application. This may not be the case in all instances for everyone, but in most of my cases, this is enough "encryption". I'm not writing anything earth shattering to say the least. However, this is just my projects. Others may be different.


 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 03:06am 16 Feb 2019
Copy link to clipboard 
Print this post

one tip: as long as you are running the console at 115k or less, then you can stream your source code into AUTOSAVE using the following strategy:

1. send line of text, terminated with a <CR>
2. wait for an <LF> response
3. if not at end of the program, go to step 1.
4. send ctrl-Z
5. wait for an <LF> response

the key point is that while you terminate each line with a carriage return (chr$(13)), the micromite response will have a line feed (chr$(10)) added at the end. i'm assuming here that you are reading back characters one at a time using something like inkey$.


cheers,
rob :-)
 
     Page 1 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025