Merge branch 'master' of /home/wd/git/u-boot/custodians

* 'master' of /home/wd/git/u-boot/custodians:
  lzma: fix printf warnings
  Remove CONFIG_SYS_EXTBDINFO from snapper9260.h
  cmd_pxe.c: fix strict-aliasing warnings
  net: smc91111: use mdelay()
  doc: Fix some typos in different files
  disk/part.c: Fix device enumeration through API
  mkenvimage: Really set the redundant byte when applicable
  mkenvimage: Don't try to detect comments in the input file
  mkenvimage: Use mmap() when reading from a regular file
  mkenvimage: Read/Write from/to stdin/out by default or if the filename is "-"
  mkenvimage: More error handling
  mkenvimage: Correct an include and add a missing one
  mkenvimage: correct and clarify comments and error messages
  MAKEALL: display SPL size if present
  ARMV7/Vexpress: add missing get_ticks() and get_tbclk()
  mkenvimage: fix usage message
  cmd_fat: add FAT write command
  fs/fat/fat_write.c: Fix GCC 4.6 warnings
  FAT write: Fix compile errors
This commit is contained in:
Wolfgang Denk 2012-03-30 20:17:11 +02:00
commit 7373323056
28 changed files with 210 additions and 132 deletions

View File

@ -511,8 +511,12 @@ build_target() {
TOTAL_CNT=$((TOTAL_CNT + 1))
${CROSS_COMPILE}size ${BUILD_DIR}/u-boot \
| tee -a ${LOG_DIR}/$target.MAKELOG
OBJS=${BUILD_DIR}/u-boot
if [ -e ${BUILD_DIR}/spl/u-boot-spl ]; then
OBJS="${OBJS} ${BUILD_DIR}/spl/u-boot-spl"
fi
${CROSS_COMPILE}size ${OBJS} | tee -a ${LOG_DIR}/$target.MAKELOG
}
build_targets() {
for t in "$@" ; do

8
README
View File

@ -1236,8 +1236,12 @@ The following options need to be configured:
- FAT(File Allocation Table) filesystem write function support:
CONFIG_FAT_WRITE
Support for saving memory data as a file
in FAT formatted partition
Define this to enable support for saving memory data as a
file in FAT formatted partition.
This will also enable the command "fatwrite" enabling the
user to write files to FAT.
- Keyboard Support:
CONFIG_ISA_KEYBOARD

View File

@ -226,3 +226,13 @@ void lowlevel_init(void)
ulong get_board_rev(void){
return readl((u32 *)SYS_ID);
}
unsigned long long get_ticks(void)
{
return get_timer(0);
}
ulong get_tbclk (void)
{
return (ulong)CONFIG_SYS_HZ;
}

View File

@ -184,3 +184,60 @@ U_BOOT_CMD(
"<interface> <dev[:part]>\n"
" - print information about filesystem from 'dev' on 'interface'"
);
#ifdef CONFIG_FAT_WRITE
static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
long size;
unsigned long addr;
unsigned long count;
block_dev_desc_t *dev_desc = NULL;
int dev = 0;
int part = 1;
char *ep;
if (argc < 5)
return cmd_usage(cmdtp);
dev = (int)simple_strtoul(argv[2], &ep, 16);
dev_desc = get_dev(argv[1], dev);
if (dev_desc == NULL) {
puts("\n** Invalid boot device **\n");
return 1;
}
if (*ep) {
if (*ep != ':') {
puts("\n** Invalid boot device, use `dev[:part]' **\n");
return 1;
}
part = (int)simple_strtoul(++ep, NULL, 16);
}
if (fat_register_device(dev_desc, part) != 0) {
printf("\n** Unable to use %s %d:%d for fatwrite **\n",
argv[1], dev, part);
return 1;
}
addr = simple_strtoul(argv[3], NULL, 16);
count = simple_strtoul(argv[5], NULL, 16);
size = file_fat_write(argv[4], (void *)addr, count);
if (size == -1) {
printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
argv[4], argv[1], dev, part);
return 1;
}
printf("%ld bytes written\n", size);
return 0;
}
U_BOOT_CMD(
fatwrite, 6, 0, do_fat_fswrite,
"write file into a dos filesystem",
"<interface> <dev[:part]> <addr> <filename> <bytes>\n"
" - write file 'filename' from the address 'addr' in RAM\n"
" to 'dev' on 'interface'"
);
#endif

