summaryrefslogblamecommitdiffstats
path: root/private/ntos/nthals/halalpha/environ.c
blob: 3831214a5eff9aeee9d6bc080c7124a561d25ba0 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                
//smjfix - This code needs to be made MP safe if it isn't being called
//         by MP safe code.
//jwlfix - It's currently being called by the kernel (ex, actually) in
//         an MP-safe fashion, and by config during phase 1 (?) of
//         bootstrapping the system.

/*++

Copyright (c) 1991  Microsoft Corporation
Copyright (c) 1992, 1993  Digital Equipment Corporation

Module Name:

    environ.c

Abstract:

    This module implements the ARC firmware Environment Variable functions as
    described in the Advanced Risc Computing Specification (Revision 1.00),
    section 3.3.3.11.

Author:

    David M. Robinson (davidro) 13-June-1991


Revision History:

    James Livingston  94.05.17

        Fix a coding error that caused NVRAM to get trashed in the attempt
        to update a nearly full environment variable space.

    Steve Jenness  93.12.20

        The firmware still requires the naked checksum set and check
        routines.  Add them back in under the AXP_FIRMWARE conditional
        until the jxenvir.c in the firmware and the environ.c files
        are rationalized.

    Steve Jenness. 93.12.17

        Reduce the reads and writes to the NVRAM part.  Some parts are
        slow to access (especially on writes).  Do NVRAM access only when
        really necessary.  Remove use of HalpCopyNVRamBuffer because it is
        too difficult to make generically fast (put more intelligence
        in higher code instead).

    Steve Brooks. 6-Oct 1993 remove all platform and device specific references

        These routines have been restructured to be platform and device
        independant. All calls access the NVRAM via the calls
        HalpReadNVRamBuffer, HalpWriteNVRamBuffer, and HalpCopyNVRamBuffer

    Jeff McLeman (DEC) 31-Jul-1992 modify for Jensen

--*/

#include "halp.h"
#include "environ.h"

#include "arccodes.h"

//
// Static data.
//

UCHAR Environment[LENGTH_OF_ENVIRONMENT];
ULONG EnvironmentChecksum;
BOOLEAN EnvironmentValid = FALSE;

UCHAR OutputString[MAXIMUM_ENVIRONMENT_VALUE];
PCONFIGURATION Configuration;

//
// Routine prototypes.
//

ARC_STATUS
HalpReadAndChecksumEnvironment (
    );

ARC_STATUS
HalpWriteAndChecksumEnvironment (
    );

ARC_STATUS
HalGetEnvironmentVariable (
    IN PCHAR Variable,
    IN USHORT length,
    OUT PCHAR Buffer
    );

ARC_STATUS
HalSetEnvironmentVariable (
    IN PCHAR Variable,
    IN PCHAR Value
    );

ARC_STATUS
HalpFindEnvironmentVariable (
    IN PCHAR Variable,
    OUT PULONG VariableIndex,
    OUT PULONG ValueIndex
    );

#if defined(AXP_FIRMWARE)

ARC_STATUS
HalpEnvironmentCheckChecksum (
    VOID
    );

ARC_STATUS
HalpEnvironmentSetChecksum (
    VOID
    );

#endif //AXP_FIRMWARE

#ifdef AXP_FIRMWARE

#pragma alloc_text(DISTEXT, HalpReadAndChecksumEnvironment )
#pragma alloc_text(DISTEXT, HalpWriteAndChecksumEnvironment )
#pragma alloc_text(DISTEXT, HalGetEnvironmentVariable )
#pragma alloc_text(DISTEXT, HalSetEnvironmentVariable )
#pragma alloc_text(DISTEXT, HalpFindEnvironmentVariable )
#pragma alloc_text(DISTEXT, HalpEnvironmentCheckChecksum )
#pragma alloc_text(DISTEXT, HalpEnvironmentSetChecksum )

#endif // AXP_FIRMWARE


ARC_STATUS
HalpReadAndChecksumEnvironment(
    )

/*++

Routine Description:

    This routine reads the part of the NVRAM containing the environment
    variables into a memory buffer.  It checksums the data as read.

Arguments:

    None.

Return Value:

    ESUCCESS - checksum is good.
    EIO - checksum is bad.

--*/

