Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psin qca7000 v2 #115

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mrgpib: mrgpib.o getoptv.o putoptv.o version.o error.o fdchecksum32.o pibfile1.o
setpib: setpib.o getoptv.o putoptv.o version.o hexpeek.o hexdump.o dataspec.o basespec.o error.o todigit.o uintspec.o bytespec.o pibfile1.o checksum32.o fdchecksum32.o memencode.o nvmseek2.o
setpib1: setpib1.o getoptv.o putoptv.o version.o hexpeek.o hexdump.o dataspec.o basespec.o error.o todigit.o uintspec.o bytespec.o pibfile1.o checksum32.o fdchecksum32.o memencode.o
setpib2: setpib2.o getoptv.o putoptv.o version.o hexpeek.o hexdump.o dataspec.o basespec.o error.o todigit.o uintspec.o bytespec.o pibfile1.o checksum32.o fdchecksum32.o memencode.o
psin: psin.o getoptv.o putoptv.o version.o hexdecode.o hexstring.o todigit.o error.o pibfile1.o piblock.o pibscalers.o fdchecksum32.o
psin: psin.o getoptv.o putoptv.o version.o hexdecode.o hexstring.o todigit.o error.o pibfile.o pibfile1.o pibfile2.o piblock.o pibscalers.o fdchecksum32.o checksum32.o
pskey: pskey.o getoptv.o putoptv.o version.o error.o hexdecode.o hexstring.o hexout.o pibfile1.o SHA256Reset.o SHA256Write.o SHA256Block.o SHA256Fetch.o keys.o fdchecksum32.o
psout: psout.o getoptv.o putoptv.o version.o error.o pibfile.o pibfile1.o pibfile2.o pibscalers.o checksum32.o fdchecksum32.o
psnotch: psnotch.o getoptv.o putoptv.o version.o error.o todigit.o uintspec.o
Expand Down
131 changes: 113 additions & 18 deletions pib/piblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@
*
*--------------------------------------------------------------------*/

/*====================================================================*
*
* signed piblock (struct _file_ const * pib);
*
* recompute and update the checksum on a thunderbolt or lightning
* PIB file where the checksum is located inside the PIB;
*
*
*--------------------------------------------------------------------*/

#ifndef PIBLOCK_SOURCE
#define PIBLOCK_SOURCE
Expand All @@ -58,6 +49,101 @@
#include "../tools/error.h"
#include "../tools/files.h"
#include "../pib/pib.h"
#include "../plc/plc.h"

/*====================================================================*
*
* signed pibchain2 (struct _file_ * file);
*
* recalculates the checksum for a panther / lynx PIB file
*
* Contributor(s):
* Charles Maier
* Christian Aurich
*
*--------------------------------------------------------------------*/

static signed pibchain2 (struct _file_ const * file)

{
unsigned module = 0;
struct nvm_header2 nvm_header;
uint32_t prev = ~0;
uint32_t next = 0;
if (lseek (file->file, 0, SEEK_SET))
{
error (1, errno, NVM_IMG_CHECKSUM, file->name, module);
}
do
{
if (read (file->file, &nvm_header, sizeof (nvm_header)) != sizeof (nvm_header))
{
error (1, errno, NVM_HDR_CANTREAD, file->name, module);
}
if (LE16TOH (nvm_header.MajorVersion) != 1)
{
error (1, errno, NVM_HDR_VERSION, file->name, module);
}
if (LE16TOH (nvm_header.MinorVersion) != 1)
{
error (1, errno, NVM_HDR_VERSION, file->name, module);
}
if (checksum32 (&nvm_header, sizeof (nvm_header), 0))
{
error (1, errno, NVM_HDR_CHECKSUM, file->name, module);
}
if (LE32TOH (nvm_header.PrevHeader) != prev)
{
error (1, errno, NVM_HDR_LINK, file->name, module);
}
if (LE32TOH (nvm_header.ImageType) == NVM_IMAGE_PIB)
{
nvm_header.ImageChecksum = fdchecksum32 (file->file, LE32TOH (nvm_header.ImageLength), 0);
if (lseek (file->file, (off_t)(0) - LE32TOH (nvm_header.ImageLength), SEEK_CUR) == -1)
{
error (1, errno, FILE_CANTHOME, file->name);
}
nvm_header.HeaderChecksum = checksum32 (&nvm_header, sizeof (nvm_header), nvm_header.HeaderChecksum);
if (lseek (file->file, (off_t)(0) - sizeof (nvm_header), SEEK_CUR) == -1)
{
error (1, errno, FILE_CANTHOME, file->name);
}
if (write (file->file, &nvm_header, sizeof (nvm_header)) != sizeof (nvm_header))
{
error (1, errno, FILE_CANTSAVE, file->name);
}
if (lseek (file->file, (off_t)(0) - sizeof (nvm_header), SEEK_CUR) == -1)
{
error (1, errno, FILE_CANTHOME, file->name);
}
break;
}
if (fdchecksum32 (file->file, LE32TOH (nvm_header.ImageLength), nvm_header.ImageChecksum))
{
error (1, errno, NVM_IMG_CHECKSUM, file->name, module);
}
prev = next;
next = LE32TOH (nvm_header.NextHeader);
module++;
}
while (~nvm_header.NextHeader);
return (0);
}

