Beispiel #1
0
bool KoDocumentInfo::saveOasis( KoStore* store )
{
    KoStoreDevice dev( store );
    KoXmlWriter* xmlWriter = KoDocument::createOasisXmlWriter( &dev, "office:document-meta" );
    xmlWriter->startElement( "office:meta" );

    xmlWriter->startElement( "meta:generator");
    xmlWriter->addTextNode( QString( "KOffice/%1" ).arg( KOFFICE_VERSION_STRING ) );
    xmlWriter->endElement();
    QStringList lst = pages();
    QStringList::ConstIterator it = lst.begin();
    for( ; it != lst.end(); ++it )
    {
        KoDocumentInfoPage* p = page( *it );
        Q_ASSERT( p );
        if ( !p->saveOasis( *xmlWriter ) )
            return false;
    }
    xmlWriter->endElement();
    xmlWriter->endElement(); // root element
    xmlWriter->endDocument();
    delete xmlWriter;
    return true;
}
Beispiel #2
0
void
create_warehouse(){
  FD fd;
  std::vector<PageWarehouse> pages(W);

  for(int i=0; i<W; i++){
    const int w_id = i+1;
    pages[i].page_id = w_id;
    pages[i].w_id = w_id;
    gen_rand_astring(pages[i].w_name, 6, 10);
    gen_rand_astring(pages[i].w_street_1, 10, 20);
    gen_rand_astring(pages[i].w_street_2, 10, 20);
    gen_rand_astring(pages[i].w_city, 10, 20);
    gen_rand_nstring(pages[i].w_state, 2, 2);
    gen_rand_zip(pages[i].w_zip);
    gen_rand_decimal(&pages[i].w_tax, 0, 2000, 4);
    pages[i].w_ytd = 300000.00;
  }

  fd.open(WFILENAME, O_CREAT | O_TRUNC | O_WRONLY, 0644);
  fd.write(&pages[0], pages.size()*sizeof(PageWarehouse));

  std::cerr << "create warehouse " << pages.size() << "records: " << WFILENAME << std::endl;
}
Beispiel #3
0
bool Score::saveCompressedFile(QIODevice* f, QFileInfo& info, bool onlySelection, bool doCreateThumbnail)
      {
      MQZipWriter uz(f);

      QString fn = info.completeBaseName() + ".mscx";
      QBuffer cbuf;
      cbuf.open(QIODevice::ReadWrite);
      XmlWriter xml(this, &cbuf);
      xml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
      xml.stag("container");
      xml.stag("rootfiles");
      xml.stag(QString("rootfile full-path=\"%1\"").arg(XmlWriter::xmlString(fn)));
      xml.etag();
      for (ImageStoreItem* ip : imageStore) {
            if (!ip->isUsed(this))
                  continue;
            QString path = QString("Pictures/") + ip->hashName();
            xml.tag("file", path);
            }

      xml.etag();
      xml.etag();
      cbuf.seek(0);
      //uz.addDirectory("META-INF");
      uz.addFile("META-INF/container.xml", cbuf.data());

      // save images
      //uz.addDirectory("Pictures");
      foreach (ImageStoreItem* ip, imageStore) {
            if (!ip->isUsed(this))
                  continue;
            QString path = QString("Pictures/") + ip->hashName();
            uz.addFile(path, ip->buffer());
            }

      // create thumbnail
      if (doCreateThumbnail && !pages().isEmpty()) {
            QImage pm = createThumbnail();

            QByteArray ba;
            QBuffer b(&ba);
            if (!b.open(QIODevice::WriteOnly))
                  qDebug("open buffer failed");
            if (!pm.save(&b, "PNG"))
                  qDebug("save failed");
            uz.addFile("Thumbnails/thumbnail.png", ba);
            }

#ifdef OMR
      //
      // save OMR page images
      //
      if (masterScore()->omr()) {
            int n = masterScore()->omr()->numPages();
            for (int i = 0; i < n; ++i) {
                  QString path = QString("OmrPages/page%1.png").arg(i+1);
                  QBuffer cbuf1;
                  OmrPage* page = masterScore()->omr()->page(i);
                  const QImage& image = page->image();
                  if (!image.save(&cbuf1, "PNG")) {
                        MScore::lastError = tr("save file: cannot save image (%1x%2)").arg(image.width(), image.height());
                        return false;
                        }
                  uz.addFile(path, cbuf1.data());
                  cbuf1.close();
                  }
            }
#endif
      //
      // save audio
      //
      if (_audio)
            uz.addFile("audio.ogg", _audio->data());

      QBuffer dbuf;
      dbuf.open(QIODevice::ReadWrite);
      saveFile(&dbuf, true, onlySelection);
      dbuf.seek(0);
      uz.addFile(fn, dbuf.data());
      uz.close();
      return true;
      }
Beispiel #4
0
//------------------------------------------------------------------------------
// Name: do_find()
// Desc:
//------------------------------------------------------------------------------
void DialogReferences::do_find() {
	bool ok;
	const edb::address_t address   = edb::v1::string_to_address(ui->txtAddress->text(), ok);
	const edb::address_t page_size = edb::v1::debugger_core->page_size();

	if(ok) {
		edb::v1::memory_regions().sync();
		const QList<MemRegion> regions = edb::v1::memory_regions().regions();

		int i = 0;
		Q_FOREACH(const MemRegion &region, regions) {
			// a short circut for speading things up
			if(region.accessible() || !ui->chkSkipNoAccess->isChecked()) {

				const edb::address_t size_in_pages = region.size() / page_size;

				try {

					QVector<quint8> pages(size_in_pages * page_size);
					const quint8 *const pages_end = &pages[0] + size_in_pages * page_size;

					if(edb::v1::debugger_core->read_pages(region.start, &pages[0], size_in_pages)) {
						const quint8 *p = &pages[0];
						while(p != pages_end) {

							if(static_cast<std::size_t>(pages_end - p) < sizeof(edb::address_t)) {
								break;
							}

							const edb::address_t addr = p - &pages[0] + region.start;

							edb::address_t test_address;
							memcpy(&test_address, p, sizeof(edb::address_t));

							if(test_address == address) {

								QListWidgetItem *const item = new QListWidgetItem(edb::v1::format_pointer(addr));
								item->setData(Qt::UserRole, 'D');
								ui->listWidget->addItem(item);
							}

							edb::Instruction insn(p, pages_end - p, addr, std::nothrow);
							if(insn.valid()) {
								switch(insn.type()) {
								case edb::Instruction::OP_JMP:
								case edb::Instruction::OP_CALL:
								case edb::Instruction::OP_JCC:
									if(insn.operand(0).general_type() == edb::Operand::TYPE_REL) {
										if(insn.operand(0).relative_target() == address) {
											QListWidgetItem *const item = new QListWidgetItem(edb::v1::format_pointer(addr));
											item->setData(Qt::UserRole, 'C');
											ui->listWidget->addItem(item);
										}
									}
									break;
								default:
									break;
								}
							}

							emit updateProgress(util::percentage(i, regions.size(), p - &pages[0], region.size()));
							++p;
						}
					}
				} catch(const std::bad_alloc &) {
					QMessageBox::information(
						0,
						tr("Memroy Allocation Error"),
						tr("Unable to satisfy memory allocation request for requested region."));
				}
			} else {
				emit updateProgress(util::percentage(i, regions.size()));
			}
			++i;
		}
	}
}
void
Restore::restore_next(Signal* signal, FilePtr file_ptr)
{
  Uint32 *data, len= 0;
  Uint32 status = file_ptr.p->m_status;
  Uint32 page_count = file_ptr.p->m_pages.getSize();
  do 
  {
    Uint32 left= file_ptr.p->m_bytes_left;
    if (left < 8)
    {
      jam();
      /**
       * Not enough bytes to read header
       */
      break;
    }
    Ptr<GlobalPage> page_ptr(0,0), next_page_ptr(0,0);
    m_global_page_pool.getPtr(page_ptr, file_ptr.p->m_current_page_ptr_i);
    List::Iterator it;
    
    Uint32 pos= file_ptr.p->m_current_page_pos;
    if(status & File::READING_RECORDS)
    {
      jam();
      /**
       * We are reading records
       */
      len= ntohl(* (page_ptr.p->data + pos)) + 1;
      ndbrequire(len < GLOBAL_PAGE_SIZE_WORDS);
    }
    else
    {
      jam();
      /**
       * Section length is in 2 word
       */
      if(pos + 1 == GLOBAL_PAGE_SIZE_WORDS)
      {
        jam();
	/**
	 * But that's stored on next page...
	 *   and since we have atleast 8 bytes left in buffer
	 *   we can be sure that that's in buffer
	 */
	LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages);
	Uint32 next_page = file_ptr.p->m_current_page_index + 1;
	pages.position(it, next_page % page_count);
	m_global_page_pool.getPtr(next_page_ptr, * it.data);
	len= ntohl(* next_page_ptr.p->data);
      }
      else
      {
        jam();
	len= ntohl(* (page_ptr.p->data + pos + 1));
      }
    }

    if (file_ptr.p->m_status & File::FIRST_READ)
    {
      jam();
      len= 3;
      file_ptr.p->m_status &= ~(Uint32)File::FIRST_READ;
    }
    
    if (4 * len > left)
    {
      jam();

      /**
       * Not enought bytes to read "record"
       */
      if (unlikely((status & File:: FILE_THREAD_RUNNING) == 0))
      {
        crash_during_restore(file_ptr, __LINE__, 0);
      }
      len= 0;
      break;
    }
    
    /**
     * Entire record is in buffer
     */

    if(pos + len >= GLOBAL_PAGE_SIZE_WORDS)
    {
      jam();
      /**
       * But it's split over pages
       */
      if(next_page_ptr.p == 0)
      {
	LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages);
	Uint32 next_page = file_ptr.p->m_current_page_index + 1;
	pages.position(it, next_page % page_count);
	m_global_page_pool.getPtr(next_page_ptr, * it.data);
      }
      file_ptr.p->m_current_page_ptr_i = next_page_ptr.i;
      file_ptr.p->m_current_page_pos = (pos + len) - GLOBAL_PAGE_SIZE_WORDS;
      file_ptr.p->m_current_page_index = 
	(file_ptr.p->m_current_page_index + 1) % page_count;

      if (len <= GLOBAL_PAGE_SIZE_WORDS)
      {
        jam();
        Uint32 first = (GLOBAL_PAGE_SIZE_WORDS - pos);
        // wl4391_todo removing valgrind overlap warning for now
        memmove(page_ptr.p, page_ptr.p->data+pos, 4 * first);
        memcpy(page_ptr.p->data+first, next_page_ptr.p, 4 * (len - first));
        data= page_ptr.p->data;
      }
      else
      {
        jam();
        /**
         * A table definition can be larger than one page...
         * when that happens copy it out to side buffer
         *
         * First copy part belonging to page_ptr
         * Then copy full middle pages (moving forward in page-list)
         * Last copy last part
         */
        Uint32 save = len;
        assert(len <= NDB_ARRAY_SIZE(m_table_buf));
        Uint32 * dst = m_table_buf;

        /**
         * First
         */
        Uint32 first = (GLOBAL_PAGE_SIZE_WORDS - pos);
        memcpy(dst, page_ptr.p->data+pos, 4 * first);
        len -= first;
        dst += first;

        /**
         * Middle
         */
        while (len > GLOBAL_PAGE_SIZE_WORDS)
        {
          jam();
          memcpy(dst, next_page_ptr.p, 4 * GLOBAL_PAGE_SIZE_WORDS);
          len -= GLOBAL_PAGE_SIZE_WORDS;
          dst += GLOBAL_PAGE_SIZE_WORDS;

          {
            LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages);
            Uint32 next_page = (file_ptr.p->m_current_page_index + 1) % page_count;
            pages.position(it, next_page % page_count);
            m_global_page_pool.getPtr(next_page_ptr, * it.data);

            file_ptr.p->m_current_page_ptr_i = next_page_ptr.i;
            file_ptr.p->m_current_page_index = next_page;
          }
        }

        /**
         * last
         */
        memcpy(dst, next_page_ptr.p, 4 * len);
        file_ptr.p->m_current_page_pos = len;

        /**
         * Set pointer and len
         */
        len = save;
        data = m_table_buf;
      }
    }
    else
    {
      file_ptr.p->m_current_page_pos = pos + len;
      data= page_ptr.p->data+pos;
    }
    
    file_ptr.p->m_bytes_left -= 4*len;
    
    if(status & File::READING_RECORDS)
    {
      if(len == 1)
      {
	file_ptr.p->m_status = status & ~(Uint32)File::READING_RECORDS;
      }
      else
      {
	parse_record(signal, file_ptr, data, len);
      }
    }
    else
    {
      switch(ntohl(* data)){
      case BackupFormat::FILE_HEADER:
	parse_file_header(signal, file_ptr, data-3, len+3);
	break;
      case BackupFormat::FRAGMENT_HEADER:
	file_ptr.p->m_status = status | File::READING_RECORDS;
	parse_fragment_header(signal, file_ptr, data, len);
	break;
      case BackupFormat::FRAGMENT_FOOTER:
	parse_fragment_footer(signal, file_ptr, data, len);
	break;
      case BackupFormat::TABLE_LIST:
	parse_table_list(signal, file_ptr, data, len);
	break;
      case BackupFormat::TABLE_DESCRIPTION:
	parse_table_description(signal, file_ptr, data, len);
	break;
      case BackupFormat::GCP_ENTRY:
	parse_gcp_entry(signal, file_ptr, data, len);
	break;
      case BackupFormat::EMPTY_ENTRY:
        // skip
        break;
      case 0x4e444242: // 'NDBB'
	if (check_file_version(signal, ntohl(* (data+2))) == 0)
	{
	  break;
	}
      default:
	parse_error(signal, file_ptr, __LINE__, ntohl(* data));
      }
    }
  } while(0);
  
  if(file_ptr.p->m_bytes_left == 0 && status & File::FILE_EOF)
  {
    file_ptr.p->m_status &= ~(Uint32)File::RESTORE_THREAD_RUNNING;
    /**
     * File is finished...
     */
    close_file(signal, file_ptr);
    return;
  }
  
  /**
   * We send an immediate signal to continue the restore, at times this
   * could lead to burning some extra CPU since we might still wait for
   * input from the disk reading. This code is however only executed
   * as part of restarts, so it should be ok to spend some extra CPU
   * to ensure that restarts are quick.
   */
  signal->theData[0] = RestoreContinueB::RESTORE_NEXT;
  signal->theData[1] = file_ptr.i;
  sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB);
}
Uint32
Restore::init_file(const RestoreLcpReq* req, FilePtr file_ptr)
{
  new (file_ptr.p) File();
  file_ptr.p->m_sender_ref = req->senderRef;
  file_ptr.p->m_sender_data = req->senderData;

  file_ptr.p->m_fd = RNIL;
  file_ptr.p->m_file_type = BackupFormat::LCP_FILE;
  file_ptr.p->m_status = File::FIRST_READ;
  
  file_ptr.p->m_lcp_no = req->lcpNo;
  file_ptr.p->m_table_id = req->tableId;
  file_ptr.p->m_fragment_id = req->fragmentId;
  file_ptr.p->m_table_version = RNIL;

  file_ptr.p->m_bytes_left = 0; // Bytes read from FS
  file_ptr.p->m_current_page_ptr_i = RNIL;
  file_ptr.p->m_current_page_pos = 0; 
  file_ptr.p->m_current_page_index = 0;
  file_ptr.p->m_current_file_page = 0;
  file_ptr.p->m_outstanding_reads = 0;
  file_ptr.p->m_outstanding_operations = 0;
  file_ptr.p->m_rows_restored = 0;
  file_ptr.p->m_bytes_restored = 0;
  file_ptr.p->m_restore_start_time = NdbTick_CurrentMillisecond();;
  LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages);
  LocalDataBuffer<15> columns(m_databuffer_pool, file_ptr.p->m_columns);

  ndbassert(columns.isEmpty());
  columns.release();

  ndbassert(pages.isEmpty());
  pages.release();
  
  Uint32 buf_size= PAGES*GLOBAL_PAGE_SIZE;
  Uint32 page_count= (buf_size+GLOBAL_PAGE_SIZE-1)/GLOBAL_PAGE_SIZE;
  if(!pages.seize(page_count))
  {
    return RestoreLcpRef::OutOfDataBuffer;
  }

  List::Iterator it;
  for(pages.first(it); !it.isNull(); pages.next(it))
  {
    * it.data = RNIL;
  }

  Uint32 err= 0;
  for(pages.first(it); !it.isNull(); pages.next(it))
  {
    Ptr<GlobalPage> page_ptr;
    if(!m_global_page_pool.seize(page_ptr))
    {
      err= RestoreLcpRef::OutOfReadBufferPages;
      break;
    }
    * it.data = page_ptr.i;
  }
  
  if(err)
  {
    for(pages.first(it); !it.isNull(); pages.next(it))
    {
      if(* it.data == RNIL)
	break;
      m_global_page_pool.release(* it.data);
    }
  }
  else
  {
    pages.first(it);
    file_ptr.p->m_current_page_ptr_i = *it.data;
  }
  return err;
}
Beispiel #7
0
void WServer::initialize()
{
	//Start time
	_ptBeforeLoad = boost::posix_time::microsec_clock::local_time();

	/* *************************************************************************
	 * ***********************  Connect to SQL Server  *************************
	 * *************************************************************************/
	try
	{
		log("info") << "Connecting to database backend";

		//Wt::Dbo::SqlConnection *sqlConnection = new Wt::Dbo::backend::MySQL("wt", "root", "", "127.0.0.1");
		Wt::Dbo::SqlConnection *sqlConnection = new Wt::Dbo::backend::Sqlite3(":memory:");
		sqlConnection->setProperty("show-queries", "true");
		_sqlPool = new Wt::Dbo::FixedSqlConnectionPool(sqlConnection, 1);

		log("success") << "Successfully connected to database";
	}
	catch(Wt::Dbo::Exception &e)
	{
		log("fatal") << "Database error connecting to database: " <<  e.what();
		throw e;
	}
	catch(std::exception &e)
	{
		log("fatal") << "Error connecting to database: " << e.what();
		throw e;
	}

	/* *************************************************************************
	 * ***********************  Initialize Databases  **************************
	 * *************************************************************************/
	try
	{
		_dboManager = new DboDatabaseManager(this, _sqlPool);
		_modules = new ModuleDatabase(_dboManager);
		_configurations = new ConfigurationsDatabase(_dboManager);
		_languages = new LanguageDatabase(_dboManager);
		_styles = new StyleDatabase(_dboManager);
		_pages = new PageDatabase(_dboManager);
		_accessPaths = new AccessPathDatabase(_dboManager);
		_navigationMenus = new NavigationMenuDatabase(_dboManager);
	}
	catch(std::exception &e)
	{
		log("fatal") << "Error initializing databases: " << e.what();
		throw e;
	}

	/* *************************************************************************
	 * ***************************  Create Tables  *****************************
	 * *************************************************************************/
#define REINSTALL_DBO
#ifdef REINSTALL_DBO
	//Drop
	try
	{
		_installer = new Installer::DboInstaller(*_sqlPool);
		_installer->dropTables();
	}
	catch(Wt::Dbo::Exception &e)
	{
		log("error") << "Database error dropping tables: " <<  e.what();
	}
	catch(std::exception &e)
	{
		log("error") << "Error dropping tables: " << e.what();
	}

	//Create
	try
	{
		_installer->createTables();
	}
	catch(Wt::Dbo::Exception &e)
	{
		log("fatal") << "Database error creating tables: " <<  e.what();
		throw e;
	}
	catch(std::exception &e)
	{
		log("fatal") << "Error creating tables: " << e.what();
		throw e;
	}

	//Insert
// 	try
// 	{
		_installer->insertRows();
// 	}
// 	catch(Wt::Dbo::Exception &e)
// 	{
// 		log("fatal") << "Database error inserting data: " <<  e.what();
// 		throw e;
// 	}
// 	catch(std::exception &e)
// 	{
// 		log("fatal") << "Error inserting data: " << e.what();
// 		throw e;
// 	}
#endif

	/* *************************************************************************
	 * *************************  Load DboDatabases  ***************************
	 * *************************************************************************/
// 	try
// 	{
		log("info") << "Loading DboDatabaseManager";
		_dboManager->load();
// 	}
// 	catch(Wt::Dbo::Exception &e)
// 	{
// 		log("fatal") << "Database error loading DboDatabaseManager: " << e.what();
// 		throw e;
// 	}
// 	catch(std::exception &e)
// 	{
// 		log("fatal") << "Error loading DboDatabaseManager: " << e.what();
// 		throw e;
// 	}

	//Server localized strings
	setLocalizedStrings(new DboLocalizedStrings(this));

	pages()->register404PageHandler(new Default404Page());
	pages()->registerPageHandler("home", ModuleDatabase::Navigation, new AnotherPage());
	pages()->registerPageHandler("sitemap", ModuleDatabase::Navigation, new AnotherPage());
	pages()->registerPageHandler("login", ModuleDatabase::Authentication, new LoginPage());
	pages()->registerPageHandler("register", ModuleDatabase::Authentication, new RegistrationPage());

	/* *************************************************************************
	 * *********************  Create temporary XML file  ***********************
	 * *************************************************************************/
	try
	{
		log("info") << "Writing XML Configuration file";
		createWtXmlConfiguration();
		log("success") << "XML Configuration file created";
	}
	catch(std::exception &e)
	{
		log("fatal") << "Error creating XML Configuration file: " << e.what();
		throw e;
	}

	//Configure authorization module
	configureAuth();
}
Beispiel #8
0
int main(int argc, char **argv)
{
  boot_img_hdr hdr;

  int bootimg_fd;

  void *boot_data = 0;
  unsigned boot_size = 0;
  char boot_magic[BOOT_MAGIC_SIZE+1];
  char kernel_fn[MAXNAMELEN];
  void *kernel_data = 0;
  char ramdisk_fn[MAXNAMELEN];
  void *ramdisk_data = 0;
  char second_fn[MAXNAMELEN];
  void *second_data = 0;
  char header_fn[MAXNAMELEN];
  char *cmdline = "";
  char *bootimg_fn = 0;
  char *board = "";
  unsigned pagesize = 2048;
  int fd;
  /*SHA_CTX ctx;*/
  /*uint8_t* sha;*/
  unsigned long i;
  unsigned count;
  char *msg1 = "";
  char *msg2 = "";
  int offset;
  FILE *fp;
  unsigned kernel_offset =  0x00008000;
  unsigned ramdisk_offset = 0x01000000;
  unsigned second_offset =  0x00F00000;
  unsigned tags_offset =    0x00000100;
  unsigned kernel_base = 0;
  unsigned ramdisk_base = 0;
  unsigned second_base = 0;
  unsigned tags_base = 0;

  argc--;
  argv++;

  while(argc > 0){
    char *arg = argv[0];
    char *val = argv[1];
    if(argc < 2) {
      return usage();
    }
    argc -= 2;
    argv += 2;
    if(!strcmp(arg, "--input") || !strcmp(arg, "-i")) {
      bootimg_fn = val;
    } else {
      return usage();
    }
  }

  if(bootimg_fn == 0) {
    fprintf(stderr,"error: no input filename specified\n");
    return usage();
  }

  sprintf(kernel_fn, "%s-kernel", bootimg_fn);
  bootimg_fd = open(bootimg_fn, O_RDONLY);
  if (bootimg_fd < 0) {
    fprintf(stderr,"error: could not open %s\n", bootimg_fn);
    return 1;
  }

  count = read(bootimg_fd, (void *)&hdr, sizeof(hdr));
  if (count != sizeof(hdr)) {
    msg1 = "could not read hdr from input";
    goto fail;
  }
  for (i = 0; i < BOOT_MAGIC_SIZE; i++) {
    boot_magic[i] = hdr.magic[i];
  }
  boot_magic[BOOT_MAGIC_SIZE] = '\0';
  if (strcmp(BOOT_MAGIC, boot_magic)) {
    fprintf(stderr, "error: %s boot image file's magic value %s does not match %s\n",
            bootimg_fn, boot_magic, BOOT_MAGIC);
    goto fail;
  }
  if (hdr.page_size != 2048 && hdr.page_size != 4096 &&
      hdr.page_size != 8192 && hdr.page_size != 16384) {
    fprintf(stderr, "warning: hdr.page_size %d must be 2048, 4096, 8192 or 16384\n",
            hdr.page_size);
    goto fail;
  }
  count = lseek(bootimg_fd, hdr.page_size, SEEK_SET);
  if (count != hdr.page_size) {
    msg1 = "boot header is not a page";
    goto fail;
  }

  sprintf(header_fn, "%s-header", bootimg_fn);
  fp = fopen(header_fn, "w+");
  if(!fp) {
    msg1 = "could not create";
    msg2 = header_fn;
    goto fail;
  }
  kernel_base  = hdr.kernel_addr - kernel_offset;
  ramdisk_base = hdr.ramdisk_addr - ramdisk_offset;
  second_base  = hdr.second_addr - second_offset;
  tags_base    = hdr.tags_addr - tags_offset;

  fprintf(fp, "Assumptions\n");
  fprintf(fp, "kernel_offset = 0x%X\n", kernel_offset);
  fprintf(fp, "ramdisk_offset = 0x%X\n", ramdisk_offset);
  fprintf(fp, "second_offset = 0x%X\n", second_offset);
  fprintf(fp, "tags_offset = 0x%X\n", tags_offset);
  fprintf(fp, "Detected values\n");
  fprintf(fp, "kernel_size = %d\n", hdr.kernel_size);
  fprintf(fp, "kernel_addr = 0x%X\n", hdr.kernel_addr);
  fprintf(fp, "ramdisk_size = %d\n", hdr.ramdisk_size);
  fprintf(fp, "ramdisk_addr = 0x%X\n", hdr.ramdisk_addr);
  fprintf(fp, "second_size = %d\n", hdr.second_size);
  fprintf(fp, "second_addr = 0x%X\n", hdr.second_addr);
  fprintf(fp, "tags_addr = 0x%X\n", hdr.tags_addr);
  fprintf(fp, "page_size = %d\n", hdr.page_size);
  /*fprintf(fp, "unused = %d%d\n", hdr.unused[0], hdr.unused[1]);*/
  fprintf(fp, "name/board = %s\n", hdr.name);
  fprintf(fp, "cmdline = %s\n", hdr.cmdline);
  /*fprintf(fp, "id = %s\n", hdr.id);*/
  fprintf(fp, "Computed values\n");
  fprintf(fp, "kernel_base = 0x%X\n", kernel_base);
  fprintf(fp, "ramdisk_base = 0x%X, kernel_base - ramdisk_offset=0x%X\n", ramdisk_base,
          kernel_base - ramdisk_base);
  fprintf(fp, "second_base = 0x%X, kernel_base - second_offset=0x%X\n", second_base,
          kernel_base - second_base);
  fprintf(fp, "tags_base = 0x%X, kernel_base - tags_offset = 0x%X\n", tags_base,
          kernel_base - tags_base);
  if (kernel_base != ramdisk_base ||
      kernel_base != second_base ||
      kernel_base != tags_base) {
    fprintf(fp, "WARNING! base addresses do not match!\n");
    fprintf(stderr, "WARNING! base addresses do not match!\n");
  }

  fclose(fp);

  /* kernel */
  if(hdr.kernel_size == 0) {
    msg1 = "kernel size is zero";
    goto fail;
  }
  offset = hdr.page_size;
  write_chunk(bootimg_fd, bootimg_fn, hdr.kernel_size, "kernel", offset);

  /* ramdisk */
  if(hdr.ramdisk_size == 0) {
    msg1 = "ramdisk size is zero";
    goto fail;
  }
  offset += pages(hdr.page_size, hdr.kernel_size) * hdr.page_size;
  write_chunk(bootimg_fd, bootimg_fn, hdr.ramdisk_size, "first-ramdisk", offset);

  /* ramdisk 2 */
  if(hdr.second_size > 0) {
    offset += pages(hdr.page_size, hdr.ramdisk_size) * hdr.page_size;
    write_chunk(bootimg_fd, bootimg_fn, hdr.second_size, "second-ramdisk", offset);
  }

  return 0;

 fail:
  close(bootimg_fd);
  fprintf(stderr,"error: %s %s '%s': %s\n", msg1, msg2, bootimg_fn,
          strerror(errno));
  return 1;
}
Beispiel #9
0
void ObxTreeView::reportPosition()
{
    emit positionChanged(currentPage(), pages());
}
Beispiel #10
0
void handle(JsonObject& resp, JsonObject& req) {
	Serial.begin(BAUDRATE, SerialConfig::SERIAL_8E1, SerialMode::SERIAL_FULL);
	Serial.swap();
	String cmd = req["request"];
	resp["id"] = req["id"];
	resp["reply"] = req["request"];
	uint32_t startTime = millis();
	Erc erc = 0;
	if (cmd.equals("resetBootloader")) {

		erc = stm32.resetSystem();

	} else if (cmd.equals("resetFlash")) {

		erc = stm32.resetFlash();

	} else if (cmd.equals("goFlash")) {

		uint32_t address = req["address"];
		erc = stm32.go(address);
		resp["address"] = address;

	} else if (cmd.equals("status")) {

		resp["esp_id"] = ESP.getChipId();
		resp["heap"] = ESP.getFreeHeap();
		resp["upTime"] = millis();
		resp["version"] = __DATE__ " " __TIME__;
		resp["usart.rxd"] = Stm32::_usartRxd;
		resp["mode"] =
				stm32.getMode() == Stm32::M_FLASH ?
						"APPLICATION" : "BOOTLOADER";
		resp["baudrate"] = BAUDRATE;

	} else if (cmd.equals("getId")) {

		uint16_t chipId;
		erc = stm32.getId(chipId);
		if (erc == E_OK) {
			resp["chipId"] = chipId;
		}

	} else if (cmd.equals("getVersion")) {

		uint8_t version;
		erc = stm32.getVersion(version);
		if (erc == E_OK) {
			resp["version"] = version;
		}

	} else if (cmd.equals("get")) {

		Bytes data(30);
		Str strData(60);
		uint8_t version;
		erc = stm32.get(version, data);
		if (erc == E_OK) {
			erc = Base64::encode(strData, data);
			resp["cmds"] = String(strData.c_str());
			resp["version"] = version;
		}

	} else if (cmd.equals("writeMemory")) {

		Bytes data(256);
		Str str((const char*) req["data"]);
		uint32_t address = req["address"];
		resp["address"] = address;
		erc = Base64::decode(data, str);
		resp["length"] = data.length();
		if (erc == E_OK) {
			erc = stm32.writeMemory(address, data);
		}

	} else if (cmd.equals("eraseMemory")) {

		Bytes pages(256);
		Str str((const char*) req["pages"]);
		erc = Base64::decode(pages, str);
		resp["length"] = pages.length();
		erc = stm32.eraseMemory(pages);

	} else if (cmd.equals("extendedEraseMemory")) {

		erc = stm32.extendedEraseMemory();

	} else if (cmd.equals("eraseAll")) {

		erc = stm32.eraseAll();

	} else if (cmd.equals("readMemory")) {

		Str strData(410);
		Bytes data(256);
		uint32_t address = req["address"];
		uint32_t length = req["length"];
		resp["address"] = address;
		resp["length"] = length;
		erc = stm32.readMemory(address, length, data);
		if (erc == E_OK) {
			erc = Base64::encode(strData, data);
			resp["data"] = String(strData.c_str());
		}

	} else if (cmd.equals("writeProtect")) {

		Bytes data(256);
		Str str((const char*) req["data"]);
		erc = Base64::decode(data, str);
		erc = stm32.writeProtect(data);

	} else if (cmd.equals("writeUnprotect")) {

		erc = stm32.writeUnprotect();

	} else if (cmd.equals("readoutProtect")) {

		erc = stm32.readoutProtect();

	} else if (cmd.equals("readoutUnprotect")) {

		erc = stm32.readoutUnprotect();

	} else if (cmd.equals("settings")) {

		if (req.containsKey("baudrate")) {
			BAUDRATE = req["baudrate"];
			resp["baudrate"] = BAUDRATE;
			Config.set("uart.baudrate", BAUDRATE);
		}
		String config;
		Config.load(config);
		resp["config"] = config;

	} else {
		erc = EINVAL;
	}
	resp["delta"] = millis() - startTime;
	resp["error"] = erc;

	Serial.begin(BAUDRATE, SerialConfig::SERIAL_8N1, SerialMode::SERIAL_FULL);
	Serial.swap();
}