Author Topic: NXP USB bootloader Linux vs Windows quirk  (Read 3794 times)

0 Members and 1 Guest are viewing this topic.

Offline MattHollandsTopic starter

  • Frequent Contributor
  • **
  • Posts: 313
  • Country: gb
    • Matt's Projects
NXP USB bootloader Linux vs Windows quirk
« on: January 26, 2017, 11:57:19 pm »
My latest project uses an NXP LPC11U24 chip which is an ARM Cortex-m0. One of the neat features is that you can boot it into a preloaded usb bootloader than enumerates as a 32kb mass storage device, and then you can copy your bin file onto it - effectively programming it.

However on my Linux Debian PC, the program does not run when I reset the chip - the LEDs just glow slightly which is the same as it does when it's in the bootloader. But it does work on a Windows 10 (even a Windows 10 virtual machine running on my Linux machine).

I assumed that the flash memory must be changing in some way so I took MD5SUMs of the bin file at different stages and here is what happened:

1. MD5 of the bin file on my laptop harddrive - 4911e46463102b3bd8bbf69e75c2e407
2. Using my Windows 10 VM, attach chip via usb bootloader, delete current firmware, replace with bin file. MD5 the bin file on the chip - 4911e46463102b3bd8bbf69e75c2e407 (the same)
3. Exit bootloader, program begins to run, flashing LED etc. Reconnect chip via usb bootloader, MD5 the bin file on the chip - bec2c37631b20f3bf4723f11f9674010 (different - but program still runs)
4. Using my Linux Debian machine, attach chip via usb bootloader, delete current firmware, replace with bin file. MD5 the bin file on the chip - 4911e46463102b3bd8bbf69e75c2e407 (the same as what I got with the Windows machine)
5. Exit bootloader, program does not run, LEDs glow dimly. Reconnect chip via usb bootloader, MD5 the bin file on the chip - 664f5274738df16546427baea6c8066f (different to anything before)
This is 100% repeatable.

So from what I can see, the chip's flash changes in some way when the bootloader is disconnected, but on Linux it changes differently to how it changes on Windows such that it doesn't run at all. Slightly at a loss to what this could be. I was hoping that maybe someone else had used the bootloader on Linux or had any idea what the difference could be.

p.s. Unless there is some unsolvable problem I REALLY don't want to use Windows.
« Last Edit: January 27, 2017, 12:01:36 am by MattHollands »
Read about my stuff at: projects.matthollands.com
 

Offline BradC

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: au
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #1 on: January 27, 2017, 12:07:42 am »
Are you syncing after copying the bin across? USB Storage on Linux has a fair amount of caching and you must sync before disconnect.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #2 on: January 27, 2017, 12:21:55 am »
That neat USB MSD "trick" is a horrible idea and relies on OS specific behavior.  At some point NXP documents had a note that it only works on Windows. I'm not sure if that has changed.

But, yes, sync on a drive is a good idea.

EDIT: I guess the note was removed and all OSes are supposed to be supported now:
Quote
20121119 Modifications:
• Removed remark “USB ISP commands are supported for the Windows operating system only.”. USP ISP commands are supported in Windows, Linux, and Mac OS.
« Last Edit: January 27, 2017, 12:26:59 am by ataradov »
Alex
 