{
    PUCHAR BufChar;
    ULONG Index;
    ULONG Checksum1, Checksum2;

#ifndef EISA_PLATFORM
    UCHAR Nvram[LENGTH_OF_ENVIRONMENT+16];
#endif // EISA_PLATFORM

    //
    // Read checksum of environment data from the NVRAM.
    // For non eisa machines we have only one checksum for the whole nvram.
    // And it is stored in Checksum
    //

    HalpReadNVRamBuffer(
        (PUCHAR)&Checksum2,
#ifdef EISA_PLATFORM
        &((PNV_CONFIGURATION)NVRAM_CONFIGURATION)->Checksum2[0],
#else // EISA_PLATFORM
        &((PNV_CONFIGURATION)NVRAM_CONFIGURATION)->Checksum[0],
#endif // EISA_PLATFORM
        4);

    //
    // If the environment data stored in the buffer is already valid,
    // short-circuit the NVRAM read.
    //

    if (EnvironmentValid == TRUE) {
        if (Checksum2 == EnvironmentChecksum) {
            return ESUCCESS;
        }
    }

#ifdef EISA_PLATFORM
    //
    // Read the NVRAM environment data into the buffer.
    //

    HalpReadNVRamBuffer(
        &Environment[0],
        &((PNV_CONFIGURATION)NVRAM_CONFIGURATION)->Environment[0],
        LENGTH_OF_ENVIRONMENT);

    //
    // Form checksum of data read from NVRAM.
    //

    BufChar = &Environment[0];
    Checksum1 = 0;
    for ( Index = 0 ; Index < LENGTH_OF_ENVIRONMENT; Index++ ) {
        Checksum1 += *BufChar++;
    }

    if (Checksum1 != Checksum2) {
        return EIO;
    } else {
        EnvironmentValid = TRUE;
        EnvironmentChecksum = Checksum1;
        return ESUCCESS;
    }
#else // EISA_PLATFORM

    //
    // Read the NVRAM into Nvram.
    //

    HalpReadNVRamBuffer( &Nvram[0], 
                         NVRAM_CONFIGURATION, 
                         LENGTH_OF_ENVIRONMENT + 16 );

    //
    // Form checksum of data read from NVRAM.
    //

    BufChar = &Nvram[0];
    Checksum1 = 0;
    for ( Index = 0 ; Index < LENGTH_OF_ENVIRONMENT+16; Index++ ) {
        Checksum1 += *BufChar++;
    }

    if (Checksum1 != Checksum2) {
        return EIO;
    } else {
        EnvironmentValid = TRUE;
        EnvironmentChecksum = Checksum1;

        //
        // Nvram checksum was ok. Save the read Environment part of NVRAM
        // in global Environment[].
        //
        BufChar = &Environment[0];
        for( Index = 16; Index <  LENGTH_OF_ENVIRONMENT+16; Index++ ) {
            *BufChar++ = Nvram[Index];
        }

        return ESUCCESS;
    }
#endif // EISA_PLATFORM
}


ARC_STATUS
HalpWriteAndChecksumEnvironment (
    )

/*++

Routine Description:

    This routine writes the environment data back to the NVRAM, calculates
    a new checksum, and stores the checksum.

    N.B. - For this method of rewriting the environment variables to be
           effective (minimal NVRAM access and quick overall), the
           HalpWriteNVRamBuffer is assumed to do block access and to
           suppress writes it doesn't need to do.

    N.B. - To allow the HalpWriteNVRamBuffer to suppress writes, the new data
           should have as many bytes in common with the current NVRAM
           contents as possible.  For example, the environment variables
           should not be reordered unless needed.

Arguments:

    None.

Return Value:

    ESUCCESS - NVRAM write succeeded.
    EIO - NVRAM write failed.

--*/

{
    ULONG Index;
    ULONG Checksum;
    KIRQL OldIrql;
    PUCHAR BufChar;

    KeRaiseIrql(DEVICE_LEVEL, &OldIrql);

    //
    // Form checksum from new NVRAM data.
    //

    Checksum = 0;

    BufChar = &Environment[0];
    for ( Index = 0 ; Index < LENGTH_OF_ENVIRONMENT; Index++ ) {
        Checksum += *BufChar++;
    }

#ifndef EISA_PLATFORM
    {
        UCHAR TempBuffer[16];
        HalpReadNVRamBuffer( TempBuffer, (PUCHAR)NVRAM_CONFIGURATION, 16 ); 
        for ( Index = 0 ; Index < 16; Index++ ) {
            Checksum += TempBuffer[ Index ];
        }
    }
#endif // !EISA_PLATFORM

    //
    // Write environment variables to NVRAM.
    //

    HalpWriteNVRamBuffer(
        &((PNV_CONFIGURATION)NVRAM_CONFIGURATION)->Environment[0],
        &Environment[0],
        LENGTH_OF_ENVIRONMENT);

    //
    // Write environment checksum.
    //

    HalpWriteNVRamBuffer(
#ifdef EISA_PLATFORM
        &((PNV_CONFIGURATION)NVRAM_CONFIGURATION)->Checksum2[0],
#else // EISA_PLATFORM
        &((PNV_CONFIGURATION)NVRAM_CONFIGURATION)->Checksum[0],
#endif // EISA_PLATFORM
        (PUCHAR)&Checksum,
        4);

    EnvironmentChecksum = Checksum;
    EnvironmentValid = TRUE;

    KeLowerIrql(OldIrql);

    return ESUCCESS;
}


