Functions | Variables

projects/nrfgo_sdk/bootloader_32k/host_applications/bootlu1p_linux/flashprog.c File Reference

#include <stdio.h>
#include <string.h>
#include <usb.h>
#include "bootldr_usb_cmds.h"
#include "flashprog.h"

Go to the source code of this file.

Functions

int flash_prog (usb_dev_handle *hdev, unsigned low_addr, unsigned high_addr, unsigned flash_size, unsigned char *hex_buf)

Variables

const int BULK_OUT_EP = 0x01
const int BULK_IN_EP = 0x81

Function Documentation

int flash_prog ( usb_dev_handle *  hdev,
unsigned  low_addr,
unsigned  high_addr,
unsigned  flash_size,
unsigned char *  hex_buf 
)

Definition at line 98 of file flashprog.c.

{
    unsigned num_flash_pages = flash_size/FLASH_PAGE_SIZE;
    fprintf(stdout, "Programming flash pages 1-%d...\n", num_flash_pages - 5);
    //
    // First program and verify the flash pages above page 0 and below the bootloader
    // (last four pages of the flash):
    flash_program(hdev, hex_buf, 1, num_flash_pages - 5);
    fprintf(stdout, "Verifying flash pages 1-%d...\n", num_flash_pages - 5);
    if (flash_verify(hdev, hex_buf, 1, num_flash_pages - 5) == 0)
    {
        return 0;
    }
    //
    // Then program page 0 and the pages containing the bootloader:
    fprintf(stdout, "Programming flash page 0...\n", num_flash_pages - 5);
    flash_program(hdev, hex_buf, 0, 1);
    if (high_addr > (num_flash_pages - 4)*FLASH_PAGE_SIZE)
    {
        // Only program pages containing bootloader if user program uses these pages
        fprintf(stdout, "Programming flash pages %d-%d...\n", num_flash_pages - 4, num_flash_pages - 1);
        flash_program(hdev, hex_buf, num_flash_pages - 4, 4);
    }
    fprintf(stdout, "Verifying flash page 0...\n", num_flash_pages - 5);
    if (flash_verify(hdev, hex_buf, 0, 1) == 0)
        return 0;
    if (high_addr > (num_flash_pages - 4)*FLASH_PAGE_SIZE)
    {
        fprintf(stdout, "Verifying flash pages %d-%d...\n", num_flash_pages - 4, num_flash_pages - 1);
        if(flash_verify(hdev, hex_buf, num_flash_pages - 4, 4) == 0)
        {
            return 0;
        }
    }
    return 1;
}

Variable Documentation

const int BULK_OUT_EP = 0x01

Definition at line 18 of file flashprog.c.

const int BULK_IN_EP = 0x81

Definition at line 19 of file flashprog.c.