Advertisement
Guest User

Untitled

a guest
Aug 6th, 2010
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.61 KB | None | 0 0
  1. diff --git a/apps/codecs.c b/apps/codecs.c
  2. index 29a6644..93b1b6b 100644
  3. --- a/apps/codecs.c
  4. +++ b/apps/codecs.c
  5. @@ -55,7 +55,11 @@
  6.  #include "logf.h"
  7.  
  8.  #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
  9. -
  10. +#if  !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  11. +#  define FS_PREFIX(_x_) sim_ ## _x_
  12. +# else
  13. +#  define FS_PREFIX(_x_) _x_
  14. +# endif
  15.  #define PREFIX(_x_) sim_ ## _x_
  16.  #if CONFIG_CODEC == SWCODEC
  17.  unsigned char codecbuf[CODEC_SIZE];
  18. @@ -66,6 +70,7 @@ void sim_codec_close(void *pd);
  19.  #else /* !PLATFORM_HOSTED */
  20.  
  21.  #define PREFIX
  22. +#define FS_PREFIX
  23.  #define sim_codec_close(x)
  24.  
  25.  #endif
  26. @@ -77,7 +82,7 @@ extern void* plugin_get_audio_buffer(size_t *buffer_size);
  27.  #undef open
  28.  static int open(const char* pathname, int flags, ...)
  29.  {
  30. -#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
  31. +#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  32.      int fd;
  33.      if (flags & O_CREAT)
  34.      {
  35. @@ -178,11 +183,11 @@ struct codec_api ci = {
  36.      enc_unget_pcm_data,
  37.  
  38.      /* file */
  39. -    (open_func)PREFIX(open),
  40. -    PREFIX(close),
  41. -    (read_func)PREFIX(read),
  42. -    PREFIX(lseek),
  43. -    (write_func)PREFIX(write),
  44. +    (open_func)FS_PREFIX(open),
  45. +    FS_PREFIX(close),
  46. +    (read_func)FS_PREFIX(read),
  47. +    FS_PREFIX(lseek),
  48. +    (write_func)FS_PREFIX(write),
  49.      round_value_to_list32,
  50.  
  51.  #endif /* HAVE_RECORDING */
  52. diff --git a/apps/main.c b/apps/main.c
  53. index 67cd6d2..2973bd8 100644
  54. --- a/apps/main.c
  55. +++ b/apps/main.c
  56. @@ -353,7 +353,39 @@ static void init(void)
  57.      sb_skin_init();
  58.      viewportmanager_init();
  59.  
  60. +#if defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  61. +    disk_init_subsystem();
  62. +    int rc = storage_init();
  63. +    if(rc)
  64. +        panicf("storage error: %d", rc);
  65. +    rc = disk_mount_all();
  66. +    if(rc <= 0)
  67. +    {
  68. +        printf("disk_mount error: %d\n", rc);
  69. +        lcd_clear_display();
  70. +        lcd_puts(0, 0, "No partition");
  71. +        lcd_puts(0, 1, "found.");
  72. +        lcd_puts(0, 2, "Continue ?");
  73. +
  74. +        lcd_update();
  75. +
  76. +        while(true)
  77. +        {
  78. +            int button = get_action(CONTEXT_YESNOSCREEN, HZ*5);
  79. +            switch (button)
  80. +            {
  81. +                case ACTION_YESNO_ACCEPT: goto Lcontinue;
  82. +                case ACTION_NONE: continue;
  83. +                default: exit(1);
  84. +            }
  85. +        }
  86. +
  87. +        Lcontinue:
  88. +        printf("continue without partition !\n");
  89. +    }
  90. +#else /* defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
  91.      storage_init();
  92. +#endif
  93.      settings_reset();
  94.      settings_load(SETTINGS_ALL);
  95.      settings_apply(true);
  96. diff --git a/apps/plugin.c b/apps/plugin.c
  97. index b3baea7..ae1e9cf 100644
  98. --- a/apps/plugin.c
  99. +++ b/apps/plugin.c
  100. @@ -59,9 +59,15 @@
  101.  #endif
  102.  
  103.  #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
  104. +#if  !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  105. +#  define FS_PREFIX(_x_) sim_ ## _x_
  106. +# else
  107. +#  define FS_PREFIX(_x_) _x_
  108. +# endif
  109.  #define PREFIX(_x_) sim_ ## _x_
  110.  #else
  111.  #define PREFIX
  112. +#define FS_PREFIX
  113.  #endif
  114.  
  115.  #if defined(HAVE_PLUGIN_CHECK_OPEN_CLOSE) && (MAX_OPEN_FILES>32)
  116. @@ -306,20 +312,20 @@ static const struct plugin_api rockbox_api = {
  117.  #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
  118.      close_wrapper,
  119.  #else
  120. -    PREFIX(close),
  121. +    FS_PREFIX(close),
  122.  #endif
  123. -    (read_func)PREFIX(read),
  124. -    PREFIX(lseek),
  125. +    (read_func)FS_PREFIX(read),
  126. +    FS_PREFIX(lseek),
  127.  #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
  128.      (creat_func)creat_wrapper,
  129.  #else
  130. -    (creat_func)PREFIX(creat),
  131. +    (creat_func)FS_PREFIX(creat),
  132.  #endif
  133. -    (write_func)PREFIX(write),
  134. -    PREFIX(remove),
  135. -    PREFIX(rename),
  136. -    PREFIX(ftruncate),
  137. -    PREFIX(filesize),
  138. +    (write_func)FS_PREFIX(write),
  139. +    FS_PREFIX(remove),
  140. +    FS_PREFIX(rename),
  141. +    FS_PREFIX(ftruncate),
  142. +    FS_PREFIX(filesize),
  143.      fdprintf,
  144.      read_line,
  145.      settings_parseline,
  146. @@ -991,7 +997,7 @@ static int open_wrapper(const char* pathname, int flags, ...)
  147.  /* we don't have an 'open' function. it's a define. and we need
  148.   * the real file_open, hence PREFIX() doesn't work here */
  149.      int fd;
  150. -#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
  151. +#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  152.      if (flags & O_CREAT)
  153.      {
  154.          va_list ap;
  155. diff --git a/firmware/SOURCES b/firmware/SOURCES
  156. index d8cfade..5c50637 100644
  157. --- a/firmware/SOURCES
  158. +++ b/firmware/SOURCES
  159. @@ -95,7 +95,8 @@ common/crc32.c
  160.  #ifdef MI4_FORMAT
  161.  common/crc32-mi4.c
  162.  #endif
  163. -#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
  164. +#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
  165. +    ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
  166.  common/dir_uncached.c
  167.  common/file.c
  168.  common/disk.c
  169. @@ -185,7 +186,8 @@ drivers/touchscreen.c
  170.  
  171.  
  172.  /* Storage */
  173. -#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
  174. +#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
  175. +    ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
  176.  #if (CONFIG_STORAGE & STORAGE_MMC)
  177.  drivers/ata_mmc.c
  178.  #endif
  179. diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h
  180. index 5dcb4f6..f359a7b 100644
  181. --- a/firmware/export/config/sim.h
  182. +++ b/firmware/export/config/sim.h
  183. @@ -30,12 +30,14 @@
  184.  
  185.  #undef AMS_OF_SIZE
  186.  
  187. +#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  188.  #undef HAVE_MULTIDRIVE
  189.  #undef NUM_DRIVES
  190.  #undef HAVE_HOTSWAP
  191.  #undef HAVE_HOTSWAP_STORAGE_AS_MAIN
  192.  
  193.  #undef CONFIG_STORAGE
  194. +#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
  195.  
  196.  #undef CONFIG_USBOTG
  197.  
  198. diff --git a/firmware/export/sd.h b/firmware/export/sd.h
  199. index c798f54..f207421 100644
  200. --- a/firmware/export/sd.h
  201. +++ b/firmware/export/sd.h
  202. @@ -36,7 +36,6 @@ void sd_sleepnow(void);
  203.  bool sd_disk_is_active(void);
  204.  int  sd_soft_reset(void);
  205.  int  sd_init(void);
  206. -void sd_close(void);
  207.  int  sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
  208.  int  sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
  209.  void sd_spin(void);
  210. diff --git a/firmware/export/storage.h b/firmware/export/storage.h
  211. index e59a5e5..b6e8acf 100644
  212. --- a/firmware/export/storage.h
  213. +++ b/firmware/export/storage.h
  214. @@ -51,7 +51,8 @@ struct storage_info
  215.      char *revision;
  216.  };
  217.  
  218. -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(CONFIG_STORAGE_MULTI)
  219. +#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(CONFIG_STORAGE_MULTI)) || \
  220. +    ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER) && !defined(CONFIG_STORAGE_MULTI))
  221.  /* storage_spindown, storage_sleep and storage_spin are passed as
  222.   * pointers, which doesn't work with argument-macros.
  223.   */
  224. diff --git a/firmware/include/dir_uncached.h b/firmware/include/dir_uncached.h
  225. index f225cf8..38663ca 100644
  226. --- a/firmware/include/dir_uncached.h
  227. +++ b/firmware/include/dir_uncached.h
  228. @@ -32,7 +32,7 @@
  229.  #define ATTR_ARCHIVE     0x20
  230.  #define ATTR_VOLUME      0x40 /* this is a volume, not a real directory */
  231.  
  232. -#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
  233. +#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  234.  #define dirent_uncached sim_dirent
  235.  #define DIR_UNCACHED SIM_DIR
  236.  #define opendir_uncached sim_opendir
  237. @@ -57,7 +57,8 @@ struct dirent_uncached {
  238.  #include "fat.h"
  239.  
  240.  typedef struct {
  241. -#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
  242. +#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
  243. +    ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
  244.      bool busy;
  245.      long startcluster;
  246.      struct fat_dir fatdir;
  247. diff --git a/firmware/include/file.h b/firmware/include/file.h
  248. index a9d1d05..ff7164a 100644
  249. --- a/firmware/include/file.h
  250. +++ b/firmware/include/file.h
  251. @@ -49,7 +49,7 @@
  252.  #define O_TRUNC  0x10
  253.  #endif
  254.  
  255. -#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(PLUGIN) && !defined(CODEC)
  256. +#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(PLUGIN) && !defined(CODEC) && !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  257.  #define open(x, ...) sim_open(x, __VA_ARGS__)
  258.  #define creat(x,m) sim_creat(x,m)
  259.  #define remove(x) sim_remove(x)
  260. @@ -78,7 +78,8 @@ extern int fsync(int fd);
  261.  extern ssize_t read(int fd, void *buf, size_t count);
  262.  extern off_t lseek(int fildes, off_t offset, int whence);
  263.  extern int file_creat(const char *pathname);
  264. -#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
  265. +#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || \
  266. +    ((CONFIG_PLATFORM & PLATFORM_HOSTED) && defined(ROCKBOX_SIMULATE_STORAGE_LAYER))
  267.  /* posix compatibility function */
  268.  static inline int creat(const char *pathname, mode_t mode)
  269.  {
  270. diff --git a/uisimulator/common/SOURCES b/uisimulator/common/SOURCES
  271. index a30b5ab..243c994 100644
  272. --- a/uisimulator/common/SOURCES
  273. +++ b/uisimulator/common/SOURCES
  274. @@ -12,5 +12,9 @@ backlight-sim.c
  275.  /* this is still needed for application since it has some stubs */
  276.  powermgmt-sim.c
  277.  io.c
  278. +debug.c
  279.  sim_tasks.c
  280.  stubs.c
  281. +#if defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  282. +storage.c
  283. +#endif
  284. diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
  285. index 260e880..b1e76bc 100644
  286. --- a/uisimulator/common/io.c
  287. +++ b/uisimulator/common/io.c
  288. @@ -147,6 +147,7 @@ void dircache_rename(const char *oldname, const char *newname);
  289.  #define SIMULATOR_DEFAULT_ROOT "simdisk"
  290.  extern const char *sim_root_dir;
  291.  
  292. +#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  293.  static int num_openfiles = 0;
  294.  
  295.  struct sim_dirent {
  296. @@ -170,26 +171,6 @@ struct mydir {
  297.  
  298.  typedef struct mydir MYDIR;
  299.  
  300. -#if 1 /* maybe this needs disabling for MSVC... */
  301. -static unsigned int rockbox2sim(int opt)
  302. -{
  303. -    int newopt = O_BINARY;
  304. -
  305. -    if(opt & 1)
  306. -        newopt |= O_WRONLY;
  307. -    if(opt & 2)
  308. -        newopt |= O_RDWR;
  309. -    if(opt & 4)
  310. -        newopt |= O_CREAT;
  311. -    if(opt & 8)
  312. -        newopt |= O_APPEND;
  313. -    if(opt & 0x10)
  314. -        newopt |= O_TRUNC;
  315. -
  316. -    return newopt;
  317. -}
  318. -#endif
  319. -
  320.  /** Simulator I/O engine routines **/
  321.  #define IO_YIELD_THRESHOLD 512
  322.  
  323. @@ -212,6 +193,26 @@ struct sim_io
  324.  
  325.  static struct sim_io io;
  326.  
  327. +#if 1 /* maybe this needs disabling for MSVC... */
  328. +static unsigned int rockbox2sim(int opt)
  329. +{
  330. +    int newopt = O_BINARY;
  331. +
  332. +    if(opt & 1)
  333. +        newopt |= O_WRONLY;
  334. +    if(opt & 2)
  335. +        newopt |= O_RDWR;
  336. +    if(opt & 4)
  337. +        newopt |= O_CREAT;
  338. +    if(opt & 8)
  339. +        newopt |= O_APPEND;
  340. +    if(opt & 0x10)
  341. +        newopt |= O_TRUNC;
  342. +
  343. +    return newopt;
  344. +}
  345. +#endif
  346. +
  347.  int ata_init(void)
  348.  {
  349.      /* Initialize the rockbox kernel objects on a rockbox thread */
  350. @@ -256,6 +257,7 @@ static ssize_t io_trigger_and_wait(int cmd)
  351.  
  352.      return result;
  353.  }
  354. +#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
  355.  
  356.  #if !defined(__PCTOOL__) && !defined(APPLICATION)
  357.  static const char *get_sim_pathname(const char *name)
  358. @@ -275,6 +277,7 @@ static const char *get_sim_pathname(const char *name)
  359.  #define get_sim_pathname(name) name
  360.  #endif
  361.  
  362. +#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  363.  MYDIR *sim_opendir(const char *name)
  364.  {
  365.      DIR_T *dir;
  366. @@ -509,6 +512,18 @@ int sim_fsync(int fd)
  367.  #endif
  368.  }
  369.  
  370. +/* rockbox off_t may be different from system off_t */
  371. +int sim_ftruncate(int fd, long length)
  372. +{
  373. +#ifdef WIN32
  374. +    return _chsize(fd, length);
  375. +#else
  376. +    return ftruncate(fd, length);
  377. +#endif
  378. +}
  379. +
  380. +#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
  381. +
  382.  #ifdef WIN32
  383.  /* sim-win32 */
  384.  #define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_))
  385. @@ -586,6 +601,8 @@ void sim_codec_close(void *pd)
  386.  
  387.  void *sim_plugin_load(char *plugin, void **pd)
  388.  {
  389. +#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  390. +    
  391.      void *hdr;
  392.      char path[MAX_PATH];
  393.  #ifdef WIN32
  394. @@ -614,60 +631,15 @@ void *sim_plugin_load(char *plugin, void **pd)
  395.          hdr = dlsym(*pd, "___header");
  396.  
  397.      return hdr;    /* maybe NULL if symbol not present */
  398. -}
  399. -
  400. -void sim_plugin_close(void *pd)
  401. -{
  402. -    dlclose(pd);
  403. -}
  404. -
  405. -#ifdef WIN32
  406. -static unsigned old_cp;
  407. -
  408. -void debug_exit(void)
  409. -{
  410. -    /* Reset console output codepage */
  411. -    SetConsoleOutputCP(old_cp);
  412. -}
  413.  
  414. -void debug_init(void)
  415. -{
  416. -    old_cp = GetConsoleOutputCP();
  417. -    /* Set console output codepage to UTF8. Only works
  418. -     * correctly when the console uses a truetype font. */
  419. -    SetConsoleOutputCP(65001);
  420. -    atexit(debug_exit);
  421. -}
  422. -#else
  423. -void debug_init(void)
  424. -{
  425. -    /* nothing to be done */
  426. -}
  427. -#endif
  428. +#else /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
  429.  
  430. -void debugf(const char *fmt, ...)
  431. -{
  432. -    va_list ap;
  433. -    va_start( ap, fmt );
  434. -    vfprintf( stderr, fmt, ap );
  435. -    va_end( ap );
  436. -}
  437. +    return NULL;
  438.  
  439. -void ldebugf(const char* file, int line, const char *fmt, ...)
  440. -{
  441. -    va_list ap;
  442. -    va_start( ap, fmt );
  443. -    fprintf( stderr, "%s:%d ", file, line );
  444. -    vfprintf( stderr, fmt, ap );
  445. -    va_end( ap );
  446. +#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
  447.  }
  448.  
  449. -/* rockbox off_t may be different from system off_t */
  450. -int sim_ftruncate(int fd, long length)
  451. +void sim_plugin_close(void *pd)
  452.  {
  453. -#ifdef WIN32
  454. -    return _chsize(fd, length);
  455. -#else
  456. -    return ftruncate(fd, length);
  457. -#endif
  458. +    dlclose(pd);
  459.  }
  460. diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
  461. index 6d7d7de..0063f0d 100644
  462. --- a/uisimulator/common/stubs.c
  463. +++ b/uisimulator/common/stubs.c
  464. @@ -36,7 +36,6 @@
  465.  #include "ata.h" /* for volume definitions */
  466.  
  467.  extern char having_new_lcd;
  468. -static bool storage_spinning = false;
  469.  
  470.  #if CONFIG_CODEC != SWCODEC
  471.  void audio_set_buffer_margin(int seconds)
  472. @@ -45,6 +44,9 @@ void audio_set_buffer_margin(int seconds)
  473.  }
  474.  #endif
  475.  
  476. +#if !defined(ROCKBOX_SIMULATE_STORAGE_LAYER)
  477. +static bool storage_spinning = false;
  478. +
  479.  int fat_startsector(void)
  480.  {
  481.      return 63;
  482. @@ -131,6 +133,8 @@ void storage_spindown(int s)
  483.      storage_spinning = false;
  484.  }
  485.  
  486. +#endif /* !defined(ROCKBOX_SIMULATE_STORAGE_LAYER) */
  487. +
  488.  void rtc_init(void)
  489.  {
  490.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement