func uploadCertificates(portName string, driver gxui.Driver, updateProgress func(string, int)) {
	defer func() { uploading = false }()

	updateProgress("Connecting to programmer on "+portName, 10)
	programmer, err := flasher.Open(portName)
	if err != nil {
		updateProgress(err.Error(), -1)
		return
	}
	defer programmer.Close()

	updateProgress("Synchronizing with programmer", 20)
	if err := programmer.Hello(); err != nil {
		updateProgress(err.Error(), -1)
		return
	}

	updateProgress("Reading programmer capabilities", 30)
	payloadSize, err = programmer.GetMaximumPayloadSize()
	if err != nil {
		updateProgress(err.Error(), -1)
		return
	}
	if payloadSize < 1024 {
		updateProgress("Programmer reports "+strconv.Itoa(int(payloadSize))+" as maximum payload size (1024 is needed)", -1)
		return
	}

	updateProgress("Converting certificates", 40)
	entries := []certificates.CertEntry{}
	for _, downloadedCert := range downloadedCerts {
		entries = append(entries, downloadedCert.Data)
	}
	convertedCers := certificates.ConvertCertEntries(entries)

	updateProgress("Uploading certificates...", 50)
	CertificatesOffset := 0x4000
	err = flashChunk(programmer, CertificatesOffset, convertedCers)
	if err != nil {
		updateProgress(err.Error(), -1)
		return
	}

	// For debugging puporses
	/*
		if err := ioutil.WriteFile("cert_output.bin", convertedCers, 0644); err != nil {
			updateProgress(err.Error(), -1)
			return
		}
	*/

	updateProgress("Upload completed!", 100)
}
func main() {
	flag.Parse()

	if portName == "" {
		log.Fatal("Please specify a serial port")
	}

	log.Println("Connecting to programmer")
	if _f, err := flasher.Open(portName); err != nil {
		log.Fatal(err)
	} else {
		f = _f
	}
	defer f.Close()

	// Synchronize with programmer
	log.Println("Synch with programmer")
	if err := f.Hello(); err != nil {
		log.Fatal(err)
	}

	// Check maximum supported payload size
	log.Println("Reading max payload size")
	_payloadSize, err := f.GetMaximumPayloadSize()
	if err != nil {
		log.Fatal(err)
	} else {
		payloadSize = _payloadSize
	}
	if payloadSize < 1024 {
		log.Fatalf("Programmer reports %d as maximum payload size (1024 is needed)", payloadSize)
	}

	if firmwareFile != "" {
		if err := flashFirmware(); err != nil {
			log.Fatal(err)
		}
	}

	if rootCertDir != "" || len(addresses) != 0 {
		if err := flashCerts(); err != nil {
			log.Fatal(err)
		}
	}

	if readAll {
		log.Println("Reading all flash")
		if err := readAllFlash(); err != nil {
			log.Fatal(err)
		}
	}
}