SAMA5D4 Xplained Ultra Board BSP
guowenxue
2019-08-23 9393cb81acc34d1bd27cc921d8d98e618fb74662
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
import SAMBA 3.2
import SAMBA.Connection.Serial 3.2
import SAMBA.Device.SAMA5D4 3.2
 
SerialConnection {
 
    device: SAMA5D4Xplained {
        config {
            nandflash {
                header: 0xc1e04e07
            }
        }
    }
 
    function initNand() {
        /* Placeholder: Nothing to do */
    }
 
    function getEraseSize(size) {
        /* get smallest erase block size supported by applet */
        var eraseSize
        for (var i = 0; i <= 32; i++) {
            eraseSize = 1 << i
            if ((applet.eraseSupport & eraseSize) !== 0)
                break;
        }
        eraseSize *= applet.pageSize
 
        /* round up file size to erase block size */
        return (size + eraseSize - 1) & ~(eraseSize - 1)
    }
 
    function eraseWrite(offset, filename, bootfile) {
        /* get file size */
        var file = File.open(filename, false)
        var size = file.size()
        file.close()
 
        applet.erase(offset, getEraseSize(size))
        applet.write(offset, filename, bootfile)
    }
 
    onConnectionOpened: {
        var bootstrapFileName = "images/bootstrap-sama5d4.bin"
        var ubootFileName = "images/u-boot-sama5d4.bin"
        var linuxFileNmae = "images/linuxrom-sama5d4.itb"
        var rootfsFileNmae = "images/rootfs-sama5d4.ubi"
        
        print("-I- === Initilize low level (system clocks) ===")
        initializeApplet("lowlevel")
 
        print("-I- === Initialize extram ===")
        initializeApplet("extram")
 
        print("-I- === Initialize nandflash access ===")
        initializeApplet("nandflash")
        
        print("-I- === Erase nandflash access ===")
        //applet.erase(0, 0x100000)
        applet.erase()
    
        print("-I- === Load AT91Bootstrap  ===")
        eraseWrite(0x000000, bootstrapFileName, true)
 
        print("-I- === Load u-boot   ===")
        eraseWrite(0x040000, ubootFileName)
 
        print("-I- === Load linux kernel image  ===")
        applet.write(0x100000, linuxFileNmae)
 
        print("-I- === Load UBI rootfs image  ===")
        applet.write(0x800000, rootfsFileNmae)
 
        print("-I- === Done. ===")
    }
}