add BD stop() method, fix indentation, only initialize fatfs once
authorchristinaa <tinab@hush.ai>
Tue, 3 Jan 2017 02:01:02 +0000 (02:01 +0000)
committerchristinaa <tinab@hush.ai>
Tue, 3 Jan 2017 02:02:01 +0000 (02:02 +0000)
arm_chainloader/drivers/block_device.hpp
arm_chainloader/drivers/mbr_disk.cc
arm_chainloader/drivers/sdhost_impl.cc
arm_chainloader/loader.cc

index eb504e5..93fb649 100644 (file)
@@ -30,6 +30,9 @@ struct BlockDevice {
        }\r
 \r
        virtual bool read_block(uint32_t sector, uint32_t* buf) = 0;\r
+\r
+       /* called to stop the block device */\r
+       virtual void stop() {}\r
 };\r
 \r
 extern BlockDevice* get_sdhost_device();
\ No newline at end of file
index e60ddbc..f4cb124 100644 (file)
@@ -149,7 +149,14 @@ MbrImpl STATIC_FILESYSTEM g_MbrDisk {};
 \r
 #include "fatfs/diskio.h"\r
 \r
+bool g_FatFsDiskInitialized = false;\r
+\r
 DSTATUS disk_initialize (BYTE pdrv) {\r
+       /* cache disk initialization state */\r
+       if (g_FatFsDiskInitialized) {\r
+               return static_cast<DRESULT>(0);\r
+       }\r
+\r
        BYTE pt = g_MbrDisk.get_partition_type(pdrv);\r
        switch (pt) {\r
                case MBR_FAT32_INT13:\r
@@ -157,7 +164,8 @@ DSTATUS disk_initialize (BYTE pdrv) {
                case MBR_FAT32:\r
                case MBR_FAT16:\r
                        logf("Mounting FAT partition %d of type 0x%x\n", pdrv, pt);\r
-                       return (DRESULT)0;\r
+                       g_FatFsDiskInitialized = true;\r
+                       return static_cast<DRESULT>(0);\r
        }\r
        logf("Disk %d isn't a FAT volume (partition type is 0x%x)!\n", pdrv, pt);\r
        return STA_NOINIT;\r
index 16736ec..3f974b2 100644 (file)
@@ -495,6 +495,24 @@ struct SdhostImpl : BlockDevice {
                }\r
        }\r
 \r
+       virtual void stop() override {\r
+               logf("stopping sdhost controller driver ...\n");\r
+\r
+               SH_CMD = 0;\r
+               SH_ARG = 0;\r
+               SH_TOUT = 0xA00000;\r
+               SH_CDIV = 0x1FB;\r
+\r
+               logf("powering down controller ...\n");\r
+               SH_VDD = 0;\r
+               SH_HCFG = 0;\r
+               SH_HBCT = 0x400;\r
+               SH_HBLC = 0;\r
+               SH_HSTS = 0x7F8;\r
+\r
+               logf("controller down!\n");\r
+       }\r
+\r
        SdhostImpl() {\r
                restart_controller();\r
                logf("eMMC driver sucessfully started!\n");\r
index 97c7146..6674431 100644 (file)
@@ -20,6 +20,7 @@ Second stage bootloader.
 #include <drivers/fatfs/ff.h>
 #include <chainloader.h>
 #include <drivers/mailbox.hpp>
+#include <drivers/block_device.hpp>
 #include <libfdt.h>
 #include <memory_map.h>
 
@@ -83,9 +84,9 @@ struct LoaderImpl {
                        panic("error reading fdt");
                }
 
-                void* v_fdt = reinterpret_cast<void*>(fdt);
+                               void* v_fdt = reinterpret_cast<void*>(fdt);
 
-                int res;
+                               int res;
 
                if ((res = fdt_check_header(v_fdt)) != 0) {
                        panic("fdt blob invalid, fdt_check_header returned %d", res);
@@ -102,30 +103,36 @@ struct LoaderImpl {
                res = fdt_setprop(v_fdt, node, "bootargs", cmdline, strlen((char*) cmdline) + 1);
                logf("fdt_setprop(): %d\n", res);
 
-                /* pass in a memory map, skipping first meg for bootcode */
-                int memory = fdt_path_offset(v_fdt, "/memory");
-                if(memory < 0)
-                    return NULL;
+               /* pass in a memory map, skipping first meg for bootcode */
+               int memory = fdt_path_offset(v_fdt, "/memory");
+               if(memory < 0)
+                       return NULL;
 
-                /* start the memory map at 1M/16 and grow continuous for 256M
-                 * TODO: does this disrupt I/O? */
+               /* start the memory map at 1M/16 and grow continuous for 256M
+                * TODO: does this disrupt I/O? */
 
-                char dtype[] = "memory";
-                //uint32_t memmap[] = { 0x10000, 0x20000000 };
-                //uint8_t memmap[] = { 0x00, 0x00, 0x01, 0x00,
-                //                     0x00, 0x00, 0x00, 0x20 };
-                uint8_t memmap[] = { 0x00, 0x00, 0x01, 0x00,
-                                     0x30, 0x00, 0x00, 0x00 };
+               char dtype[] = "memory";
+               //uint32_t memmap[] = { 0x10000, 0x20000000 };
+               //uint8_t memmap[] = { 0x00, 0x00, 0x01, 0x00,
+               //                     0x00, 0x00, 0x00, 0x20 };
+               uint8_t memmap[] = { 0x00, 0x00, 0x01, 0x00,
+                                                        0x30, 0x00, 0x00, 0x00 };
 
-                res = fdt_setprop(v_fdt, memory, "reg", (void*) memmap, sizeof(memmap));
-                //res = fdt_setprop(v_fdt, memory, "device_type", dtype, strlen(dtype) + 1);
-                logf("fdt_setprop(): %d\n", res);
+               res = fdt_setprop(v_fdt, memory, "reg", (void*) memmap, sizeof(memmap));
+               //res = fdt_setprop(v_fdt, memory, "device_type", dtype, strlen(dtype) + 1);
+               logf("fdt_setprop(): %d\n", res);
 
                logf("valid fdt loaded at 0x%X\n", (unsigned int)fdt);
 
                return fdt;
        }
 
+       void teardown_hardware() {
+               BlockDevice* bd = get_sdhost_device();
+               if (bd)
+                       bd->stop();
+       }
+
        LoaderImpl() {  
                logf("Mounting boot partitiion ...\n");
                FRESULT r = f_mount(&g_BootVolumeFs, ROOT_VOLUME_PREFIX, 1);
@@ -165,20 +172,22 @@ struct LoaderImpl {
 
                logf("zImage loaded at 0x%X\n", (unsigned int)zImage);
 
-                logf("First few of zImage.. %X%X%X%X\n", zImage[0], zImage[1], zImage[2], zImage[3]);
+               logf("First few of zImage.. %X%X%X%X\n", zImage[0], zImage[1], zImage[2], zImage[3]);
+
+               /* flush the cache */
+               logf("Flushing....\n")
+               for (uint8_t* i = zImage; i < zImage + sz; i += 32) {
+                       __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,1" : : "r" (i) : "memory");
+               }
 
-                /* flush the cache */
-                logf("Flushing....\n")
-                for (uint8_t* i = zImage; i < zImage + sz; i += 32) {
-                    __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,1" : : "r" (i) : "memory");
-                }
+               teardown_hardware();
 
-                /* fire away */
+               /* fire away */
                logf("Jumping to the Linux kernel...\n");
                
                /* this should never return */
-                logf("FDT loaded at %x\n", (unsigned int) fdt);
-                logf("First few of fdt... %X%X%X%X\n", fdt[0], fdt[1], fdt[2], fdt[3]);
+               logf("FDT loaded at %x\n",  reinterpret_cast<uint32_t>(fdt));
+               logf("First few of fdt... %X%X%X%X\n", fdt[0], fdt[1], fdt[2], fdt[3]);
                boot_linux(0, ~0, fdt, zImage);
        }
 };
This page took 0.04233 seconds and 4 git commands to generate.