# SFBProvenanceData.h

Go to the documentation of this file.

    00001 /*                                             -*- mode:C++; fill-column:100 -*-
    00002  * SFBProvenanceData.h The actual program description block itself,
    00003  *                       compiled anew on every build
    00004  * Copyright (C) 2009 The Regents of the University of New Mexico.  All rights reserved.
    00005  *
    00006  * This file is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU Lesser General Public
    00008  * License as published by the Free Software Foundation; either
    00009  * version 2.1 of the License, or (at your option) any later version.
    00010  *
    00011  * This library is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  * Lesser General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU General Public License
    00017  * along with this library; if not, write to the Free Software
    00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00019  * USA
    00020  */
    00021
    00030 /*
    00031  * NOTE: This file, even though it is a .h, includes variable
    00032  * _definitions_, not just declarations.  That is because this file,
    00033  * when used, MUST BE INCLUDED DURING ONLY ONE COMPILATION STEP!
    00034  *
    00035  * For sketches, this file is expected to be included only during the
    00036  * compilation of 'sketch-wrapper.cpp'.
    00037  *
    00038  * It is the date and time of _that one compilation step_ that
    00039  * determines the buildDate and buildTime in 'theProvenance'.  This
    00040  * file and the sketch loader script together conspire to place
    00041  * 'theProvenance' at the very beginning of the compiled image.
    00042  */
    00043
    00044
    00045 #ifndef SFBPROVENANCEDATA_H
    00046 #define SFBPROVENANCEDATA_H
    00047
    00048 #include "SFBProvenance.h"
    00049
    00050 #ifndef HOST_MODE
    00051 #define IN_HEADER  __attribute__((section (".header")))
    00052 #define IN_FOOTER  __attribute__((section (".footer")))
    00053 #else
    00054 #define IN_HEADER  /* nothing */
    00055 #define IN_FOOTER  /* nothing */
    00056 #endif
    00057
    00058 #ifndef SFB_SKETCH_CREATOR_ID
    00059 #define SFB_SKETCH_CREATOR_ID (0)
    00060 #endif
    00061
    00062 #ifndef SFB_SKETCH_PROGRAM_ID
    00063 #define SFB_SKETCH_PROGRAM_ID (0)
    00064 #endif
    00065
    00066 #ifndef SFB_SKETCH_COPYRIGHT_NOTICE
    00067 #define SFB_SKETCH_COPYRIGHT_NOTICE (0)
    00068 #endif
    00069
    00070 u32 theFooter IN_FOOTER = SFB_PROVENANCE_NZTRX;  // loader script puts .footer section after everything else.
    00071
    00072 extern char __rom_length;       // Provided by sfbloader.ld
    00073
    00074 volatile const SFBProvenance theProvenance IN_HEADER  = {  // Yow, it really must be volatile const!
    00075   0xEA000000+sizeof(SFBProvenance)/4-2, // ARM Branch instruction, offset is blocksize (in words) less 2 for pipeline
    00076   0,                            // checksum0
    00077   0,                            // checksum1
    00078   0,                            // sourceOwnerId
    00079   0,                            // sourceBoardId
    00080   SFB_PROVENANCE_MAGIC,
    00081   0,                            // flags (TBD)
    00082   0,                            // reserved (TBD)
    00083   SKETCH_ARCH_CODE,             // set by compilation flags
    00084   SFB_SKETCH_CREATOR_ID,
    00085   SFB_SKETCH_PROGRAM_ID,
    00086   SKETCH_BUILD_DATE,
    00087   SKETCH_BUILD_TIME,
    00088   (int) &__rom_length,
    00089   (u32) SFB_SKETCH_COPYRIGHT_NOTICE,
    00090   SFB_PROVENANCE_CIGAM
    00091 };
    00092
    00093 extern void initProgramServerSketch() {
    00094   programServerSetSketch(&theProvenance,(uptr) &theProvenance, 0);
    00095 }
    00096
    00102 int wantPhPacketCodeUpdate(u8 * packet) {
    00103   if (!packet)
    00104     return -1;
    00105
    00106   u8 arch;
    00107   int cid, pid, bdt, btm;
    00108   u32 matches =
    00109     packetScanf(packet,"Ph%c%l%l%l%l%\n", &arch, &cid, &pid, &bdt, &btm);
    00110   if (matches < 8) return -(matches+2);
    00111   if (cid == -1 || pid == -1) return -10;
    00112   if (bdt < 0 || btm < 0) return -11;
    00113   if (arch != SKETCH_ARCH_CODE) return -(400+10*arch+SKETCH_ARCH_CODE);
    00114
    00115   u8 bootMode = getBootBlockBootMode();
    00116
    00117   if (bootMode==RED_BOOT_MODE) return 6;
    00118   if (bootMode==BLUE_BOOT_MODE && cid != theProvenance.creatorId) return 1;
    00119   if (bootMode==BLUE_BOOT_MODE && pid != theProvenance.programId) return 2;
    00120   if (bdt < theProvenance.buildDate) return 3;
    00121   if (bdt == theProvenance.buildDate && btm < theProvenance.buildTime) return 4;
    00122   if (bdt == theProvenance.buildDate && btm == theProvenance.buildTime) return 5;
    00123
    00124   return 0;
    00125 }
    00126
    00127
    00128
    00129 #endif /* SFBPROVENANCEDATA_H */
    00130