how to move from halfkay to a free bootloader?

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I've been working on a project to make an open source mouse pcb which it mostly is, including the code. You can view it at the link below if interested. since i can't solder smt i hired a guy to assemble the pcb, but he hasn't got back to me after a bereavement. So then I paid for the jlcpcb assembly service and since i'm a linux user decided to change the standard atmel FLIP. I flashed the atmega32u4 successfully over isp with the atmel-dfu bootloader according to the qmk mech keyboards repo instructions. with the halfkay bootloader, the firmware takes up 26% of the flash, so even with a larger bootloader it should be okay I hope. anyway since i'm an elderly script kiddie I don't know how to generate a makefile supporting atmel-dfu. normally i'd just copy a makefile from another project, but all i've found are based around qmk, which is very abstracted and not easy usable.

as an alternative I could flash the firmware over isp, but i don't want to do that every time, and the existing button code to jump to the bootloader will not function due to the different bootloader size.

 

https://www.overclock.net/forum/...

 

code is here:

 

https://www.overclock.net/forum/...

 

so ideally i'd like someone to point me to a makefile for atmel-dfu that would be compatible with this code. I've tried modifying makefiles in the past, but my text editor seems to screw them up if I do too much.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gipetto wrote:
... with the halfkay bootloader, ...
fyi, ubaboot is an alternative to HalfKay though ubaboot is GPLv3 which is compatible with your source code.

One of the several advantages of HalfKay is permissiveness for applications.

gipetto wrote:
code is here:
Some of those files are missing copyright and cannot be copied [pedantic]

Might consider a license file(s) in the zip's root directory if don't want to add to the contents of the current files.

 

P.S.

A similar handle :

Geppetto Electronics

 


HalfKay Communication Protocol | PJRC

GitHub - rrevans/ubaboot: USB bootloader for atmega32u4 in 512 bytes

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, i'll look into ubaboot. it would be helpful if the jump to bootloader address stayed the same. i doubt it will, but there's a chance. I change my handle every few years so i'm not too worried.

Last Edited: Wed. Jan 1, 2020 - 12:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

megaAVR USB DFU is built-in after final test or during assembly (Microchip Thailand for QFP)

My TO DO is to search for megaAVR USB DFU how-to (ASF3?) maybe this evening or sometime tomorrow.

 

https://www.microchip.com/mymicrochip/Reports.aspx?type=cpn&filter=ATmega32U4

 

edit :

ubaboot constrains application developers (GPLv3) whereas PJRC Teensy and Microchip do not.

PJRC Store | Teensy 2.0 (ATmega32U4 QFN with HalfKay bootloader)

PJRC Store | 32U4 Chip (ATmega32U4 QFP with HalfKay bootloader)

"Dare to be naïve." - Buckminster Fuller

Last Edited: Wed. Jan 1, 2020 - 02:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I should have clarified, I bought the 32u4 from pjrc but the human factor was the bottleneck. I wanted to have a turnkey assembly from the jlcpcb parts library without extra companies adding charges.

Last Edited: Wed. Jan 1, 2020 - 10:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just to note that LUFA has a DFU bootloader and can be built from makefiles.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

ubaboot constrains application developers (GPLv3) whereas PJRC Teensy and Microchip do not.

 

I have to push back on that.

 

GPL v3 bootloader doesn't constrain the application at all. PJRC don't publish source code, how can that not be a constraint??

 

@gipetto I would be interested in helping

Bob. Engineer and trainee Rocket Scientist.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

help me understand this. the bootloader is one program, the firmware is another program. my issue is that I don't have a working firmware makefile which is compatible with a free bootloader, not that i need a bootloader that can be built from makefiles. Is there some way that a single makefile can be used to combine both programs?

 

@donotdespisethesnake I have some spare pcbs here, one spare populated, the rest not free if you can assemble them yourself. I would like to hold on to the populated spare though for diagnosing faults but i might let it go if you needed it for testing. at the moment i'm just looking to modify the makefile linked above for atmel-dfu, since i have that bootloader flashed already. i understand it would be a step less to use atmel-flip if it was to be done again but i don't have a windows machine here and last i checked wine doesn't handle windows ports very well. the mouse shells supported are the intellimouse optical 1.1, the wheel mouse optical, and the intellimouse 1.3. the io1.1 shells are available on aliexpress.

 

if you want to order the pcb assembled from jlcpcb the files are here, though you'll need a python script to format them and kicad nightly. i can walk you through it.

https://github.com/itsnoteasy/mi...

Last Edited: Wed. Jan 1, 2020 - 02:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Weeks 11-12: AVR USB Devices and Programming

by Andrew Mao

at MIT

 

[mid-page]

Programming via DFU

...

[blinky]

...

Here’s my Makefile for programming and erasing the board over DFU:

...

 

[after mid-page]

Programming with LUFA

...

[Makefile]

...

Note that the bootloader takes up 4K of the ATmega16U2’s 16K flash memory. If a bigger program is needed, it would be time to switch to an ISP.

One could compare the sizes of the DFU bootloaders (Atmel, Dean's LUFA)

Dean also has a USB HID bootloader that appears to be 2KB; could compare it via AVR GCC and via IAR EWAVR KickStart.

https://github.com/abcminiuser/lufa/blob/master/Bootloaders/HID/BootloaderHID.txt#L54

 

LUFA isn't copyleft :

https://github.com/abcminiuser/lufa/blob/master/README.txt#L16

 


IAR Embedded Workbench - AVR

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR are statically linked with one program space; GPL and LGPL are copyleft.

ARM Cortex-M with MPU can have GPL code in one memory region with other code in other memory regions; uClinux is one instance (Linux system calls, shared object or .so)

AVR32 UC3 and PIC32 are other MCU with a MPU; PIC32MZ EF and PIC32MZ DA-series have MMU.

UC3C and UC3L have FlashVaultTM to secure code; arm Cortex-M23 and Cortex-M33 have TrustZone.

donotdespisethesnake wrote:
PJRC don't publish source code, ...
of HalfKay bootloader though do publish the USB interface source code for Teensy applications.

There's no copyright of HalfKay; therefore, HalfKay cannot be copied.

donotdespisethesnake wrote:
... how can that not be a constraint??
The beauty of HalfKay has several dimensions (one is size cheeky

ubaboot is also impressive.

 


Practical Advice on Running uClinux on Cortex-M3/M4 | Electronic Design

Linux, in the form of uClinux, runs on platforms like STmicroelectronics' STM32. Vladimir Khusainov, co-founder and Director of Engineering at Emcraft Systems, talks about how this works.

Vladimir Khusainov

SEP 17, 2012

...

Linux and System-On-Modules: i.MX RT1050, STM32F7, SmartFusion2, i.MX 8M, i.MX 6ULL, i.MX 6SoloX (EmCraft Systems)

 

Dual licenses (GPL, corporate) :

Licensing -- Quantum Leaps

[1/4 page, left column]

...

Please note that GPL requires that all modifications to the original code as well as your application code (Derivative Works as defined in the Copyright Law) must also be released under the terms of the GPL open source license.

[3 exceptions for original boards : Arduino, mbed, Raspberry Pi]

...

 

License Price List

...

The exceptions aid the S in SMB/SME for design wins by proof-of-concept; discussion with the customer on first prototype is a part of the negotiation (customer will inquire about price and cost)

Another exception that aids is the GCC run-time exception for most, not all, instances of GCC.

gcc/COPYING.RUNTIME at master · gcc-mirror/gcc · GitHub

LLVM is on a different license; AVR LLVM is in beta.

http://llvm.org/docs/FAQ.html#can-i-modify-the-llvm-source-code-and-redistribute-binaries-or-other-tools-based-on-it-without-redistributing-the-source

 

https://github.com/PaulStoffregen/cores/blob/master/usb_hid/usb.c#L3 (PJRC)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gipetto wrote:
... and last i checked wine doesn't handle windows ports very well.
The commercial Wine, CrossOver, is more complete wrt Win32 (Windows XP, a good amount of Windows 7)

CodeWeavers has CrossOver as primary customers are gamers and office workers (Office 365, Office 2010 and etc) (so, a fair amount of .NET)

Visual Studio is a no go; therefore, Atmel Studio is a no go (Visual Studio 2015 Isolated Shell)

AVR Studio is a go (Windows XP) though USB is iffy (linked file systems)

Wine 5 is on its way; Wine 4 has USB HID for game controllers (Atmel-ICE (EDBG) is USB HID for programming and debugging, MPLAB PICkit 4 and MPLAB Snap have an EDBG mode)

Some AVR in Visual Studio Code.

 

P.S.

Operated, well, Wine on Linux for a Windows XP application about ten years ago.

Crossover 18.1.0 on Chrome OS is in a long duration beta; am having issues with it for a Windows 7 application though with workarounds (apparent memory fragmentation, a few apparent benign buffer overruns)

Chrome OS lacks USB CDC though that may already be corrected for its Linux VM (due to Android Studio on Linux on Chrome OS)

Chrome OS runs most Android applications.

AVRDUDE has been ported to Android; Android has USB HCI and USB CDC.

 


CodeWeavers Blogs | Jeremy White | Celebrating the difficult; the release of CrossOver 19 | CodeWeavers

by Jeremy White [creator of CodeWeavers]

10 December 2019

[next to last paragraph]

In the New Year, we are looking forward to Wine 5.0 and building new a version of CrossOver that leverages the incredible range of work that is going into Wine 5.0 as we speak.

...

 

https://www.avrfreaks.net/forum/avr-studio-mac-linux#comment-2600281

 

https://play.google.com/store/apps/details?id=ru.zdevs.zflasheravr

...

ZFlasher AVR - program for flash AVR microcontrollers. The application is based on avrdude - one of the best flasher.

Your device must support USB Host (OTG), otherwise the program will not work.

Program work checked with programmer:
* USBasp
* AVRISP mkII
* USBtiny
* STK500v2
* AVR109
* Arduino bootloader [USB CDC]

!! Some devices may have problems with USB, if the device was turned on with the connected OTG. Remove OTG adapter before boot device!

...

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

Dual licenses (GPL, corporate) :

Licensing -- Quantum Leaps

[1/4 page, left column]

...

Please note that GPL requires that all modifications to the original code as well as your application code (Derivative Works as defined in the Copyright Law) must also be released under the terms of the GPL open source license.

[3 exceptions for original boards : Arduino, mbed, Raspberry Pi]

...

 

License Price List

...

I'm dubious about this.

If the application would work just as well installed with ISP, how could it be a derivative work of the bootloader?

Some bootloaders are designed to share data or code with the application.

I suppose an application that actually used that data or code would be a derived work.

Otherwise, I say nyet.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gipetto wrote:
elp me understand this. the bootloader is one program, the firmware is another program. my issue is that I don't have a working firmware makefile which is compatible with a free bootloader, not that i need a bootloader that can be built from makefiles. Is there some way that a single makefile can be used to combine both programs?
Yes, but don't.

As noted, they are distinct programs.  They should be treated as such.

 

If you must, a recursive make would do the trick.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skeeve wrote:
If the application would work just as well installed with ISP, how could it be a derivative work of the bootloader?
A CPU and its program spaces or lack thereof (AVR have one program space)

AVR have address spaces though no MPU.

skeeve wrote:
Some bootloaders are designed to share data or code with the application.
via secure shares (arm TrustZone for Cortex-M23 and Cortex-M33)

MPU is optional for arm Cortex-M0+

(any arm Cortex-M0+ SAM with an MPU?)

skeeve wrote:
I suppose an application that actually used that data or code would be a derived work.
LGPL allows for dynamic linking such that an application isn't copyleft'd.

Can thunk between two memory regions via an MPU or MMU (bootloader is GPL, application is any)

edit : Sideways though not an end run.

FSF AVR GCC has trampolines.

https://gcc.gnu.org/onlinedocs/gcc-5.5.0/gcc/AVR-Options.html#EIND-and-Devices-with-More-Than-128-Ki-Bytes-of-Flash

 


https://gcc.gnu.org/wiki/avr-gcc#Address_Spaces

Using TrustZone for Armv8-M | CMSIS-Core (Cortex-M)

Cortex-M – Arm Developer

[1/3 page]

Cortex-M comparison table

GNU Lesser General Public License v3 (LGPL-3.0) Explained in Plain English - TLDRLegal

...

Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under LGPL, but applications that use the library don't have to be.

...

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Wed. Jan 1, 2020 - 05:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:
skeeve wrote:

If the application would work just as well installed with ISP, how could it be a derivative work of the bootloader?

A CPU and its program spaces or lack thereof (AVR have one program space)

 

AVR have address spaces though no MPU.

Suppose I give the same object code to four different people with four different boards.

One board has a GPL bootloader that I did not write, but gave its human a year ago.

Another human acquired a different GPL bootloader from someone other than myself.

Another board does not have a bootloader.  Its human uses ISP.

The fourth human, unbeknownst to him, is using a proprietary bootloader on the target chip.

To which of these humans would I have to give the source code?

Does it matter whether I know which human has which kind of board?

Does it matter which order I hand out copies?

What if I do not know the order?

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The bootloader is not linked with the appplication. All this talk about "memory spaces" and MPUs is just nonsense.

Bob. Engineer and trainee Rocket Scientist.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Ok fellas, the nice guys in the qmk discord walked me through installing atmel-dfu, the makefile didn't need any modifications. the mouse buttons now register and i'm ok to proceed. thanks for all the help, and if you want to follow on the project check the overclock.net link above.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's also the Arduino bootloader ("Caterina"?), which I believe is based on the LUFA bootloader.

 

GPL licenses get pretty awful to apply to deeply embedded systems.  It annoys me that people will slap GPL on (for example) an Arduino library without really understanding what it means. :-(

 

I said this about Optiboot (the Arduino AVR Serial bootloader)  ( https://forum.arduino.cc/index.p... ):

It is my intent and understanding (as the current maintainer of Optiboot) that Optiboot is like the linux kernel; completely distinct from the application, and "not connected" in any way that would cause the Optiboot license to apply to a product that uses proprietary application code but uses optiboot for booting.

Halfkay, of course,  is not open source and has its own licensing requirements.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the clarification.

 

The OP is making an Open Source project, so this is not even an issue.

Bob. Engineer and trainee Rocket Scientist.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
GPL licenses get pretty awful to apply to deeply embedded systems.
The Linux Foundation provides guidance for small operators; there's OpenChain for larger operations.

Exceptions to GPL can exist that are

  • narrow (particular and/or specific use cases)
  • wide (limit the scope)
  • uncertain (indecision)
  • unknown (known to an attorney, unknown to mefrown

 

Practical GPL Compliance - The Linux Foundation

Home - OpenChain

due to

How OpenChain certification aids open-source transparency for identifying security vulnerabilities - Embedded.com

...

One of the [OpenChain] core requirements is the creation (and maintenance) of an open source bill of materials. 

...

License Exceptions | Software Package Data Exchange (SPDX)

...

Bootloader-exception

...

Frequently Asked Questions about the GNU Licenses - GNU Project - Free Software Foundation

[mid-page]

What is the difference between an “aggregate” and other kinds of “modified versions”?

[third paragraph]

...

If modules are designed to run linked together in a shared address space, that almost surely means combining them into one program.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I filed down some solder blobs and accidentally damaged a pcb trace which I believe I patched up correctly. I have this small program to light an led depending on whether a trace works or not but it's not lighting for me. can anyone see any obvious errors?

 

#include <avr/io.h>        //This is our usual include
#define F_CPU 16000000UL    //This says to the compiler at what frequency our Atmega is running, in this case its 16Mhz
#include <util/delay.h>        //The delay functions/routines
 
int main(void){
DDRD &= ~(1<<PD2);    //Configure PORTD pin 2 as an input
PORTD |= (1<<PD2);    //Activate pull-ups in PORTD pin 2
DDRD |= (1<<PD6);    //Configure an output, built-in led
 
 while(1){                //Infinite loop
   if(PIND & (1 << 2)){        //ready the button state
   DDRD &= ~(1 << 6); //led high
   }else{
   DDRD |= (1 << 6); //led low
   }
_delay_ms(1000);
 }
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope nothing obviously wrong in that (assuming PD2 button is normally open and connects to ground when closed)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I figured it out, it turned out i was still stuck in bootloader mode because I didn't replug the usb cable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gipetto wrote:
... because I didn't replug the usb cable.
USB Port Power Control | Power Management for USB — The Linux Kernel documentation

if the USB hub can cycle VBUS

 

"Dare to be naïve." - Buckminster Fuller