Date:2011-03-09 04:41:32 (8 years 7 months ago)
Author:Werner Almesberger
Commit:e8bed1f3c135f07aeedfc0cd4c9baaa091b669ec
Message:atusb/fw/: flash a boot loader instead of the application (in progress)

- boot.c: basic boot loader that runs DFU for 2 s, then starts the payload
- board.h (DFU_USB_VENDOR, DFU_USB_PRODUCT): added USB IDs for DFU
- flash.c: stubs for board-specific Flash functions
- Makefile: build boot.hex for the boot loader
- Makefile (prog): load the boot loader at its rightful place
- Makefile (prog): also set hfuse and the lock fuse
Files: atusb/fw/Makefile (3 diffs)
atusb/fw/board.h (1 diff)
atusb/fw/boot.c (1 diff)
atusb/fw/flash.c (1 diff)

Change Details

atusb/fw/Makefile
2424CC = $(AVR_PREFIX)gcc
2525OBJCOPY = $(AVR_PREFIX)objcopy
2626#OBJDUMP = $(AVR_PREFIX)objdump
27SIZE = $(AVR_PREFIX)size
2728
2829USB_OBJS = usb.o atu2.o
2930OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS)
31BOOT_OBJS = boot.o board.o spi.o flash.o dfu.o $(USB_OBJS)
3032
3133vpath %.c usb/
3234
...... 
5456
5557# ----- Rules -----------------------------------------------------------------
5658
57.PHONY: all clean upload prog version.c
59.PHONY: all clean upload prog version.c
5860
59all: $(NAME).bin
61all: $(NAME).bin boot.hex
6062
6163$(NAME).elf: $(OBJS)
6264        $(MAKE) version.o
6365        $(CC) $(CFLAGS) -mmcu=$(CHIP) -o $@ $(OBJS) version.o
6466
67boot.elf: $(BOOT_OBJS)
68        $(CC) $(CFLAGS) -mmcu=$(CHIP) -o $@ $(BOOT_OBJS) \
69          -Wl,--section-start=.text=0x7000
70
6571%.bin: %.elf
6672        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
6773        @echo "build #`cat .version`, `ls -l $@`"
6874
75%.hex: %.elf
76        $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
77        $(SIZE) $@
78
6979# ----- Cleanup ---------------------------------------------------------------
7080
7181clean:
72        rm -f $(NAME).bin $(NAME).elf $(OBJS) $(OBJS:.o=.d)
82        rm -f $(NAME).bin $(NAME).elf
83        rm -f $(OBJS) $(OBJS:.o=.d)
84        rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
7385        rm -f version.c version.d version.o
7486
7587# ----- Build version ---------------------------------------------------------
...... 
102114
103115# ----- Programming and device control ----------------------------------------
104116
105upload: $(NAME).bin
106        scp $(NAME).bin $(HOST):
117upload: $(NAME).bin boot.hex
118        scp $(NAME).bin boot.hex $(HOST):
119
120# lfuse: external clock, slow start-up
121# hfuse: 4 kB boot loader, reset into boot loader
122# lock: allow everything but SPM to the boot loader
107123
108124prog:
109125        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
110          -U flash:w:$(NAME).bin:r \
111          -U lfuse:w:0x60:m # external clock, slow start-up
126          -U flash:w:boot.hex:i \
127          -U lfuse:w:0x60:m \
128          -U hfuse:w:0xde:m \
129          -U lock:w:0xef:m
130
131# -U flash:w:$(NAME).bin:r \
112132
113133on:
114134        ssh $(HOST) poke 0x10010318 4
atusb/fw/board.h
5858#define USB_VENDOR 0x20b7 /* Qi Hardware */
5959#define USB_PRODUCT 0x1540 /* ben-wpan atusb */
6060
61#define DFU_USB_VENDOR USB_VENDOR
62#define DFU_USB_PRODUCT USB_PRODUCT
63
6164
6265void reset_rf(void);
6366uint8_t read_irq(void);
67
6468void led(int on);
6569void panic(void);
70
6671void board_init(void);
6772
6873#endif /* !BOARD_H */
atusb/fw/boot.c
1/*
2 * fw/boot.c - DFU boot loader for ATUSB
3 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdint.h>
15
16#include <avr/io.h>
17
18#define F_CPU 8000000UL
19#include <util/delay.h>
20
21#include "usb.h"
22#include "dfu.h"
23
24#include "board.h"
25#include "spi.h"
26#include "atusb/ep0.h"
27
28
29#define MS_TO_LOOPS(ms) ((uint32_t) (ms)*81)
30
31
32static void (*run_payload)(void) = 0;
33
34
35int main(void)
36{
37    uint32_t loop = 0;
38
39    board_init();
40    spi_init();
41    reset_rf();
42
43    /* now we should be at 8 MHz */
44
45    usb_init();
46    dfu_init();
47
48    led(1);
49
50    while (loop != MS_TO_LOOPS(2000)) {
51        usb_poll();
52        if (dfu.state == dfuIDLE)
53            loop++;
54        else
55            loop = 0;
56    }
57
58    led(0);
59
60    run_payload();
61
62    while (1); /* not reached */
63}
atusb/fw/flash.c
1/*
2 * fw/flash.c - Board-specific flash functions
3 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdint.h>
15
16#include <avr/io.h>
17#include <avr/interrupt.h>
18
19#define F_CPU 8000000UL
20#include <util/delay.h>
21
22#include "dfu.h"
23#include "board.h"
24
25
26
27void flash_start(void)
28{
29}
30
31
32int flash_can_write(uint16_t size)
33{
34    return 0;
35}
36
37
38void flash_write(const uint8_t *buf, uint16_t size)
39{
40}
41
42
43uint16_t flash_read(uint8_t *buf, uint16_t size)
44{
45    return 0;
46}

Archive Download the corresponding diff file



interactive