ARC_STATUS
HalGetEnvironmentVariable (
    IN PCHAR Variable,
    IN USHORT length,
    OUT PCHAR Buffer
    )

/*++

Routine Description:

    This routine searches (not case sensitive) the non-volatile ram for
    Variable, and if found returns a pointer to a zero terminated string that
    contains the value, otherwise a NULL pointer is returned.


Arguments:

    Variable - Supplies a zero terminated string containing an environment
               variable.
    Length - Supplies the length of the value buffer in bytes

    Buffer - Supplies a pointer to a buffer that will recieve the 
             environment variable.

Return Value:

    ESUCCESS - Buffer contains the zero terminated string value of Variable.
    ENOENT - The variable doesn't exist in the environment.
    ENOMEM - The variable exists, but the value is longer than Length.

--*/

{
    PUCHAR NvChars;
    ULONG VariableIndex;
    ULONG ValueIndex;
    ULONG Index;
    ARC_STATUS Status;
    KIRQL OldIrql;

    //
    // Raise IRQL to synchronize
    //

    KeRaiseIrql(DEVICE_LEVEL, &OldIrql);

    //
    // If checksum is wrong, or the variable can't be found, return NULL.
    //

    if ((HalpReadAndChecksumEnvironment() != ESUCCESS) ||
        (HalpFindEnvironmentVariable(Variable,
                                     &VariableIndex,
                                     &ValueIndex) != ESUCCESS)) {
        Status = ENOENT;
    } else {

        //
        // Copy value to an output string, break on zero terminator
        // or string max.
        //

        NvChars = &Environment[ValueIndex];
        for ( Index = 0 ; Index < length ; Index += 1 ) {
            if ( (*Buffer++ = *NvChars++) == 0 ) {
                break;
            }
        }

        if (Index == length) {
            Status = ENOMEM;
        } else {
            Status = ESUCCESS;
        }
    }

    //
    // Lower IRQL back to where it was
    //

    KeLowerIrql(OldIrql);

    return Status;
}


ARC_STATUS
HalSetEnvironmentVariable (
    IN PCHAR Variable,
    IN PCHAR Value
    )

/*++

Routine Description:

    This routine sets Variable (not case sensitive) to Value.

Arguments:

    Variable - Supplies a zero terminated string containing an environment
               variable.

    Value - Supplies a zero terminated string containing an environment
            variable value.

Return Value:

    ESUCCESS - The set completed successfully
    ENOSPC - No space in NVRAM for set operation.
    EIO - Invalid Checksum.

--*/

{
    ULONG VariableIndex;
    ULONG ValueIndex;
    PUCHAR TopOfEnvironment;
    PCHAR String;
    PUCHAR NvChars;
    LONG Count;
    CHAR Char;
    KIRQL OldIrql;

    //
    // Raise Irql to Synchronize
    //

    KeRaiseIrql(DEVICE_LEVEL, &OldIrql);

    //
    // If checksum is wrong, return EIO;
    //

    if (HalpReadAndChecksumEnvironment() != ESUCCESS) {
        KeLowerIrql(OldIrql);
        return EIO;
    }

//
//smjfix - examine the boundary condition where the environment space
//         is exactly filled.

    //
    // Determine the top of the environment space by looking for the first
    // non-null character from the top.
    //

    TopOfEnvironment = &Environment[LENGTH_OF_ENVIRONMENT-1];

    do {
        Char = *TopOfEnvironment;

    } while ( Char == 0 && (--TopOfEnvironment > Environment) );

    //
    // Adjust TopOfEnvironment to the first new character, unless environment
    // space is empty, or the environment is exactly full.  In the latter
    // case, the new value MUST fit into the space taken by the old.
    //

    if (TopOfEnvironment != Environment
       && TopOfEnvironment < &Environment[LENGTH_OF_ENVIRONMENT-2]) {
        TopOfEnvironment += 2;
    }

    //
    // Handle the case where the content of the NVRAM has been corrupted
    // such that the last character in the environment is non-zero.
    //

    Count = &Environment[LENGTH_OF_ENVIRONMENT-1] - TopOfEnvironment;
    if (Count < 0) {
        KeLowerIrql(OldIrql);
        return ENOSPC;
    }


    //
    // Check to see if the variable already has a value.
    //

    if (HalpFindEnvironmentVariable(Variable, &VariableIndex, &ValueIndex) 
        == ESUCCESS) {
        ULONG SizeOfValue = strlen(Value);

        if (SizeOfValue == strlen(&Environment[ValueIndex])) {

            //
            // Overwrite the current variable in place.
            //

            RtlMoveMemory(&Environment[ValueIndex],
                          Value,
                          SizeOfValue);
            //
            // Suppress the append of the variable to the end of the
            // environment variable data.
            //

            *Value = 0;

        } else {

            //
            // Count free space, starting with the free area at the top and
            // adding the old variable value.
            //

            for ( NvChars = &Environment[ValueIndex];
                  NvChars <= TopOfEnvironment;
                  NvChars++ ) {

                  Char = *NvChars;
                  if ( Char == 0 )
                    break;
                      Count++;
            }

            //
            // Determine if free area is large enough to handle new value, if
            // not return error.
            //

            for ( String = Value ; *String != 0 ; String++ ) {
                if (Count-- == 0) {
                    KeLowerIrql(OldIrql);
                    return ENOSPC;
                }
            }

            //
            // Move ValueIndex to the end of the value and compress strings.
            //

            do {
                Char = Environment[ValueIndex++];
            } while( Char != 0 );

            Count = TopOfEnvironment - &Environment[ValueIndex];
            RtlMoveMemory(&Environment[VariableIndex],
                          &Environment[ValueIndex],
                          Count);

            //
            // Adjust new top of environment.
            //

            TopOfEnvironment = &Environment[VariableIndex+Count];

            //
            // Zero to the end.
            //

            Count = &Environment[LENGTH_OF_ENVIRONMENT] - TopOfEnvironment;
            Char = 0;
            while ( Count -- ) {
                TopOfEnvironment[Count] = Char;
            }
        }

    } else {

        //
        // Variable is new.
        //

        //
        // Determine if free area is large enough to handle new value, if not
        // return error.
        //

        //
        // From the length of free space subtract new variable's length,
        // Value's length and 2 chars, one for the '=' sign and one of the
        // null terminator.
        //

        Count -= ( strlen(Variable) + strlen(Value) + 2 );

        //
        // Check if there is space to fit the new variable.
        //

        if (Count < 0) {
            KeLowerIrql(OldIrql);
            return ENOSPC;
        }

      }

    //
    // If Value is not zero, append the new variable and value.
    //

    if (*Value != 0) {

        //
        // Write new variable, converting to upper case.
        //
        while ( *Variable != 0 ) {

            Char = ((*Variable >= 'a') && (*Variable <= 'z') ?
                         (*Variable - 'a' + 'A') : *Variable);

            *TopOfEnvironment = Char;

            Variable ++;
            TopOfEnvironment ++;
        }

        //
        // Write equal sign.
        //

        Char = '=';
        *TopOfEnvironment++ = Char;

        //
        // Write new value.
        //

        for ( Count = 0; Value[Count] != 0; Count ++ )
            ;

        RtlMoveMemory(&TopOfEnvironment[0], Value, Count);

    }

    //
    // Write the environment variables out to NVRAM and checksum it.
    //

    if (HalpWriteAndChecksumEnvironment() != ESUCCESS) {
        KeLowerIrql(OldIrql);
        return EIO;
    }

    //
    // Lower Irql back to where it was
    //

    KeLowerIrql(OldIrql);

    
    return ESUCCESS;

}

ARC_STATUS
HalpFindEnvironmentVariable (
    IN PCHAR Variable,
    OUT PULONG VariableIndex,
    OUT PULONG ValueIndex
    )

/*++

Routine Description:

    This routine searches (not case sensitive) the supplied NVRAM image
    for the given Variable.

Arguments:

    Variable - Supplies a zero terminated string containing an environment
               variable.
    VariableIndex - Returned byte offset into Environment of the
                    Variable if found.
    ValueIndex - Returned byte offset into Environment of the
                 value of the Variable if found.

Return Value:

    ESUCCESS - Variable found and indicies returned.
    ENOENT - Variable not found.

--*/