Offline MattHollandsTopic starter

  • Frequent Contributor
  • **
  • Posts: 313
  • Country: gb
    • Matt's Projects
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #3 on: January 27, 2017, 12:37:49 am »
running sync before umount does not seem to help :(
Read about my stuff at: projects.matthollands.com
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #4 on: January 27, 2017, 12:46:51 am »
Here is a workaround that worked on old bootloaders (before the fix) http://dangerousprototypes.com/docs/LPC_ARM_quick_start#Bootloaders

But I would assume that by now all devices should have a fixed version of the bootloaders.
Alex
 
The following users thanked this post: MattHollands

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #5 on: January 27, 2017, 07:13:36 am »
running sync before umount does not seem to help
If you do a proper unmount, you don't need to ecplicitly sync.

Offline MattHollandsTopic starter

  • Frequent Contributor
  • **
  • Posts: 313
  • Country: gb
    • Matt's Projects
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #6 on: January 27, 2017, 12:22:45 pm »
Here is a workaround that worked on old bootloaders (before the fix) http://dangerousprototypes.com/docs/LPC_ARM_quick_start#Bootloaders

But I would assume that by now all devices should have a fixed version of the bootloaders.

Works! Thank you!
Read about my stuff at: projects.matthollands.com
 

Offline mubes

  • Regular Contributor
  • *
  • Posts: 238
  • Country: gb
  • Do Not Boil
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #7 on: January 27, 2017, 12:55:24 pm »
Assuming you've got to the point where the LPC 'drive' is appearing then the problem is that the file-write stuff expects that the file is written to the chip in linear order, which it is on doze. Linux/OSX, not so much.  All you need to do is explicitly write the file directly to the device, something like;

Code: [Select]
dd conv=nocreat,notrunc if=newfile.bin of=/media/CRP\ DISABLD/firmware.bin
sync

Regards

DAVE
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #8 on: January 27, 2017, 04:35:45 pm »
Works! Thank you!
So 5 years later, parts are still shipped broken. Nice.
Alex
 

Offline MattHollandsTopic starter

  • Frequent Contributor
  • **
  • Posts: 313
  • Country: gb
    • Matt's Projects
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #9 on: January 27, 2017, 06:47:08 pm »
Works! Thank you!
So 5 years later, parts are still shipped broken. Nice.

Looking at the date code, it looks like this was manufactured in the 45th week of 2015. Seeing as they removed that comment in 2012, you would think that this would be correct...
Read about my stuff at: projects.matthollands.com
 

Offline dgtl

  • Regular Contributor
  • *
  • Posts: 183
  • Country: ee
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #10 on: January 28, 2017, 05:01:16 pm »
I've messed with the same issue on LPC1343 ages ago. It was broken already then.
Most of such bootloaders do not have proper fat filesystem implementation. They have researched that windows overwrites a file in place; they pre-create a fat with one file and assume that you overwrite that file so that the block mapping does not change, they just redirect these corresponding blocks of mass-storage media to flash blocks. But the OS might use blocks on the FAT filesystem in whatever order and the devide gets to know what it was only after the FAT table itself was written after the data on unmount of the FS. As there is usually not so much RAM as flash, you can't store the fw in ram for writing later; you have to write down what the computer said and un-shuffle the filesystem when OS finished and you know what the order is. But waiting for the OS to unmount the fs and after that un-shuffling the blocks is not done and the blocks of the code can remain shuffled (a lot of users would not unmount/eject the drive properly anyway).
In linux the dd workaround helps as this will open the file and write bytes to the same file without letting the fs to map blocks. Copying with overwrite files depends somewhat on file manager behavior; deleting and copying new file depends on kernel fs implementation and these seem to be not windows-compatible.
I wonder, why they won't do MTP instead of mass-storage. As mass-storage just provides raw flash block access (SCSI), it can not be accessed by multiple owners at the same time. Protocols like MTP give the pc fs-independent file-level access and this would be much more suitable.
Or we could use DFU if Microsoft would provide a generic driver or another simple way to access the device (libusb/winusb still need signed inf etc). At least they added generic usb-serial support in win10, maybe we'll get dfu in win15?
 
The following users thanked this post: MattHollands

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #11 on: January 29, 2017, 12:43:11 am »
I have written FAT filesystem drivers before, one with full functionality is not hard and doesn't take all that much space either. That's just broken. |O
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: NXP USB bootloader Linux vs Windows quirk
« Reply #12 on: January 29, 2017, 12:46:23 am »
I have written FAT filesystem drivers before, one with full functionality is not hard and doesn't take all that much space either. That's just broken. |O
But that's the trick. This bootloader does not have an actual file system, it has no place to store it. It simulates in run-time, but expects blocks  to come in in the right order, since there is no place to store ordering information. And USB MSC has no idea of the file system, it transfers sectors.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf