Skip to content

Commit 6328015

Browse files
committed
Switched to new burn bootloader menu system, dynamically generated from the programmers.txt file.
1 parent adeff81 commit 6328015

File tree

8 files changed

+156
-280
lines changed

8 files changed

+156
-280
lines changed

app/AvrdudeUploader.java

Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -36,107 +36,88 @@ public class AvrdudeUploader extends Uploader {
3636
public AvrdudeUploader() {
3737
}
3838

39+
// XXX: add support for uploading sketches using a programmer
3940
public boolean uploadUsingPreferences(String buildPath, String className)
40-
throws RunnerException {
41+
throws RunnerException {
4142
List commandDownloader = new ArrayList();
42-
43-
// avrdude doesn't want to read device signatures (it always gets
44-
// 0x000000); force it to continue uploading anyway
45-
//commandDownloader.add("-F");
46-
4743
String protocol = Preferences.get("boards." + Preferences.get("board") + ".upload.protocol");
4844

4945
// avrdude wants "stk500v1" to distinguish it from stk500v2
5046
if (protocol.equals("stk500"))
5147
protocol = "stk500v1";
5248
commandDownloader.add("-c" + protocol);
53-
if (protocol.equals("dapa")) {
54-
// avrdude doesn't need to be told the address of the parallel port
55-
//commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
56-
} else {
57-
commandDownloader.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
58-
commandDownloader.add(
59-
"-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed"));
60-
}
61-
if (Preferences.getBoolean("upload.erase"))
62-
commandDownloader.add("-e");
63-
else
64-
commandDownloader.add("-D");
65-
if (!Preferences.getBoolean("upload.verify"))
66-
commandDownloader.add("-V");
49+
commandDownloader.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
50+
commandDownloader.add(
51+
"-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed"));
52+
commandDownloader.add("-D"); // don't erase
6753
commandDownloader.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");
6854

6955
flushSerialBuffer();
7056

71-
return uisp(commandDownloader);
72-
}
73-
74-
public boolean burnBootloaderAVRISP(String target) throws RunnerException {
75-
List commandDownloader = new ArrayList();
76-
commandDownloader.add("-c" +
77-
Preferences.get("bootloader." + target + ".programmer"));
78-
79-
if (Preferences.get("bootloader." + target + ".communication").equals("usb")) {
80-
commandDownloader.add("-Pusb");
81-
} else {
82-
commandDownloader.add(
83-
"-P" + (Base.isWindows() ?
84-
"/dev/" + Preferences.get("serial.port").toLowerCase() :
85-
Preferences.get("serial.port")));
86-
}
87-
commandDownloader.add("-b" + Preferences.get("serial.burn_rate"));
88-
return burnBootloader(target, commandDownloader);
57+
return avrdude(commandDownloader);
8958
}
9059

91-
public boolean burnBootloaderParallel(String target) throws RunnerException {
92-
List commandDownloader = new ArrayList();
93-
commandDownloader.add("-dprog=dapa");
94-
commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
95-
return burnBootloader(target, commandDownloader);
60+
public boolean burnBootloader(String programmer) throws RunnerException {
61+
List params = new ArrayList();
62+
params.add("-c" + Preferences.get("programmers." + programmer + ".protocol"));
63+
64+
if ("usb".equals(Preferences.get("programmers." + programmer + ".communication"))) {
65+
params.add("-Pusb");
66+
} else if ("serial".equals(Preferences.get("programmers." + programmer + ".communication"))) {
67+
params.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
68+
// XXX: add support for specifying the baud rate for serial programmers.
69+
}
70+
// XXX: add support for specifying the port address for parallel
71+
// programmers, although avrdude has a default that works in most cases.
72+
73+
if (Preferences.get("programmers." + programmer + ".delay") != null)
74+
params.add("-i" + Preferences.get("programmers." + programmer + ".delay"));
75+
76+
return burnBootloader(params);
9677
}
9778

98-
protected boolean burnBootloader(String target, Collection params)
99-
throws RunnerException
100-
{
101-
return
102-
// unlock bootloader segment of flash memory and write fuses
103-
uisp(params, Arrays.asList(new String[] {
104-
"-e",
105-
"-Ulock:w:" + Preferences.get("bootloader." + target + ".unlock_bits") + ":m",
106-
"-Uefuse:w:" + Preferences.get("bootloader." + target + ".extended_fuses") + ":m",
107-
"-Uhfuse:w:" + Preferences.get("bootloader." + target + ".high_fuses") + ":m",
108-
"-Ulfuse:w:" + Preferences.get("bootloader." + target + ".low_fuses") + ":m",
109-
})) &&
110-
// upload bootloader and lock bootloader segment
111-
uisp(params, Arrays.asList(new String[] {
112-
"-Uflash:w:" + Preferences.get("bootloader." + target + ".path") +
113-
File.separator + Preferences.get("bootloader." + target + ".file") + ":i",
114-
"-Ulock:w:" + Preferences.get("bootloader." + target + ".lock_bits") + ":m"
115-
}));
79+
protected boolean burnBootloader(Collection params)
80+
throws RunnerException {
81+
List fuses = new ArrayList();
82+
fuses.add("-e"); // erase the chip
83+
fuses.add("-Ulock:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.unlock_bits") + ":m");
84+
if (Preferences.get("boards." + Preferences.get("board") + ".bootloader.extended_fuses") != null)
85+
fuses.add("-Uefuse:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.extended_fuses") + ":m");
86+
fuses.add("-Uhfuse:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.high_fuses") + ":m");
87+
fuses.add("-Ulfuse:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.low_fuses") + ":m");
88+
89+
if (!avrdude(params, fuses))
90+
return false;
91+
92+
List bootloader = new ArrayList();
93+
bootloader.add("-Uflash:w:" + "hardware" + File.separator + "bootloaders" + File.separator +
94+
Preferences.get("boards." + Preferences.get("board") + ".bootloader.path") +
95+
File.separator + Preferences.get("boards." + Preferences.get("board") + ".bootloader.file") + ":i");
96+
bootloader.add("-Ulock:w:" + Preferences.get("boards." + Preferences.get("board") + ".bootloader.lock_bits") + ":m");
97+
98+
return avrdude(params, bootloader);
11699
}
117100

118-
public boolean uisp(Collection p1, Collection p2) throws RunnerException {
101+
public boolean avrdude(Collection p1, Collection p2) throws RunnerException {
119102
ArrayList p = new ArrayList(p1);
120103
p.addAll(p2);
121-
return uisp(p);
104+
return avrdude(p);
122105
}
123106

124-
public boolean uisp(Collection params) throws RunnerException {
107+
public boolean avrdude(Collection params) throws RunnerException {
125108
List commandDownloader = new ArrayList();
126109
commandDownloader.add("avrdude");
127110

128-
// On Windows and the Mac, we need to point avrdude at its config file
129-
// since it's getting installed in an unexpected location (i.e. a
130-
// sub-directory of wherever the user happens to stick Arduino). On Linux,
131-
// avrdude will have been properly installed by the distribution's package
132-
// manager and should be able to find its config file.
111+
// Point avrdude at its config file since it's in a non-standard location.
133112
if(Base.isMacOS()) {
134113
commandDownloader.add("-C" + "hardware/tools/avr/etc/avrdude.conf");
135114
}
136115
else if(Base.isWindows()) {
137116
String userdir = System.getProperty("user.dir") + File.separator;
138117
commandDownloader.add("-C" + userdir + "hardware/tools/avr/etc/avrdude.conf");
139118
} else {
119+
// ???: is it better to have Linux users install avrdude themselves, in
120+
// a way that it can find its own configuration file?
140121
commandDownloader.add("-C" + "hardware/tools/avrdude.conf");
141122
}
142123

app/Editor.java

Lines changed: 73 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -802,64 +802,73 @@ public void run() {
802802

803803
menu.addSeparator();
804804

805-
burnBootloader8Item = new JMenuItem("Burn Bootloader");
806-
burnBootloader8Item.addActionListener(new ActionListener() {
807-
public void actionPerformed(ActionEvent e) {
808-
handleBurnBootloader("atmega8", false);
809-
}
810-
});
811-
menu.add(burnBootloader8Item);
812-
813-
if (!Base.isMacOS()) {
814-
burnBootloader8ParallelItem =
815-
new JMenuItem("Burn Bootloader (parallel port)");
816-
burnBootloader8ParallelItem.addActionListener(new ActionListener() {
817-
public void actionPerformed(ActionEvent e) {
818-
handleBurnBootloader("atmega8", true);
819-
}
820-
});
821-
menu.add(burnBootloader8ParallelItem);
805+
JMenu bootloaderMenu = new JMenu("Burn Bootloader");
806+
for (Iterator i = Preferences.getSubKeys("programmers"); i.hasNext(); ) {
807+
String programmer = (String) i.next();
808+
Action action = new BootloaderMenuAction(programmer);
809+
item = new JMenuItem(action);
810+
bootloaderMenu.add(item);
822811
}
812+
menu.add(bootloaderMenu);
823813

824-
burnBootloader168DiecimilaItem = new JMenuItem("Burn Diecimila Bootloader");
825-
burnBootloader168DiecimilaItem.addActionListener(new ActionListener() {
826-
public void actionPerformed(ActionEvent e) {
827-
handleBurnBootloader("atmega168-diecimila", false);
828-
}
829-
});
830-
menu.add(burnBootloader168DiecimilaItem);
831-
814+
// burnBootloader8Item = new JMenuItem("Burn Bootloader");
815+
// burnBootloader8Item.addActionListener(new ActionListener() {
816+
// public void actionPerformed(ActionEvent e) {
817+
// handleBurnBootloader("atmega8", false);
818+
// }
819+
// });
820+
// menu.add(burnBootloader8Item);
821+
//
832822
// if (!Base.isMacOS()) {
833-
// burnBootloader168DiecimilaParallelItem =
834-
// new JMenuItem("Burn Diecimila Bootloader (parallel port)");
835-
// burnBootloader168DiecimilaParallelItem.addActionListener(new ActionListener() {
823+
// burnBootloader8ParallelItem =
824+
// new JMenuItem("Burn Bootloader (parallel port)");
825+
// burnBootloader8ParallelItem.addActionListener(new ActionListener() {
836826
// public void actionPerformed(ActionEvent e) {
837-
// handleBurnBootloader("atmega168-diecimila", true);
827+
// handleBurnBootloader("atmega8", true);
838828
// }
839829
// });
840-
// menu.add(burnBootloader168DiecimilaParallelItem);
830+
// menu.add(burnBootloader8ParallelItem);
841831
// }
842-
843-
burnBootloader168NGItem = new JMenuItem("Burn NG/Mini Bootloader");
844-
burnBootloader168NGItem.addActionListener(new ActionListener() {
845-
public void actionPerformed(ActionEvent e) {
846-
handleBurnBootloader("atmega168-ng", false);
847-
}
848-
});
849-
menu.add(burnBootloader168NGItem);
850-
851-
// if (!Base.isMacOS()) {
852-
// burnBootloader168NGParallelItem =
853-
// new JMenuItem("Burn NG/Mini Bootloader (parallel port)");
854-
// burnBootloader168NGParallelItem.addActionListener(new ActionListener() {
855-
// public void actionPerformed(ActionEvent e) {
856-
// handleBurnBootloader("atmega168-ng", true);
857-
// }
858-
// });
859-
// menu.add(burnBootloader168NGParallelItem);
860-
// }
861-
862-
showBootloaderMenuItemsForCurrentMCU();
832+
//
833+
// burnBootloader168DiecimilaItem = new JMenuItem("Burn Diecimila Bootloader");
834+
// burnBootloader168DiecimilaItem.addActionListener(new ActionListener() {
835+
// public void actionPerformed(ActionEvent e) {
836+
// handleBurnBootloader("atmega168-diecimila", false);
837+
// }
838+
// });
839+
// menu.add(burnBootloader168DiecimilaItem);
840+
//
841+
//// if (!Base.isMacOS()) {
842+
//// burnBootloader168DiecimilaParallelItem =
843+
//// new JMenuItem("Burn Diecimila Bootloader (parallel port)");
844+
//// burnBootloader168DiecimilaParallelItem.addActionListener(new ActionListener() {
845+
//// public void actionPerformed(ActionEvent e) {
846+
//// handleBurnBootloader("atmega168-diecimila", true);
847+
//// }
848+
//// });
849+
//// menu.add(burnBootloader168DiecimilaParallelItem);
850+
//// }
851+
//
852+
// burnBootloader168NGItem = new JMenuItem("Burn NG/Mini Bootloader");
853+
// burnBootloader168NGItem.addActionListener(new ActionListener() {
854+
// public void actionPerformed(ActionEvent e) {
855+
// handleBurnBootloader("atmega168-ng", false);
856+
// }
857+
// });
858+
// menu.add(burnBootloader168NGItem);
859+
//
860+
//// if (!Base.isMacOS()) {
861+
//// burnBootloader168NGParallelItem =
862+
//// new JMenuItem("Burn NG/Mini Bootloader (parallel port)");
863+
//// burnBootloader168NGParallelItem.addActionListener(new ActionListener() {
864+
//// public void actionPerformed(ActionEvent e) {
865+
//// handleBurnBootloader("atmega168-ng", true);
866+
//// }
867+
//// });
868+
//// menu.add(burnBootloader168NGParallelItem);
869+
//// }
870+
//
871+
// showBootloaderMenuItemsForCurrentMCU();
863872

864873
menu.addMenuListener(new MenuListener() {
865874
public void menuCanceled(MenuEvent e) {}
@@ -943,6 +952,17 @@ public void actionPerformed(ActionEvent actionevent) {
943952
}
944953
}
945954

955+
class BootloaderMenuAction extends AbstractAction {
956+
private String programmer;
957+
public BootloaderMenuAction(String programmer) {
958+
super("w/ " + Preferences.get("programmers." + programmer + ".name"));
959+
this.programmer = programmer;
960+
}
961+
public void actionPerformed(ActionEvent actionevent) {
962+
handleBurnBootloader(programmer);
963+
}
964+
}
965+
946966
protected void populateSerialMenu() {
947967
// getting list of ports
948968

@@ -2240,25 +2260,16 @@ protected void handleReference() {
22402260
}
22412261
}
22422262

2243-
2244-
protected void handleBurnBootloader(final String target, final boolean parallel) {
2263+
protected void handleBurnBootloader(final String programmer) {
22452264
if(debugging)
22462265
doStop();
22472266
console.clear();
2248-
//String what = sketch.isLibrary() ? "Applet" : "Library";
2249-
//message("Exporting " + what + "...");
22502267
message("Burning bootloader to I/O Board (this may take a minute)...");
22512268
SwingUtilities.invokeLater(new Runnable() {
22522269
public void run() {
22532270
try {
2254-
//boolean success = sketch.isLibrary() ?
2255-
//sketch.exportLibrary() : sketch.exportApplet();
22562271
Uploader uploader = new AvrdudeUploader();
2257-
boolean success = parallel ?
2258-
uploader.burnBootloaderParallel(target) :
2259-
uploader.burnBootloaderAVRISP(target);
2260-
2261-
if (success) {
2272+
if (uploader.burnBootloader(programmer)) {
22622273
message("Done burning bootloader.");
22632274
} else {
22642275
// error message will already be visible
@@ -2274,7 +2285,6 @@ public void run() {
22742285
}});
22752286
}
22762287

2277-
22782288
public void highlightLine(int lnum) {
22792289
if (lnum < 0) {
22802290
textarea.select(0, 0);

app/Preferences.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ static public void init() {
220220
"Error reading the board definitions file. " +
221221
"Please re-download or re-unzip Arduino.\n", ex);
222222
}
223+
224+
try {
225+
load(new FileInputStream(new File(
226+
System.getProperty("user.dir") +
227+
File.separator + "hardware" +
228+
File.separator + "programmers.txt")),
229+
"programmers");
230+
} catch (Exception ex) {
231+
Base.showError("Error reading programmers definitions",
232+
"Error reading the programmers definitions file. " +
233+
"Please re-download or re-unzip Arduino.\n", ex);
234+
}
223235
}
224236

225237

0 commit comments

Comments
 (0)