/*====================================================================*
*
* signed piblock (struct _file_ const * pib);
*
* recompute and update the checksum on a thunderbolt or lightning
* PIB file where the checksum is located inside the PIB;
*
*
* extended to be able to update the checksum for panther/lynx PIB
* files;
*
*
*--------------------------------------------------------------------*/


signed piblock (struct _file_ const * file)

Expand All @@ -75,18 +161,27 @@ signed piblock (struct _file_ const * file)
{
error (1, errno, FILE_CANTHOME, file->name);
}
simple_pib.CHECKSUM = fdchecksum32 (file->file, LE16TOH (simple_pib.PIBLENGTH), simple_pib.CHECKSUM);
if (lseek (file->file, 0, SEEK_SET))
{
error (1, errno, "2 " FILE_CANTHOME, file->name);
}
if (write (file->file, &simple_pib, sizeof (simple_pib)) != sizeof (simple_pib))


if (simple_pib.PIBVERSION == 0x0001 && simple_pib.RESERVED1 == 0x0001)
{
error (1, errno, FILE_CANTSAVE, file->name);
pibchain2(file);
}
if (lseek (file->file, 0, SEEK_SET))
else
{
error (1, errno, FILE_CANTHOME, file->name);
simple_pib.CHECKSUM = fdchecksum32 (file->file, LE16TOH (simple_pib.PIBLENGTH), simple_pib.CHECKSUM);
if (lseek (file->file, 0, SEEK_SET))
{
error (1, errno, "2 " FILE_CANTHOME, file->name);
}
if (write (file->file, &simple_pib, sizeof (simple_pib)) != sizeof (simple_pib))
{
error (1, errno, FILE_CANTSAVE, file->name);
}
if (lseek (file->file, 0, SEEK_SET))
{
error (1, errno, FILE_CANTHOME, file->name);
}
}
return (0);
}
Expand Down
29 changes: 24 additions & 5 deletions pib/psin.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@

/*====================================================================*
*
* psin.c - load prescalers into int6000 parameter file;
* psin.c - load prescalers into int6000 and qca7000 parameter file;
*
*
* Contributor(s):
* Charles Maier
* Charles Maier
* Nathaniel Houghton
* Christian Aurich
*
*--------------------------------------------------------------------*/

Expand Down Expand Up @@ -92,7 +93,9 @@
#endif

#ifndef MAKEFILE
#include "../pib/pibfile.c"
#include "../pib/pibfile1.c"
#include "../pib/pibfile2.c"
#include "../pib/piblock.c"
#include "../pib/pibscalers.c"
#endif
Expand Down Expand Up @@ -156,7 +159,7 @@ static signed psin (struct _file_ * pib)
unsigned limit = pibscalers (pib);
uint32_t value = 0;
signed c;
if ((limit != INT_CARRIERS) && (limit != AMP_CARRIERS))
if ((limit != INT_CARRIERS) && (limit != AMP_CARRIERS) && (limit != PLC_CARRIERS))
{
error (1, 0, "Don't understand this PIB's prescaler format");
}
Expand All @@ -167,6 +170,13 @@ static signed psin (struct _file_ * pib)
error (1, errno, FILE_CANTSEEK, pib->name);
}
}
else if (limit == PLC_CARRIERS)
{
if (lseek (pib->file, QCA_PRESCALER_OFFSET, SEEK_SET) != QCA_PRESCALER_OFFSET)
{
error (1, errno, FILE_CANTSEEK, pib->name);
}
}
while ((c = getc (stdin)) != EOF)
{
if (isspace (c))
Expand Down Expand Up @@ -227,6 +237,15 @@ static signed psin (struct _file_ * pib)
error (1, errno, "Can't update %s", pib->name);
}
}
else if (limit == PLC_CARRIERS)
{
uint8_t tmp = value & 0xff;
if (write (pib->file, &tmp, sizeof (tmp)) != sizeof (tmp))
{
error (1, errno, "Can't save %s", pib->name);
}
}

while (nobreak (c))
{
c = getc (stdin);
Expand All @@ -251,7 +270,7 @@ int main (int argc, char const * argv [])
{
"",
"pibfile [< scalers]",
"load prescalers into int6000 parameter file",
"load prescalers into int6000 and qca7000 parameter file",
(char const *) (0)
};
struct _file_ pib;
Expand All @@ -278,7 +297,7 @@ int main (int argc, char const * argv [])
{
error (1, errno, "Can't open %s", pib.name);
}
else if (pibfile1 (&pib))
else if (pibfile (&pib))
{
error (1, errno, "Bad PIB file: %s", pib.name);
}
Expand Down