View File

@ -318,7 +318,7 @@ static int
do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *pxefile_addr_str;
void *pxefile_addr_r;
unsigned long pxefile_addr_r;
int err;
if (argc != 1)
@ -339,10 +339,10 @@ do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* Keep trying paths until we successfully get a file we're looking
* for.
*/
if (pxe_uuid_path(pxefile_addr_r) > 0
|| pxe_mac_path(pxefile_addr_r) > 0
|| pxe_ipaddr_paths(pxefile_addr_r) > 0
|| get_pxelinux_path("default", pxefile_addr_r) > 0) {
if (pxe_uuid_path((void *)pxefile_addr_r) > 0
|| pxe_mac_path((void *)pxefile_addr_r) > 0
|| pxe_ipaddr_paths((void *)pxefile_addr_r) > 0
|| get_pxelinux_path("default", (void *)pxefile_addr_r) > 0) {
printf("Config file found\n");
@ -363,7 +363,7 @@ do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
*/
static int get_relfile_envaddr(char *file_path, char *envaddr_name)
{
void *file_addr;
unsigned long file_addr;
char *envaddr;
envaddr = from_env(envaddr_name);
@ -371,10 +371,10 @@ static int get_relfile_envaddr(char *file_path, char *envaddr_name)
if (!envaddr)
return -ENOENT;
if (strict_strtoul(envaddr, 16, (unsigned long *)&file_addr) < 0)
if (strict_strtoul(envaddr, 16, &file_addr) < 0)
return -EINVAL;
return get_relfile(file_path, file_addr);
return get_relfile(file_path, (void *)file_addr);
}
/*

View File

@ -80,6 +80,9 @@ block_dev_desc_t *get_dev(char* ifname, int dev)
block_dev_desc_t* (*reloc_get_dev)(int dev);
char *name;
if (!ifname)
return NULL;
name = drvr->name;
#ifdef CONFIG_NEEDS_MANUAL_RELOC
name += gd->reloc_off;

View File

@ -91,7 +91,7 @@ of the flags are the same on all implementations.
PORTMUX_DIR_OUTPUT
PORTMUX_DIR_INPUT
These mutually-exlusive flags configure the initial direction of the
These mutually-exclusive flags configure the initial direction of the
pins. PORTMUX_DIR_OUTPUT means that the pins are driven by the CPU,
while PORTMUX_DIR_INPUT means that the pins are tristated by the CPU.
These flags are ignored by portmux_select_peripheral().
@ -125,7 +125,7 @@ PORTMUX_PULL_UP.
PORTMUX_DRIVE_HIGH
PORTMUX_DRIVE_MAX
These mutually-exlusive flags determine the drive strength of the
These mutually-exclusive flags determine the drive strength of the
pins. PORTMUX_DRIVE_MIN will give low power-consumption, but may cause
corruption of high-speed signals. PORTMUX_DRIVE_MAX will give high
power-consumption, but may be necessary on pins toggling at very high

View File

@ -6,7 +6,7 @@ syncronize RTC of the board. This command needs the command line
parameter of server's IP address or environment variable
"ntpserverip". The network time is sent as UTC. So if you want to
set local time to RTC, set the offset in second from UTC to the
enviroment variable "time offset".
environment variable "time offset".
If the DHCP server provides time server's IP or time offset, you
don't need to set the above environment variables yourself.

View File

@ -236,7 +236,7 @@ PART 10)
=> setenv serverip 192.168.0.10
=> setenv gatewayip=192.168.0.1
=> saveenv
Saving Enviroment to Flash...
Saving Environment to Flash...
Un-Protected 1 sectors
Erasing Flash...
done
@ -296,7 +296,7 @@ Erase Flash Bank # 2 - missing
=> cp.b 0x100000 FFF00000 1f28c
Copy to Flash... done
=> saveenv
Saving Enviroment to Flash...
Saving Environment to Flash...
Un-Protected 1 sectors
Erasing Flash...
done
@ -330,7 +330,7 @@ Erase Flash from 0xfff00000 to 0xfff3ffff
done
Erased 7 sectors
Copy to Flash... done
Saving Enviroment to Flash...
Saving Environment to Flash...
Un-Protected 1 sectors
Erasing Flash...
done

View File

@ -62,16 +62,16 @@ Environment variables
U-Boot environment variables can be stored at different places:
- Dataflash on SPI chip select 0 (dataflash card)
- Nand flash.
- Nor falsh (not populate by default)
- Nor flash (not populate by default)
You can choose your storage location at config step (here for at91sam9260ek) :
make at91sam9263ek_config - use data flash (spi cs0) (default)
make at91sam9263ek_nandflash_config - use nand flash
make at91sam9263ek_dataflash_cs0_config - use data flash (spi cs0)
make at91sam9263ek_norflash_config - use nor falsh
make at91sam9263ek_norflash_config - use nor flash
You can choose to boot directly from U-Boot at config step
make at91sam9263ek_norflash_boot_config - boot from nor falsh
make at91sam9263ek_norflash_boot_config - boot from nor flash
------------------------------------------------------------------------------

View File

@ -4,7 +4,7 @@
=======================================================================
This file contains some handy info regarding U-Boot and the AMCC
Ebony evalutation board. See the README.ppc440 for additional
Ebony evaluation board. See the README.ppc440 for additional
information.

View File

@ -250,7 +250,7 @@ print [c<n>] [d<n>] [spd] [dimmparms] [commonparms] [opts] [addresses] [regs]
c<n> - the controller number, eg. c0, c1
d<n> - the DIMM number, eg. d0, d1
spd - print SPD data
dimmparms - DIMM paramaters, calcualted from SPD
dimmparms - DIMM parameters, calculated from SPD
commonparms - lowest common parameters for all DIMMs
opts - options
addresses - address assignment (not implemented yet)
@ -260,7 +260,7 @@ edit <c#> <d#> <spd|dimmparms|commonparms|opts|addresses|regs> <element> <value>
c<n> - the controller number, eg. c0, c1
d<n> - the DIMM number, eg. d0, d1
spd - print SPD data
dimmparms - DIMM paramaters, calcualted from SPD
dimmparms - DIMM parameters, calculated from SPD
commonparms - lowest common parameters for all DIMMs
opts - options
addresses - address assignment (not implemented yet)

View File

@ -15,7 +15,7 @@ Freescale MPC832XEMDS Board
"On" == 0
SW3 is switch 18 as silk-screened onto the board.
SW4[8] is the bit labled 8 on Switch 4.
SW4[8] is the bit labeled 8 on Switch 4.
SW5[1:6] refers to bits labeled 1 through 6 in order on switch 5.
SW6[7:1] refers to bits labeled 7 through 1 in order on switch 6.
SW7[1:8]= 0000_0001 refers to bits labeled 1 through 6 is set as "On"

View File

@ -15,7 +15,7 @@ Freescale MPC8360EMDS Board
"On" == 0
SW18 is switch 18 as silk-screened onto the board.
SW4[8] is the bit labled 8 on Switch 4.
SW4[8] is the bit labeled 8 on Switch 4.
SW2[1:6] refers to bits labeled 1 through 6 in order on switch 2.
SW3[7:1] refers to bits labeled 7 through 1 in order on switch 3.
SW3[1:8]= 0000_0001 refers to bits labeled 1 through 6 is set as "On"

View File

@ -14,7 +14,7 @@ Freescale MPC837xEMDS Board
"Off" == 1
"On" == 0
SW4[8] is the bit labled 8 on Switch 4.
SW4[8] is the bit labeled 8 on Switch 4.
SW2[1:6] refers to bits labeled 1 through 6 in order on switch 2.
SW2[1:8]= 0000_0001 refers to bits labeled 1 through 7 is set as "On"
and bits labeled 8 is set as "Off".

View File

@ -22,7 +22,7 @@ boot bank at 0xfff8_0000.
Memory Map
----------
0xff80_0000 - 0xffbf_ffff Alernate bank 4MB
0xff80_0000 - 0xffbf_ffff Alternate bank 4MB
0xffc0_0000 - 0xffff_ffff Boot bank 4MB
0xffb8_0000 Alternate image start 512KB

View File

@ -19,7 +19,7 @@ Booting is always from the boot bank at 0xec00_0000.
Memory Map
----------
0xe800_0000 - 0xebff_ffff Alernate bank 64MB
0xe800_0000 - 0xebff_ffff Alternate bank 64MB
0xec00_0000 - 0xefff_ffff Boot bank 64MB
0xebf8_0000 - 0xebff_ffff Alternate u-boot address 512KB
@ -115,7 +115,7 @@ Implementing AMP(Asymmetric MultiProcessing)
- Select "Advanced setup" -> " Prompt for advanced kernel
configuration options"
- Select "Set physical address where the kernel is loaded" and
set it to 0x20000000, asssuming core1 will start from 512MB.
set it to 0x20000000, assuming core1 will start from 512MB.
- Select "Set custom page offset address"
- Select "Set custom kernel base address"
- Select "Set maximum low memory"

View File

@ -35,7 +35,7 @@ Updated 13-July-2004 Jon Loeliger
"On" == 0
SW18 is switch 18 as silk-screened onto the board.
SW4[8] is the bit labled 8 on Switch 4.
SW4[8] is the bit labeled 8 on Switch 4.
SW2[1:6] refers to bits labeled 1 through 6 in order on switch 2
SW3[7:1] refers to bits labeled 7 through 1 in order on switch 3

View File

@ -33,7 +33,7 @@ Matrix Vision mvBlueCOUGAR-P (mvBC-P)
2.4 I2C
LM75 @ 0x90 for temperature monitoring.
EEPROM @ 0xA0 for vendor specifics.
image sensor interface (slave adresses depend on sensor)
image sensor interface (slave addresses depend on sensor)
3 Flash layout.

View File

@ -40,10 +40,10 @@ Matrix Vision mvBlueLYNX-M7 (mvBL-M7)
MAX5381 DAC @ 0x60 for 1st digital input threshold.
LM75 @ 0x90 for temperature monitoring.
EEPROM @ 0xA0 for system setup (HRCW etc.) + vendor specifics.
1st image sensor interface (slave adresses depend on sensor)
1st image sensor interface (slave addresses depend on sensor)
Bus2:
MAX5381 DAC @ 0x60 for 2nd digital input threshold.
2nd image sensor interface (slave adresses depend on sensor)
2nd image sensor interface (slave addresses depend on sensor)
3 Flash layout.

View File

@ -23,7 +23,7 @@ Matrix Vision mvSMR
2.4 I2C
EEPROM @ 0xA0 for vendor specifics.
image sensor interface (slave adresses depend on sensor)
image sensor interface (slave addresses depend on sensor)
3 Flash layout.

View File

@ -4,7 +4,7 @@
=======================================================================
This file contains some handy info regarding U-Boot and the AMCC
Ocotea 440gx evalutation board. See the README.ppc440 for additional
Ocotea 440gx evaluation board. See the README.ppc440 for additional
information.

View File

@ -17,7 +17,7 @@ Booting by default is always from the boot bank at 0xef00_0000.
Memory Map
----------
0xef00_0000 - 0xef7f_ffff Alernate bank 8MB
0xef00_0000 - 0xef7f_ffff Alternate bank 8MB
0xe800_0000 - 0xefff_ffff Boot bank 8MB
0xef78_0000 - 0xef7f_ffff Alternate u-boot address 512KB
@ -89,7 +89,7 @@ Implementing AMP(Asymmetric MultiProcessing)
"Prompt for advanced kernel configuration options"
- Select
"Set physical address where the kernel is loaded"
and set it to 0x20000000, asssuming core1 will
and set it to 0x20000000, assuming core1 will
start from 512MB.
- Select "Set custom page offset address"
- Select "Set custom kernel base address"

View File

@ -1168,17 +1168,6 @@ static void smc_write_phy_register (struct eth_device *dev, byte phyreg,
#endif /* !CONFIG_SMC91111_EXT_PHY */
/*------------------------------------------------------------
. Waits the specified number of milliseconds - kernel friendly
.-------------------------------------------------------------*/
#ifndef CONFIG_SMC91111_EXT_PHY
static void smc_wait_ms(unsigned int ms)
{
udelay(ms*1000);
}
#endif /* !CONFIG_SMC91111_EXT_PHY */
/*------------------------------------------------------------
. Configures the specified PHY using Autonegotiation. Calls
. smc_phy_fixed() if the user has requested a certain config.
@ -1205,7 +1194,7 @@ static void smc_phy_configure (struct eth_device *dev)
break;
}
smc_wait_ms (500); /* wait 500 millisecs */
mdelay(500); /* wait 500 millisecs */
}
if (timeout < 1) {
@ -1270,7 +1259,7 @@ static void smc_phy_configure (struct eth_device *dev)
break;
}
smc_wait_ms (500); /* wait 500 millisecs */
mdelay(500); /* wait 500 millisecs */
/* Restart auto-negotiation if remote fault */
if (status & PHY_STAT_REM_FLT) {

View File

@ -41,23 +41,19 @@ static void uppercase(char *str, int len)
}
static int total_sector;
static int disk_write(__u32 startblock, __u32 getsize, __u8 *bufptr)
static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
{
if (cur_dev == NULL)
if (!cur_dev || !cur_dev->block_write)
return -1;
if (startblock + getsize > total_sector) {
if (cur_part_info.start + block + nr_blocks >
cur_part_info.start + total_sector) {
printf("error: overflow occurs\n");
return -1;
}
startblock += part_offset;
if (cur_dev->block_read) {
return cur_dev->block_write(cur_dev->dev, startblock, getsize,
(unsigned long *) bufptr);
}
return -1;
return cur_dev->block_write(cur_dev->dev,
cur_part_info.start + block, nr_blocks, buf);
}
/*
@ -797,7 +793,7 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, unsigned long size)
if (size % mydata->sect_size)
sect_num++;
if (startsect + sect_num > total_sector)
if (startsect + sect_num > cur_part_info.start + total_sector)
return -1;
return 0;
@ -827,7 +823,6 @@ static dir_entry *empty_dentptr;
static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
char *filename, dir_entry *retdent, __u32 start)
{
__u16 prevcksum = 0xffff;
__u32 curclust = (startsect - mydata->data_begin) / mydata->clust_size;
debug("get_dentfromdir: %s\n", filename);
@ -861,8 +856,6 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
#ifdef CONFIG_SUPPORT_VFAT
if ((dentptr->attr & ATTR_VFAT) &&
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
prevcksum =
((dir_slot *)dentptr)->alias_checksum;
get_long_file_name(mydata, curclust,
get_dentfromdir_block,
&dentptr, l_name);
@ -926,7 +919,6 @@ static int do_fat_write(const char *filename, void *buffer,
unsigned long size)
{
dir_entry *dentptr, *retdent;
dir_slot *slotptr;
__u32 startsect;
__u32 start_cluster;
boot_sector bs;
@ -934,7 +926,7 @@ static int do_fat_write(const char *filename, void *buffer,
fsdata datablock;
fsdata *mydata = &datablock;
int cursect;
int root_cluster, ret = -1, name_len;
int ret = -1, name_len;
char l_filename[VFAT_MAXLEN_BYTES];
int write_size = size;
@ -947,9 +939,7 @@ static int do_fat_write(const char *filename, void *buffer,
total_sector = bs.total_sect;
if (total_sector == 0)
total_sector = part_size;
root_cluster = bs.root_cluster;
total_sector = cur_part_info.size;
if (mydata->fatsize == 32)
mydata->fatlength = bs.fat32_length;
@ -1051,8 +1041,6 @@ static int do_fat_write(const char *filename, void *buffer,
goto exit;
}
} else {
slotptr = (dir_slot *)empty_dentptr;
/* Set short name to set alias checksum field in dir_slot */
set_name(empty_dentptr, filename);
fill_dir_slot(mydata, &empty_dentptr, filename);

View File

@ -157,7 +157,6 @@
#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \
sizeof(CONFIG_SYS_PROMPT) + 16)
#define CONFIG_SYS_LONGHELP
#define CONFIG_SYS_EXTBDINFO
#define CONFIG_CMDLINE_EDITING
#define CONFIG_AUTO_COMPLETE
#define CONFIG_SYS_HUSH_PARSER

View File

@ -107,8 +107,8 @@ int lzmaBuffToBuffDecompress (unsigned char *outStream, SizeT *uncompressedSize,
}
}
debug ("LZMA: Uncompresed size............ 0x%x\n", outSizeFull);
debug ("LZMA: Compresed size.............. 0x%x\n", compressedSize);
debug("LZMA: Uncompresed size............ 0x%zx\n", outSizeFull);
debug("LZMA: Compresed size.............. 0x%zx\n", compressedSize);
g_Alloc.Alloc = SzAlloc;
g_Alloc.Free = SzFree;

