12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /*====================================================================*
- *
- * Copyright (c) 2013 Qualcomm Atheros, Inc.
- *
- * All rights reserved.
- *
- *====================================================================*/
- /*====================================================================*
- *
- * int sdramfile (int fd, char const * filename, flag_t flags);
- *
- * sdram.h
- *
- * open an SDRAM configuration file and validate it by checking the
- * file length; unfortunately there are not many things to check;
- *
- * Contributor(s):
- * Charles Maier <cmaier@qca.qualcomm.com>
- *
- *--------------------------------------------------------------------*/
- #ifndef SDRAMFILE_SOURCE
- #define SDRAMFILE_SOURCE
- #include <unistd.h>
- #include <memory.h>
- #include <fcntl.h>
- #include <errno.h>
- #include "../ram/sdram.h"
- #include "../tools/memory.h"
- #include "../tools/error.h"
- #include "../tools/flags.h"
- int sdramfile (int fd, char const * filename, flag_t flags)
- {
- uint32_t checksum;
- struct config_ram config_ram;
- memset (& config_ram, 0, sizeof (config_ram));
- if (lseek (fd, 0, SEEK_SET) == - 1)
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Can't rewind file: %s", filename);
- }
- return (- 1);
- }
- if (read (fd, & config_ram, sizeof (config_ram)) != sizeof (config_ram))
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Wrong file size: %s", filename);
- }
- return (- 1);
- }
- if (read (fd, & checksum, sizeof (checksum)) != sizeof (checksum))
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Can't read checksum: %s", filename);
- }
- return (- 1);
- }
- if (checksum32 (& config_ram, sizeof (config_ram), checksum))
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, 0, "Bad checksum: %s", filename);
- }
- return (- 1);
- }
- if (lseek (fd, 0, SEEK_SET) == - 1)
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Can't rewind file: %s", filename);
- }
- return (- 1);
- }
- return (0);
- }
- #endif
|