barebox/scripts/mkublheader.c
Lucas Stach 603ba8c1ba scripts: fix warning generated by glibc 2.20
Defining only _BSD_SOURCE is deprecated with version 2.20 of
glibc. It has been replaced by _DEFAULT_SOURCE. The manpage says
that code which wants to work in the same way on both old and new
versions of glibc should simply define both symbols.

Also move the definition up in fix_size as those feature flags
should be defined before including any standard headers.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-02 07:32:01 +01:00

101 lines
2.5 KiB
C

/*
* mkublheader.c - produce the header needed to load barebox on OMAP-L138
*
* Copyright (C) 2012 Jan Luebbe <j.luebbe@pengutronix.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _BSD_SOURCE
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <endian.h>
#define MAGICNUM 0xa1aced00
struct ubl_header
{
uint32_t magicNum; /* Expected magic number */
uint32_t epAddr; /* Entry point of the user application */
uint32_t imgSize; /* Number of bytes of the application image */
uint32_t imgAddr; /* SPI memory offset where application image is located */
uint32_t ldAddr; /* Address where image is copied to */
};
void usage(char *prgname)
{
printf( "Usage : %s [OPTION] FILE > HEADER\n"
"\n"
"options:\n"
" -a <address> image flash address\n"
" -e <address> entry point memory address\n"
" -l <address> load memory address\n",
prgname);
}
int main(int argc, char *argv[])
{
struct stat sb;
struct ubl_header uh;
int opt;
uint32_t imgAddr = 0x00040000 + sizeof(uh);
uint32_t epAddr = 0xc1080000, ldAddr = 0xc1080000;
while((opt = getopt(argc, argv, "ael:")) != -1) {
switch (opt) {
case 'a':
imgAddr = strtoul(optarg, NULL, 0);
break;
case 'e':
epAddr = strtoul(optarg, NULL, 0);
break;
case 'l':
ldAddr = strtoul(optarg, NULL, 0);
break;
}
}
if (optind >= argc) {
usage(argv[0]);
exit(1);
}
if (stat(argv[optind], &sb) == -1) {
perror("stat");
exit(EXIT_FAILURE);
}
uh.magicNum = htole32(MAGICNUM);
uh.epAddr = htole32(epAddr);
uh.imgSize = htole32((uint32_t)sb.st_size);
uh.imgAddr = htole32(imgAddr);
uh.ldAddr = htole32(ldAddr);
fwrite(&uh, sizeof(uh), 1, stdout);
exit(EXIT_SUCCESS);
}