OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [powerpc/] [moab/] [current/] [support/] [make_MOAB_flash.c] - Blame information for rev 867

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//
2
// This program reads a binary image and packs it into 
3
// a proper format, suitable for burning into the boot
4
// FLASH device on the MOAB platform.
5
//
6
// CAUTION! - This program is very "hard-wired" to the
7
// current MOAB environment.
8
//
9
 
10
#include <stdio.h>
11
#include <stdlib.h>
12
#include <errno.h>
13
#include <fcntl.h>
14
 
15
#define BOOT_FLASH_SIZE 0x80000
16
unsigned char FLASH_image[BOOT_FLASH_SIZE];
17
unsigned char BRA_0xFFF80100[] = { 0x4B, 0xF8, 0x01, 0x02 };
18
 
19
int main(int argc, char *argv[])
20
{
21
    int raw_fd, packed_fd, raw_len;
22
 
23
    if (argc != 3) {
24
        fprintf(stderr, "Usage: %s <RAW-binary> <PACKED-binary>\n", argv[0]);
25
        exit(1);
26
    }
27
 
28
    if ((raw_fd = open(argv[1], O_RDONLY)) < 0) {
29
        fprintf(stderr, "Can't open RAW file '%s': %s\n", argv[1], strerror(errno));
30
        exit(2);
31
    }
32
    memset(FLASH_image, 0xFF, sizeof(FLASH_image));
33
    if ((raw_len = read(raw_fd, FLASH_image, sizeof(FLASH_image))) < 0) {
34
        fprintf(stderr, "Can't read RAW file '%s': %s\n", argv[1], strerror(errno));
35
        exit(2);
36
    }
37
    memcpy(&FLASH_image[BOOT_FLASH_SIZE-4], BRA_0xFFF80100, sizeof(BRA_0xFFF80100));
38
    close(raw_fd);
39
 
40
    if ((packed_fd = open(argv[2], O_RDWR | O_CREAT, 0666)) < 0) {
41
        fprintf(stderr, "Can't create '%s': %s\n", argv[2], strerror(errno));
42
        exit(3);
43
    }
44
    if (write(packed_fd, FLASH_image, sizeof(FLASH_image)) != sizeof(FLASH_image)) {
45
        fprintf(stderr, "Can't write '%s': %s\n", argv[2], strerror(errno));
46
        exit(3);
47
    }
48
    close(packed_fd);
49
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.