View File

@ -31,13 +31,15 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <compiler.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "compiler.h"
#include <u-boot/crc.h>
#include <version.h>
@ -45,12 +47,9 @@
static void usage(const char *exec_name)
{
fprintf(stderr, "%s [-h] [-r] [-b] [-p <byte>] "
"-s <environment partition size> -o <output> <input file>\n"
fprintf(stderr, "%s [-h] [-r] [-b] [-p <byte>] -s <environment partition size> -o <output> <input file>\n"
"\n"
"This tool takes a key=value input file (same as would a "
"`printenv' show) and generates the corresponding environment "
"image, ready to be flashed.\n"
"This tool takes a key=value input file (same as would a `printenv' show) and generates the corresponding environment image, ready to be flashed.\n"
"\n"
"\tThe input file is in format:\n"
"\t\tkey1=value1\n"
@ -58,14 +57,31 @@ static void usage(const char *exec_name)
"\t\t...\n"
"\t-r : the environment has multiple copies in flash\n"
"\t-b : the target is big endian (default is little endian)\n"
"\t-p <byte> : fill the image with <byte> bytes instead of "
"0xff bytes\n"
"\t-p <byte> : fill the image with <byte> bytes instead of 0xff bytes\n"
"\t-V : print version information and exit\n"
"\n"
"If the input file is \"-\", data is read from standard input\n",
exec_name);
}
long int xstrtol(const char *s)
{
long int tmp;
errno = 0;
tmp = strtol(s, NULL, 0);
if (!errno)
return tmp;
if (errno == ERANGE)
fprintf(stderr, "Bad integer format: %s\n", s);
else
fprintf(stderr, "Error while parsing %s: %s\n", s,
strerror(errno));
exit(EXIT_FAILURE);
}
int main(int argc, char **argv)
{
uint32_t crc, targetendian_crc;
@ -95,13 +111,12 @@ int main(int argc, char **argv)
while ((option = getopt(argc, argv, ":s:o:rbp:hV")) != -1) {
switch (option) {
case 's':
datasize = strtol(optarg, NULL, 0);
datasize = xstrtol(optarg);
break;
case 'o':
bin_filename = strdup(optarg);
if (!bin_filename) {
fprintf(stderr, "Can't strdup() the output "
"filename\n");
fprintf(stderr, "Can't strdup() the output filename\n");
return EXIT_FAILURE;
}
break;
@ -112,7 +127,7 @@ int main(int argc, char **argv)
bigendian = 1;
break;
case 'p':
padbyte = strtol(optarg, NULL, 0);
padbyte = xstrtol(optarg);
break;
case 'h':
usage(prg);
@ -123,7 +138,7 @@ int main(int argc, char **argv)
case ':':
fprintf(stderr, "Missing argument for option -%c\n",
optopt);
usage(argv[0]);
usage(prg);
return EXIT_FAILURE;
default:
fprintf(stderr, "Wrong option -%c\n", optopt);
@ -134,22 +149,21 @@ int main(int argc, char **argv)
/* Check datasize and allocate the data */
if (datasize == 0) {
fprintf(stderr,
"Please specify the size of the environment "
"partition.\n");
fprintf(stderr, "Please specify the size of the environment partition.\n");
usage(prg);
return EXIT_FAILURE;
}
dataptr = malloc(datasize * sizeof(*dataptr));
if (!dataptr) {
fprintf(stderr, "Can't alloc dataptr.\n");
fprintf(stderr, "Can't alloc %d bytes for dataptr.\n",
datasize);
return EXIT_FAILURE;
}
/*
* envptr points to the beginning of the actual environment (after the
* crc and possible `redundant' bit
* crc and possible `redundant' byte
*/
envsize = datasize - (CRC_SIZE + redundant);
envptr = dataptr + CRC_SIZE + redundant;
@ -158,24 +172,28 @@ int main(int argc, char **argv)
memset(envptr, padbyte, envsize);
/* Open the input file ... */
if (optind >= argc) {
fprintf(stderr, "Please specify an input filename\n");
return EXIT_FAILURE;
}
txt_filename = argv[optind];
if (strcmp(txt_filename, "-") == 0) {
if (optind >= argc || strcmp(argv[optind], "-") == 0) {
int readbytes = 0;
int readlen = sizeof(*envptr) * 2048;
int readlen = sizeof(*envptr) * 4096;
txt_fd = STDIN_FILENO;
do {
filebuf = realloc(filebuf, readlen);
if (!filebuf) {
fprintf(stderr, "Can't realloc memory for the input file buffer\n");
return EXIT_FAILURE;
}
readbytes = read(txt_fd, filebuf + filesize, readlen);
if (errno) {
fprintf(stderr, "Error while reading stdin: %s\n",
strerror(errno));
return EXIT_FAILURE;
}
filesize += readbytes;
} while (readbytes == readlen);
} else {
txt_filename = argv[optind];
txt_fd = open(txt_filename, O_RDONLY);
if (txt_fd == -1) {
fprintf(stderr, "Can't open \"%s\": %s\n",
@ -185,28 +203,36 @@ int main(int argc, char **argv)
/* ... and check it */
ret = fstat(txt_fd, &txt_file_stat);
if (ret == -1) {
fprintf(stderr, "Can't stat() on \"%s\": "
"%s\n", txt_filename, strerror(errno));
fprintf(stderr, "Can't stat() on \"%s\": %s\n",
txt_filename, strerror(errno));
return EXIT_FAILURE;
}
filesize = txt_file_stat.st_size;
/* Read the raw input file and transform it */
filebuf = malloc(sizeof(*envptr) * filesize);
ret = read(txt_fd, filebuf, sizeof(*envptr) * filesize);
if (ret != sizeof(*envptr) * filesize) {
fprintf(stderr, "Can't read the whole input file\n");
return EXIT_FAILURE;
filebuf = mmap(NULL, sizeof(*envptr) * filesize, PROT_READ,
MAP_PRIVATE, txt_fd, 0);
if (filebuf == MAP_FAILED) {
fprintf(stderr, "mmap (%ld bytes) failed: %s\n",
sizeof(*envptr) * filesize,
strerror(errno));
fprintf(stderr, "Falling back to read()\n");
filebuf = malloc(sizeof(*envptr) * filesize);
ret = read(txt_fd, filebuf, sizeof(*envptr) * filesize);
if (ret != sizeof(*envptr) * filesize) {
fprintf(stderr, "Can't read the whole input file (%ld bytes): %s\n",
sizeof(*envptr) * filesize,
strerror(errno));
return EXIT_FAILURE;
}
}
ret = close(txt_fd);
}
/*
* The right test to do is "=>" (not ">") because of the additional
* ending \0. See below.
*/
if (filesize >= envsize) {
fprintf(stderr, "The input file is larger than the "
"environment partition size\n");
/* The +1 is for the additionnal ending \0. See below. */
if (filesize + 1 > envsize) {
fprintf(stderr, "The input file is larger than the environment partition size\n");
return EXIT_FAILURE;
}
@ -232,14 +258,6 @@ int main(int argc, char **argv)
/* End of a variable */
envptr[ep++] = '\0';
}
} else if (filebuf[fp] == '#') {
if (fp != 0 && filebuf[fp-1] == '\n') {
/* This line is a comment, let's skip it */
while (fp < txt_file_stat.st_size && fp++ &&
filebuf[fp] != '\n');
} else {
envptr[ep++] = filebuf[fp];
}
} else {
envptr[ep++] = filebuf[fp];
}
@ -255,8 +273,7 @@ int main(int argc, char **argv)
* check the env size again to make sure we have room for two \0
*/
if (ep >= envsize) {
fprintf(stderr, "The environment file is too large for "
"the target environment storage\n");
fprintf(stderr, "The environment file is too large for the target environment storage\n");
return EXIT_FAILURE;
}
envptr[ep] = '\0';
@ -268,13 +285,20 @@ int main(int argc, char **argv)
crc = crc32(0, envptr, envsize);
targetendian_crc = bigendian ? cpu_to_be32(crc) : cpu_to_le32(crc);
memcpy(dataptr, &targetendian_crc, sizeof(uint32_t));
memcpy(dataptr, &targetendian_crc, sizeof(targetendian_crc));
if (redundant)
dataptr[sizeof(targetendian_crc)] = 1;
bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (bin_fd == -1) {
fprintf(stderr, "Can't open output file \"%s\": %s\n",
bin_filename, strerror(errno));
return EXIT_FAILURE;
if (!bin_filename || strcmp(bin_filename, "-") == 0) {
bin_fd = STDOUT_FILENO;
} else {
bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP |
S_IWGRP);
if (bin_fd == -1) {
fprintf(stderr, "Can't open output file \"%s\": %s\n",
bin_filename, strerror(errno));
return EXIT_FAILURE;
}
}
if (write(bin_fd, dataptr, sizeof(*dataptr) * datasize) !=