{
    PUCHAR String;
    UCHAR Char;
    ULONG Index;

    //
    // If Variable is null, return immediately.
    //

    if (*Variable == 0) {
        return ENOENT;
    }

    Index = 0;

    while (TRUE) {

        //
        // Set string to beginning of Variable.
        //

        String = Variable;
        *VariableIndex = Index;

        //
        // Search until the end of NVRAM.
        //

        while ( Index < LENGTH_OF_ENVIRONMENT ) {

            //
            // Convert to uppercase and break if mismatch.
            //

            Char = Environment[Index];

            if ( Char != ((*String >= 'a') && (*String <= 'z') ?
                                (*String - 'a' + 'A') : *String) ) {
                break;
            }

            String++;
            Index++;
        }

        if ( Index == LENGTH_OF_ENVIRONMENT )
            return ENOENT;

        //
        // Check to see if we're at the end of the string and the variable,
        // which means a match.
        //

        Char = Environment[Index];
        if ((*String == 0) && (Char == '=')) {
            *ValueIndex = ++Index;
            return ESUCCESS;
        }

        //
        // Move index to the start of the next variable.
        //

        do {
            Char = Environment[Index++];

            if (Index >= LENGTH_OF_ENVIRONMENT) {
                return ENOENT;
            }

        } while (Char != 0);

    }
}

#if defined(AXP_FIRMWARE)

ARC_STATUS
HalpEnvironmentCheckChecksum (
    VOID
    )

/*++

Routine Description:

    This routine checks the environment area checksum.


Arguments:

    None.

Return Value:

    If the checksum is good, ESUCCESS is returned, otherwise EIO is returned.

--*/

{
    PUCHAR NvChars;
    UCHAR  Char;
    PNV_CONFIGURATION NvConfiguration;
    ULONG Index;
    ULONG Checksum1, Checksum2;
    BOOLEAN AllZeroBytes;

    NvConfiguration = (PNV_CONFIGURATION)NVRAM_CONFIGURATION;

    //
    // Form checksum from NVRAM data.
    //

    Checksum1 = 0;
    AllZeroBytes = TRUE;
    NvChars = (PUCHAR)&NvConfiguration->Environment[0];

    for ( Index = 0 ; Index < LENGTH_OF_ENVIRONMENT; Index++ ) {

        HalpReadNVRamBuffer(&Char,NvChars++,1);
        Checksum1 += Char;
        if (Char != 0) {
            AllZeroBytes = FALSE;
        }
    }

    //
    // Reconstitute checksum and return error if no compare.
    //

#ifdef EISA_PLATFORM
    HalpReadNVRamBuffer((PCHAR)&Checksum2,&NvConfiguration->Checksum2[0],4);
#else // EISA_PLATFORM
    HalpReadNVRamBuffer((PCHAR)&Checksum2,&NvConfiguration->Checksum[0],4);
#endif // EISA_PLATFORM

    //
    // We return an error condition if the Checksum does not match the sum
    // of all the protected bytes, *or* if all the protected bytes are zero.
    // The latter check covers the condition of a completely zeroed NVRAM;
    // such a condition would appear to have a valid checksum.
    //
    // We do not use a better checksum algorithm because the pain of
    // orchestrating a change in the existing SRM consoles (which read our
    // stored Nvram information for various purposes) has been deemed to be
    // too high.
    //

    if ((Checksum1 != Checksum2) || (AllZeroBytes == TRUE)) {
        return EIO;
    } else {
        return ESUCCESS;
    }
}


ARC_STATUS
HalpEnvironmentSetChecksum (
    VOID
    )

/*++

Routine Description:

    This routine sets the environment area checksum.

Arguments:

    None.

Return Value:

    None.

--*/

{
    PUCHAR NvChars;
    UCHAR Char;
    PNV_CONFIGURATION NvConfiguration;
    ULONG Index;
    ULONG Checksum;
    KIRQL OldIrql;

    NvConfiguration = (PNV_CONFIGURATION)NVRAM_CONFIGURATION;

    //
    // Form checksum from NVRAM data.
    //

    Checksum = 0;
    NvChars = (PUCHAR)&NvConfiguration->Environment[0];

    KeRaiseIrql(DEVICE_LEVEL, &OldIrql);

    for ( Index = 0 ; Index < LENGTH_OF_ENVIRONMENT; Index++ ) {
        HalpReadNVRamBuffer(&Char, NvChars ++, 1);
        Checksum += Char;
    }

    KeLowerIrql(OldIrql);

    //
    // Write environment checksum.
    //

    if ( 
#ifdef EISA_PLATFORM
    HalpWriteNVRamBuffer((PCHAR)NvConfiguration->Checksum2, (PCHAR)&Checksum, 4)
#else // EISA_PLATFORM
    HalpWriteNVRamBuffer((PCHAR)NvConfiguration->Checksum, (PCHAR)&Checksum, 4)
#endif  // EISA_PLATFORM
                         != ESUCCESS ) {
      return EIO;
    } else {
      return ESUCCESS;

    }
}

#endif //AXP_FIRMWARE