First sketch of image uploader
This commit is contained in:
parent
bfdae2a7a7
commit
b774d61713
6 changed files with 174 additions and 7 deletions
|
@ -12,7 +12,7 @@ CONTIKI_WITH_IPV6 = 1
|
|||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
PROJECT_SOURCEFILES += res_upload_image.c ${SKETCH}.cpp
|
||||
PROJECT_SOURCEFILES += res_upload_image.c res_bootloader.c ${SKETCH}.cpp
|
||||
|
||||
# variable for Makefile.include
|
||||
ifneq ($(TARGET), minimal-net)
|
||||
|
@ -34,7 +34,7 @@ SMALL=1
|
|||
# REST Engine shall use Erbium CoAP implementation
|
||||
APPS += er-coap
|
||||
APPS += rest-engine
|
||||
APPS += arduino #json-resource #time json arduino
|
||||
APPS += arduino json-resource json #time
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
include $(CONTIKI)/apps/arduino/Makefile.include
|
||||
|
|
38
examples/osd/ota-update/ota_uploader.py
Executable file
38
examples/osd/ota-update/ota_uploader.py
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import intelhex
|
||||
from subprocess import Popen
|
||||
|
||||
class Upload_Info (object) :
|
||||
|
||||
def __init__ (self, ip, filename) :
|
||||
self.ip = ip
|
||||
self.filename = filename
|
||||
# end def __init__
|
||||
|
||||
def read_hex (self) :
|
||||
self.ihex = intelhex.IntelHex (self.filename)
|
||||
# end def read_hex
|
||||
|
||||
def get_coap_int (self, path) :
|
||||
""" Get coap variable of type integer
|
||||
"""
|
||||
url = 'coap://[%s]/%s' % (self.ip, path)
|
||||
cmd = ('coap-client', '-m', 'get', '-A', 'text/plain', url)
|
||||
p = Popen (cmd, stdout = PIPE, stderr = PIPE)
|
||||
out, err = p.communicate ()
|
||||
if err :
|
||||
raise IOError (err)
|
||||
return int (out)
|
||||
# end def get_coap_int
|
||||
|
||||
def output (self) :
|
||||
sys.stdout.write (self.ihex.tobinstr ())
|
||||
# end def output
|
||||
|
||||
# end class Upload_Info
|
||||
|
||||
ui = Upload_Info (sys.argv [1], sys.argv [2])
|
||||
ui.read_hex ()
|
||||
ui.output ()
|
87
examples/osd/ota-update/res_bootloader.c
Normal file
87
examples/osd/ota-update/res_bootloader.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Ralf Schlatterbeck Open Source Consulting
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Bootloader ressources
|
||||
* \author
|
||||
* Ralf Schlatterbeck <rsc@runtux.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "rest-engine.h"
|
||||
#include "er-coap-engine.h"
|
||||
#include "uiplib.h"
|
||||
#include "generic_resource.h"
|
||||
#include "bootloader_if.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
/*
|
||||
* Resources to be activated need to be imported through the extern keyword.
|
||||
* The build system automatically compiles the resources in the
|
||||
* corresponding sub-directory.
|
||||
*/
|
||||
|
||||
static size_t
|
||||
part_count (const char *name, const char *uri, char *buf, size_t bsize)
|
||||
{
|
||||
return snprintf (buf, bsize, "%ld", bootloader_get_part_count ());
|
||||
}
|
||||
|
||||
GENERIC_RESOURCE
|
||||
( part_count
|
||||
, Partition Count
|
||||
, count
|
||||
, 0
|
||||
, NULL
|
||||
, part_count
|
||||
);
|
||||
|
||||
static size_t
|
||||
part_size (const char *name, const char *uri, char *buf, size_t bsize)
|
||||
{
|
||||
return snprintf (buf, bsize, "%ld", bootloader_get_part_size ());
|
||||
}
|
||||
|
||||
GENERIC_RESOURCE
|
||||
( part_size
|
||||
, Partition Size
|
||||
, count
|
||||
, 0
|
||||
, NULL
|
||||
, part_size
|
||||
);
|
||||
|
|
@ -57,8 +57,6 @@
|
|||
#define PRINTF(x)
|
||||
#endif
|
||||
|
||||
static const uint32_t partition_start = 0x1ef00; //bootloader_get_part_start ();
|
||||
static const uint32_t partition_size = 5000; //bootloader_get_part_size ();
|
||||
|
||||
// We allocate this statically, otherwise we cannot flash a new image
|
||||
// when ram is exhausted!
|
||||
|
@ -73,6 +71,8 @@ res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferr
|
|||
uint8_t *in_data = NULL;
|
||||
size_t len = 0;
|
||||
uint8_t sreg = SREG;
|
||||
const uint32_t partition_start = bootloader_get_part_start (1);
|
||||
const uint32_t partition_size = bootloader_get_part_size ();
|
||||
|
||||
unsigned int ct = -1;
|
||||
|
||||
|
|
|
@ -80,9 +80,39 @@ AVRDUDE_MCU=m256rfr2
|
|||
# section: guhRF Bootloader MAC Address
|
||||
BOOTLOADER_GET_MAC=0x0003ff80
|
||||
BOOTLOADER_WRITE_PAGE_TO_FLASH=0x0003ff84
|
||||
BOOTLOADER_GET_PART_COUNT=0x0003ff88
|
||||
BOOTLOADER_GET_PART_SIZE=0x0003ff8c
|
||||
BOOTLOADER_GET_PART_START=0x0003ff90
|
||||
BOOTLOADER_SET_PART_OK=0x0003ff94
|
||||
BOOTLOADER_CLR_PART_OK=0x0003ff98
|
||||
BOOTLOADER_SET_BOOT_DEFAULT=0x0003ff9c
|
||||
BOOTLOADER_SET_BOOT_NEXT=0x0003ffa0
|
||||
BOOTLOADER_BACKUP_IRQ_TABLE=0x0003ffa4
|
||||
BOOTLOADER_GET_BOOT_DEFAULT=0x0003ffa8
|
||||
BOOTLOADER_GET_BOOT_NEXT=0x0003ffac
|
||||
BOOTLOADER_GET_CALLERS_PART=0x0003ffb0
|
||||
BOOTLOADER_PARTITION=0
|
||||
|
||||
ifeq ($(BOOTLOADER_PARTITION),0)
|
||||
TEXT_SECTION_START=0x0
|
||||
else
|
||||
TEXT_SECTION_START=0x1ef00
|
||||
endif
|
||||
|
||||
LDFLAGS += -Wl,--defsym,bootloader_get_mac=$(BOOTLOADER_GET_MAC) \
|
||||
-Wl,--defsym,bootloader_write_page_to_flash=$(BOOTLOADER_WRITE_PAGE_TO_FLASH)
|
||||
-Wl,--defsym,bootloader_write_page_to_flash=$(BOOTLOADER_WRITE_PAGE_TO_FLASH) \
|
||||
-Wl,--defsym,bootloader_get_part_count=$(BOOTLOADER_GET_PART_COUNT) \
|
||||
-Wl,--defsym,bootloader_get_part_size=$(BOOTLOADER_GET_PART_SIZE) \
|
||||
-Wl,--defsym,bootloader_get_part_start=$(BOOTLOADER_GET_PART_START) \
|
||||
-Wl,--defsym,bootloader_set_part_ok=$(BOOTLOADER_SET_PART_OK) \
|
||||
-Wl,--defsym,bootloader_clr_part_ok=$(BOOTLOADER_CLR_PART_OK) \
|
||||
-Wl,--defsym,bootloader_set_boot_default=$(BOOTLOADER_SET_BOOT_DEFAULT) \
|
||||
-Wl,--defsym,bootloader_set_boot_next=$(BOOTLOADER_SET_BOOT_NEXT) \
|
||||
-Wl,--defsym,bootloader_backup_irq_table=$(BOOTLOADER_BACKUP_IRQ_TABLE) \
|
||||
-Wl,--defsym,bootloader_get_boot_default=$(BOOTLOADER_GET_BOOT_DEFAULT) \
|
||||
-Wl,--defsym,bootloader_get_boot_next=$(BOOTLOADER_GET_BOOT_NEXT) \
|
||||
-Wl,--defsym,bootloader_get_callers_part=$(BOOTLOADER_GET_CALLERS_PART) \
|
||||
-Wl,--section-start=.text=$(TEXT_SECTION_START)
|
||||
|
||||
|
||||
include $(CONTIKIAVR)/Makefile.avr
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
#ifndef BOOTLOADER_IF_H_
|
||||
#define BOOTLOADER_IF_H_
|
||||
|
||||
extern uint8_t bootloader_get_mac(uint8_t);
|
||||
extern int bootloader_write_page_to_flash
|
||||
extern int bootloader_write_page_to_flash
|
||||
(uint32_t address, unsigned int size, unsigned char *p);
|
||||
|
||||
extern uint8_t bootloader_get_mac (uint8_t);
|
||||
extern uint32_t bootloader_get_part_count (void);
|
||||
extern uint32_t bootloader_get_part_size (void);
|
||||
extern uint32_t bootloader_get_part_start (uint32_t part_index);
|
||||
extern void bootloader_set_part_ok (uint32_t part_index);
|
||||
extern void bootloader_clr_part_ok (uint32_t part_index);
|
||||
extern void bootloader_set_boot_default (uint32_t part_index);
|
||||
extern void bootloader_set_boot_next (uint32_t part_index);
|
||||
extern void bootloader_backup_irq_table (uint32_t part_index);
|
||||
extern uint32_t bootloader_get_boot_default (void);
|
||||
extern uint32_t bootloader_get_boot_next (void);
|
||||
extern uint32_t bootloader_get_callers_part (void);
|
||||
|
||||
#endif /* BOOTLOADER_IF_H_ */
|
||||
|
|
Loading…
Reference in a new issue